diff options
author | Alex Yatskov <alex@foosoft.net> | 2020-03-14 13:14:03 -0700 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2020-03-14 13:14:03 -0700 |
commit | b77e2afe3a8ef9e96a53dd8ca97d8b913941244b (patch) | |
tree | 818a2f25169845a72b3424b7400b5b07f0f7cacf /ext/bg/js/translator.js | |
parent | d32f4def0eeed1599857bc04c973337a2a13dd8b (diff) | |
parent | 98afe7adae80c6bc9de0c4b996e6f6cb0a5df49d (diff) |
Merge branch 'master' into testing
Diffstat (limited to 'ext/bg/js/translator.js')
-rw-r--r-- | ext/bg/js/translator.js | 52 |
1 files changed, 40 insertions, 12 deletions
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index a675a9f7..25da9bf0 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -16,12 +16,28 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ -/*global requestJson -dictTermsMergeBySequence, dictTagBuildSource, dictTermsMergeByGloss, dictTermsSort, dictTagsSort -dictEnabledSet, dictTermsGroup, dictTermsCompressTags, dictTermsUndupe, dictTagSanitize -jpDistributeFurigana, jpConvertHalfWidthKanaToFullWidth, jpConvertNumericTofullWidth -jpConvertAlphabeticToKana, jpHiraganaToKatakana, jpKatakanaToHiragana, jpIsCharCodeJapanese -Database, Deinflector*/ +/* global + * Database + * Deinflector + * dictEnabledSet + * dictTagBuildSource + * dictTagSanitize + * dictTagsSort + * dictTermsCompressTags + * dictTermsGroup + * dictTermsMergeByGloss + * dictTermsMergeBySequence + * dictTermsSort + * dictTermsUndupe + * jpConvertAlphabeticToKana + * jpConvertHalfWidthKanaToFullWidth + * jpConvertNumericTofullWidth + * jpDistributeFurigana + * jpHiraganaToKatakana + * jpIsCodePointJapanese + * jpKatakanaToHiragana + * requestJson + */ class Translator { constructor() { @@ -199,8 +215,19 @@ class Translator { const strayDefinitions = defaultDefinitions.filter((definition, index) => !mergedByTermIndices.has(index)); for (const groupedDefinition of dictTermsGroup(strayDefinitions, dictionaries)) { - groupedDefinition.expressions = [Translator.createExpression(groupedDefinition.expression, groupedDefinition.reading)]; - definitionsMerged.push(groupedDefinition); + // from dictTermsMergeBySequence + const {reasons, score, expression, reading, source, dictionary} = groupedDefinition; + const compatibilityDefinition = { + reasons, + score, + expression: [expression], + reading: [reading], + expressions: [Translator.createExpression(groupedDefinition.expression, groupedDefinition.reading)], + source, + dictionary, + definitions: groupedDefinition.definitions + }; + definitionsMerged.push(compatibilityDefinition); } await this.buildTermMeta(definitionsMerged, dictionaries); @@ -610,13 +637,14 @@ class Translator { static getSearchableText(text, options) { if (!options.scanning.alphanumeric) { - const ii = text.length; - for (let i = 0; i < ii; ++i) { - if (!jpIsCharCodeJapanese(text.charCodeAt(i))) { - text = text.substring(0, i); + let newText = ''; + for (const c of text) { + if (!jpIsCodePointJapanese(c.codePointAt(0))) { break; } + newText += c; } + text = newText; } return text; |