Enable katakana soft search (resolves #14)

This commit is contained in:
Alex Yatskov 2016-10-21 20:43:09 -07:00
parent 5467ed11e1
commit 83f5bd24df
2 changed files with 18 additions and 5 deletions

View File

@ -105,11 +105,24 @@ class Translator {
return Promise.all(deinflectPromises).then(() => deinflectGroups); return Promise.all(deinflectPromises).then(() => deinflectGroups);
} }
findTerm(text) { findTerm(text, enableSoftKatakanaSearch) {
return this.findTermGroups(text).then(deinflectGroups => { 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 = []; const definitions = [];
for (const key in deinflectGroups) { for (const key in groups) {
definitions.push(deinflectGroups[key]); definitions.push(groups[key]);
} }
let length = 0; let length = 0;

View File

@ -243,7 +243,7 @@ class Yomichan {
} }
api_findTerm({text, callback}) { api_findTerm({text, callback}) {
promiseCallback(this.translator.findTerm(text), callback); promiseCallback(this.translator.findTerm(text, this.options.enableSoftKatakanaSearch), callback);
} }
api_renderText({template, data, callback}) { api_renderText({template, data, callback}) {