aboutsummaryrefslogtreecommitdiff
path: root/ext/js/display/query-parser.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-07-09 17:31:16 -0400
committerGitHub <noreply@github.com>2021-07-09 17:31:16 -0400
commit0d167095479822adf1ed8918e3d1a349b3a53377 (patch)
treed99c720a58451e70d44d4a03b1c2c2c3819328a8 /ext/js/display/query-parser.js
parentdaa44a8389806046ca8fde9fa1c96c1e961393f4 (diff)
JapaneseUtil updates (#1813)
* Rename test file * Use shorthand * Add support checking functions * Remove convertReading from JapaneseUtil
Diffstat (limited to 'ext/js/display/query-parser.js')
-rw-r--r--ext/js/display/query-parser.js26
1 files changed, 23 insertions, 3 deletions
diff --git a/ext/js/display/query-parser.js b/ext/js/display/query-parser.js
index 0acf6ec8..cbcf7cff 100644
--- a/ext/js/display/query-parser.js
+++ b/ext/js/display/query-parser.js
@@ -208,8 +208,6 @@ class QueryParser extends EventDispatcher {
}
_createParseResult(data) {
- const jp = this._japaneseUtil;
- const readingMode = this._readingMode;
const fragment = document.createDocumentFragment();
for (const term of data) {
const termNode = document.createElement('span');
@@ -218,7 +216,7 @@ class QueryParser extends EventDispatcher {
if (reading.length === 0) {
termNode.appendChild(document.createTextNode(text));
} else {
- const reading2 = jp.convertReading(text, reading, readingMode);
+ const reading2 = this._convertReading(text, reading);
termNode.appendChild(this._createSegment(text, reading2));
}
}
@@ -245,4 +243,26 @@ class QueryParser extends EventDispatcher {
return segmentNode;
}
+
+ _convertReading(term, reading) {
+ switch (this._readingMode) {
+ case 'hiragana':
+ return this._japaneseUtil.convertKatakanaToHiragana(reading);
+ case 'katakana':
+ return this._japaneseUtil.convertHiraganaToKatakana(reading);
+ case 'romaji':
+ if (this._japaneseUtil.convertToRomajiSupported()) {
+ if (reading.length > 0) {
+ return this._japaneseUtil.convertToRomaji(reading);
+ } else if (this._japaneseUtil.isStringEntirelyKana(term)) {
+ return this._japaneseUtil.convertToRomaji(term);
+ }
+ }
+ return reading;
+ case 'none':
+ return '';
+ default:
+ return reading;
+ }
+ }
}