summaryrefslogtreecommitdiff
path: root/ext/bg/js/translator.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-12-22 18:26:27 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-01-24 20:15:25 -0500
commit86d96a903696db98c0680d7665c53da5cd80731f (patch)
treefb0927ed656715979ddc2d445e45bd022808828c /ext/bg/js/translator.js
parentbe2e6e0d9361e844c39bb3e48a3777db0ef52f67 (diff)
Update detection of Japanese characters
Diffstat (limited to 'ext/bg/js/translator.js')
-rw-r--r--ext/bg/js/translator.js23
1 files changed, 18 insertions, 5 deletions
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js
index d9cb0c54..2fb36194 100644
--- a/ext/bg/js/translator.js
+++ b/ext/bg/js/translator.js
@@ -214,11 +214,9 @@ class Translator {
}
async findTermsInternal(text, dictionaries, details, options) {
- if (!options.scanning.alphanumeric && text.length > 0) {
- const c = text[0];
- if (!jpIsKana(c) && !jpIsKanji(c)) {
- return [[], 0];
- }
+ text = Translator.getSearchableText(text, options);
+ if (text.length === 0) {
+ return [[], 0];
}
const titles = Object.keys(dictionaries);
@@ -587,4 +585,19 @@ class Translator {
yield variant;
}
}
+
+ static getSearchableText(text, options) {
+ if (!options.scanning.alphanumeric) {
+ const ii = text.length;
+ for (let i = 0; i < ii; ++i) {
+ const c = text[i];
+ if (!jpIsCharacterJapanese(c)) {
+ text = text.substring(0, i);
+ break;
+ }
+ }
+ }
+
+ return text;
+ }
}