aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/js/background/backend.js5
-rw-r--r--ext/js/language/translator.js3
-rw-r--r--test/data/translator-test-inputs.json3
-rw-r--r--types/ext/translation.d.ts4
4 files changed, 13 insertions, 2 deletions
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<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) {
diff --git a/test/data/translator-test-inputs.json b/test/data/translator-test-inputs.json
index f6b5ea67..cf4b8f6a 100644
--- a/test/data/translator-test-inputs.json
+++ b/test/data/translator-test-inputs.json
@@ -9,7 +9,8 @@
"priority": 0
}
]
- ]
+ ],
+ "removeNonJapaneseCharacters": false
},
"default": {
"matchType": "exact",
diff --git a/types/ext/translation.d.ts b/types/ext/translation.d.ts
index 3c41c9f3..3adfc673 100644
--- a/types/ext/translation.d.ts
+++ b/types/ext/translation.d.ts
@@ -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;
};
/**