Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Non JP Scanning Option for Kanji Dictionaries #372

Merged
merged 3 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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: 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