Skip to content

Commit

Permalink
Merge branch 'master' into parse-punctuation
Browse files Browse the repository at this point in the history
  • Loading branch information
Casheeew authored Dec 18, 2023
2 parents 08aae70 + fef568b commit f45eb07
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 9 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ dictionaries/
ext/manifest.json

ext/lib/*
!ext/lib/__mocks__/

ext/legal-npm.html
2 changes: 1 addition & 1 deletion dev/translator-vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {JapaneseUtil} from '../ext/js/language/sandbox/japanese-util.js';
import {Translator} from '../ext/js/language/translator.js';
import {createDictionaryArchive} from './util.js';

vi.mock('../ext/js/language/dictionary-importer-media-loader.js');
vi.mock('../ext/js/language/dictionary-importer-media-loader.js', async () => await import('../test/mocks/dictionary-importer-media-loader.js'));

const dirname = path.dirname(fileURLToPath(import.meta.url));

Expand Down
5 changes: 4 additions & 1 deletion ext/js/background/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -2635,7 +2635,10 @@ export class Backend {
*/
_getTranslatorFindKanjiOptions(options) {
const enabledDictionaryMap = this._getTranslatorEnabledDictionaryMap(options);
return {enabledDictionaryMap};
return {
enabledDictionaryMap,
removeNonJapaneseCharacters: !options.scanning.alphanumeric
};
}

/**
Expand Down
3 changes: 3 additions & 0 deletions ext/js/language/translator.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ export class Translator {
* @returns {Promise<import('dictionary').KanjiDictionaryEntry[]>} An array of definitions. See the _createKanjiDefinition() function for structure details.
*/
async findKanji(text, options) {
if (options.removeNonJapaneseCharacters) {
text = this._getJapaneseOnlyText(text);
}
const {enabledDictionaryMap} = options;
const kanjiUnique = new Set();
for (const c of text) {
Expand Down
2 changes: 1 addition & 1 deletion test/anki-note-builder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async function fetch(url2) {
};
}
vi.stubGlobal('fetch', fetch);
vi.mock('../ext/js/templates/template-renderer-proxy.js');
vi.mock('../ext/js/templates/template-renderer-proxy.js', async () => await import('../test/mocks/template-renderer-proxy.js'));

/**
* @returns {Promise<TranslatorVM>}
Expand Down
3 changes: 2 additions & 1 deletion test/data/translator-test-inputs.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"priority": 0
}
]
]
],
"removeNonJapaneseCharacters": false
},
"default": {
"matchType": "exact",
Expand Down
4 changes: 1 addition & 3 deletions test/database.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ import path from 'path';
import {beforeEach, describe, expect, test, vi} from 'vitest';
import {createDictionaryArchive} from '../dev/util.js';
import {DictionaryDatabase} from '../ext/js/language/dictionary-database.js';
import {DictionaryImporterMediaLoader} from '../ext/js/language/dictionary-importer-media-loader.js';
import {DictionaryImporter} from '../ext/js/language/dictionary-importer.js';
import {DictionaryImporterMediaLoader} from './mocks/dictionary-importer-media-loader.js';

const dirname = path.dirname(fileURLToPath(import.meta.url));

vi.stubGlobal('IDBKeyRange', IDBKeyRange);

vi.mock('../ext/js/language/dictionary-importer-media-loader.js');

/**
* @param {string} dictionary
* @param {string} [dictionaryName]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import {AnkiTemplateRenderer} from '../sandbox/anki-template-renderer.js';
import {AnkiTemplateRenderer} from '../../ext/js/templates/sandbox/anki-template-renderer.js';

export class TemplateRendererProxy {
constructor() {
Expand Down
4 changes: 4 additions & 0 deletions types/ext/translation.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export type FindKanjiOptions = {
* The key is the dictionary name.
*/
enabledDictionaryMap: Map<string, FindKanjiDictionary>;
/**
* Whether or not non-Japanese characters should be searched.
*/
removeNonJapaneseCharacters: boolean;
};

/**
Expand Down

0 comments on commit f45eb07

Please sign in to comment.