aboutsummaryrefslogtreecommitdiff
path: root/ext/js/language
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-07-17 12:20:11 -0400
committerGitHub <noreply@github.com>2021-07-17 12:20:11 -0400
commita933cfdc0780f618bb1ae60930a82a2af954e3cd (patch)
tree4886676976e6664349b48bb855659a74deb127ae /ext/js/language
parent4a2b824371e7e2c0f576805631f3ccf29d2c0ad3 (diff)
Pronunciation nasal improvement (#1834)
* Organize * Add utility to get diacritic information about a character * Show mora without diacritic * Add a hidden handakuten for copy-paste purposes
Diffstat (limited to 'ext/js/language')
-rw-r--r--ext/js/language/japanese-util.js20
1 files changed, 20 insertions, 0 deletions
diff --git a/ext/js/language/japanese-util.js b/ext/js/language/japanese-util.js
index 9d7ad0d8..c7f79751 100644
--- a/ext/js/language/japanese-util.js
+++ b/ext/js/language/japanese-util.js
@@ -154,6 +154,21 @@ const JapaneseUtil = (() => {
return map;
})();
+ const DIACRITIC_MAPPING = (() => {
+ const kana = 'うゔ-かが-きぎ-くぐ-けげ-こご-さざ-しじ-すず-せぜ-そぞ-ただ-ちぢ-つづ-てで-とど-はばぱひびぴふぶぷへべぺほぼぽワヷ-ヰヸ-ウヴ-ヱヹ-ヲヺ-カガ-キギ-クグ-ケゲ-コゴ-サザ-シジ-スズ-セゼ-ソゾ-タダ-チヂ-ツヅ-テデ-トド-ハバパヒビピフブプヘベペホボポ';
+ const map = new Map();
+ for (let i = 0, ii = kana.length; i < ii; i += 3) {
+ const character = kana[i];
+ const dakuten = kana[i + 1];
+ const handakuten = kana[i + 2];
+ map.set(dakuten, {character, type: 'dakuten'});
+ if (handakuten !== '-') {
+ map.set(handakuten, {character, type: 'handakuten'});
+ }
+ }
+ return map;
+ })();
+
function isCodePointInRange(codePoint, [min, max]) {
return (codePoint >= min && codePoint <= max);
@@ -417,6 +432,11 @@ const JapaneseUtil = (() => {
return this._wanakana !== null;
}
+ getKanaDiacriticInfo(character) {
+ const info = DIACRITIC_MAPPING.get(character);
+ return typeof info !== 'undefined' ? {character: info.character, type: info.type} : null;
+ }
+
// Furigana distribution
distributeFurigana(term, reading) {