aboutsummaryrefslogtreecommitdiff
path: root/ext/js/language/sandbox/japanese-util.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-09-27 18:19:53 -0400
committerGitHub <noreply@github.com>2021-09-27 18:19:53 -0400
commitb784e5b11a596a456eb8879d394fde64bc63aaef (patch)
tree411419b07d224ca1bd11d79cc302a1055a012dd1 /ext/js/language/sandbox/japanese-util.js
parent729abbf5616f93a641bb6b68593e524b352b2a19 (diff)
Katakana to hiragana conversion options (#1965)
* Refactor convertKatakanaToHiragana * Add keepProlongedSoundMarks option * Test keepProlongedSoundMarks option * Refactor * Add keepProlongedSoundMarks option to hiragana handlebars helper * Update documentation
Diffstat (limited to 'ext/js/language/sandbox/japanese-util.js')
-rw-r--r--ext/js/language/sandbox/japanese-util.js27
1 files changed, 17 insertions, 10 deletions
diff --git a/ext/js/language/sandbox/japanese-util.js b/ext/js/language/sandbox/japanese-util.js
index 9b58d255..a7542e79 100644
--- a/ext/js/language/sandbox/japanese-util.js
+++ b/ext/js/language/sandbox/japanese-util.js
@@ -297,20 +297,27 @@ const JapaneseUtil = (() => {
return this._wanakana !== null;
}
- convertKatakanaToHiragana(text) {
+ convertKatakanaToHiragana(text, keepProlongedSoundMarks=false) {
let result = '';
const offset = (HIRAGANA_CONVERSION_RANGE[0] - KATAKANA_CONVERSION_RANGE[0]);
for (let char of text) {
const codePoint = char.codePointAt(0);
- if (codePoint === KATAKANA_SMALL_KA_CODE_POINT || codePoint === KATAKANA_SMALL_KE_CODE_POINT) {
- // No change
- } else if (codePoint === KANA_PROLONGED_SOUND_MARK_CODE_POINT) {
- if (result.length > 0) {
- const char2 = getProlongedHiragana(result[result.length - 1]);
- if (char2 !== null) { char = char2; }
- }
- } else if (isCodePointInRange(codePoint, KATAKANA_CONVERSION_RANGE)) {
- char = String.fromCodePoint(codePoint + offset);
+ switch (codePoint) {
+ case KATAKANA_SMALL_KA_CODE_POINT:
+ case KATAKANA_SMALL_KE_CODE_POINT:
+ // No change
+ break;
+ case KANA_PROLONGED_SOUND_MARK_CODE_POINT:
+ if (!keepProlongedSoundMarks && result.length > 0) {
+ const char2 = getProlongedHiragana(result[result.length - 1]);
+ if (char2 !== null) { char = char2; }
+ }
+ break;
+ default:
+ if (isCodePointInRange(codePoint, KATAKANA_CONVERSION_RANGE)) {
+ char = String.fromCodePoint(codePoint + offset);
+ }
+ break;
}
result += char;
}