summaryrefslogtreecommitdiff
path: root/ext/bg/js/translator.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-04-22 13:02:06 -0700
committerAlex Yatskov <alex@foosoft.net>2017-04-22 13:02:06 -0700
commite661c4bd4383816f3f14c7458944795b44a40bad (patch)
tree47c02e8ee3edc83924ffae6cc19f41a07b70975a /ext/bg/js/translator.js
parent56fe02e9453f2b40a8af52b6f8a8125d67d2ad9f (diff)
add option to disable searching of alphanumeric text, fixes #471.1.14
Diffstat (limited to 'ext/bg/js/translator.js')
-rw-r--r--ext/bg/js/translator.js13
1 files changed, 10 insertions, 3 deletions
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js
index 67430aef..b3b90641 100644
--- a/ext/bg/js/translator.js
+++ b/ext/bg/js/translator.js
@@ -41,10 +41,17 @@ class Translator {
});
}
- findTerms(text, dictionaries, softKatakana) {
+ findTerms(text, dictionaries, softKatakana, alphanumeric) {
const titles = Object.keys(dictionaries);
const cache = {};
+ if (!alphanumeric && text.length > 0) {
+ const c = text[0];
+ if (!jpIsKana(c) && !jpIsKanji(c)) {
+ return Promise.resolve({length: 0, definitions: []});
+ }
+ }
+
return this.findTermsDeinflected(text, titles, cache).then(deinfLiteral => {
const textHiragana = wanakana._katakanaToHiragana(text);
if (text !== textHiragana && softKatakana) {
@@ -84,8 +91,8 @@ class Translator {
});
}
- findTermsGrouped(text, dictionaries, softKatakana) {
- return this.findTerms(text, dictionaries, softKatakana).then(({length, definitions}) => {
+ findTermsGrouped(text, dictionaries, softKatakana, alphanumeric) {
+ return this.findTerms(text, dictionaries, softKatakana, alphanumeric).then(({length, definitions}) => {
return {length, definitions: dictTermsGroup(definitions, dictionaries)};
});
}