aboutsummaryrefslogtreecommitdiff
path: root/ext/bg
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-10-21 20:43:09 -0700
committerAlex Yatskov <alex@foosoft.net>2016-10-21 20:43:09 -0700
commit83f5bd24dfeb60637141ddc7cd0b99513ac74eec (patch)
tree49e4ea33d0366f0daf0d38bd89426dd8e5d8d436 /ext/bg
parent5467ed11e10addf2ceedf062ce151d88ea448fd1 (diff)
Enable katakana soft search (resolves #14)
Diffstat (limited to 'ext/bg')
-rw-r--r--ext/bg/js/translator.js21
-rw-r--r--ext/bg/js/yomichan.js2
2 files changed, 18 insertions, 5 deletions
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js
index 8f895800..44f37e31 100644
--- a/ext/bg/js/translator.js
+++ b/ext/bg/js/translator.js
@@ -105,11 +105,24 @@ class Translator {
return Promise.all(deinflectPromises).then(() => deinflectGroups);
}
- findTerm(text) {
- return this.findTermGroups(text).then(deinflectGroups => {
+ findTerm(text, enableSoftKatakanaSearch) {
+ return this.findTermGroups(text).then(groups => {
+ const textHiragana = wanakana._katakanaToHiragana(text);
+ if (text !== textHiragana && enableSoftKatakanaSearch) {
+ return this.findTermGroups(textHiragana).then(groupsHiragana => {
+ for (const key in groupsHiragana) {
+ groups[key] = groups[key] || groupsHiragana[key];
+ }
+
+ return groups;
+ });
+ } else {
+ return groups;
+ }
+ }).then(groups => {
const definitions = [];
- for (const key in deinflectGroups) {
- definitions.push(deinflectGroups[key]);
+ for (const key in groups) {
+ definitions.push(groups[key]);
}
let length = 0;
diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js
index 3091e503..7bca579d 100644
--- a/ext/bg/js/yomichan.js
+++ b/ext/bg/js/yomichan.js
@@ -243,7 +243,7 @@ class Yomichan {
}
api_findTerm({text, callback}) {
- promiseCallback(this.translator.findTerm(text), callback);
+ promiseCallback(this.translator.findTerm(text, this.options.enableSoftKatakanaSearch), callback);
}
api_renderText({template, data, callback}) {