diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2020-11-29 13:09:02 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-29 13:09:02 -0500 |
commit | 34451ebf7122a2a5d140696215411abfb0dfe188 (patch) | |
tree | e9eddb52f133269853059372045dea510e8d02dc /ext/bg/js/translator.js | |
parent | a8cd03cbecf4015483ce3479e589e65ce7eece45 (diff) |
JapaneseUtil normalization (#1076)
* Use JapaneseUtil as a class which is manually instantiated
* Use alias function for toKana
Diffstat (limited to 'ext/bg/js/translator.js')
-rw-r--r-- | ext/bg/js/translator.js | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 45d7f17a..f577d0e1 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -18,7 +18,6 @@ /* global * Deinflector * TextSourceMap - * jp */ /** @@ -29,7 +28,8 @@ class Translator { * Creates a new Translator instance. * @param database An instance of DictionaryDatabase. */ - constructor(database) { + constructor({japaneseUtil, database}) { + this._japaneseUtil = japaneseUtil; this._database = database; this._deinflector = null; this._tagCache = new Map(); @@ -318,6 +318,7 @@ class Translator { collapseEmphaticOptions ]; + const jp = this._japaneseUtil; const deinflections = []; const used = new Set(); for (const [halfWidth, numeric, alphabetic, katakana, hiragana, [collapseEmphatic, collapseEmphaticFull]] of this._getArrayVariants(textOptionVariantArray)) { @@ -846,6 +847,7 @@ class Translator { return text; } + const jp = this._japaneseUtil; let newText = ''; for (const c of text) { if (!jp.isCodePointJapanese(c.codePointAt(0))) { @@ -1031,7 +1033,7 @@ class Translator { this._sortTags(definitionTagsExpanded); this._sortTags(termTagsExpanded); - const furiganaSegments = jp.distributeFurigana(expression, reading); + const furiganaSegments = this._japaneseUtil.distributeFurigana(expression, reading); const termDetailsList = [this._createTermDetails(sourceTerm, expression, reading, furiganaSegments, termTagsExpanded)]; const sourceTermExactMatchCount = (sourceTerm === expression ? 1 : 0); |