From fef568b89db1517481f76b0acfcd6796da693d20 Mon Sep 17 00:00:00 2001 From: marv Date: Mon, 18 Dec 2023 01:57:14 -0800 Subject: Fix Non JP Scanning Option for Kanji Dictionaries (#372) * Fix non JP scanning option for kanji dictionaries * Fix trailing comma * Add removeNonJapaneseCharacters to test inputs --- ext/js/background/backend.js | 5 ++++- ext/js/language/translator.js | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'ext/js') diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js index 749c81a6..20c7a189 100644 --- a/ext/js/background/backend.js +++ b/ext/js/background/backend.js @@ -2635,7 +2635,10 @@ export class Backend { */ _getTranslatorFindKanjiOptions(options) { const enabledDictionaryMap = this._getTranslatorEnabledDictionaryMap(options); - return {enabledDictionaryMap}; + return { + enabledDictionaryMap, + removeNonJapaneseCharacters: !options.scanning.alphanumeric + }; } /** diff --git a/ext/js/language/translator.js b/ext/js/language/translator.js index aa1b71dd..e33ea4d4 100644 --- a/ext/js/language/translator.js +++ b/ext/js/language/translator.js @@ -125,6 +125,9 @@ export class Translator { * @returns {Promise} 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) { -- cgit v1.2.3