Pop-up dictionary browser extension for language learning. Successor to Yomichan. (PERSONAL FORK)

Support capital N and NY for katakana in the special n handling (#2119)

* Support capital N and NY in the special n handling

* Move all convertToKanaIME n handling tests together

* Add proper katakana tests for convertToKanaIME

authored by

Kuuuube and committed by
GitHub
cde0a761 9b5940a3

+20 -6
+7 -4
ext/js/language/ja/japanese-wanakana.js
··· 53 53 // `なno|` will still convert to `なの` instead of `なんお` without issue since the `no` -> `の` conversion will be found before `n` -> `ん` and `o` -> `お`. 54 54 // `nn|` will still convert to `ん` instead of `んん` since `nn` -> `ん` will be found before `n` -> `ん`. 55 55 // If the user pastes in a long string of `n` such as `nnnnn|` it should leave the last `n` and convert to `んんn` 56 - if (text[prevSelectionStart - 1] === 'n' && text.slice(0, prevSelectionStart - 1).replaceAll('nn', '').at(-1) !== 'n') { 56 + const textLowered = text.toLowerCase(); 57 + if (textLowered[prevSelectionStart - 1] === 'n' && textLowered.slice(0, prevSelectionStart - 1).replaceAll('nn', '').at(-1) !== 'n') { 58 + const n = text.slice(prevSelectionStart - 1, prevSelectionStart); 57 59 const beforeN = text.slice(0, prevSelectionStart - 1); 58 60 const afterN = text.slice(prevSelectionStart); 59 - kanaString = convertToKana(beforeN) + 'n' + convertToKana(afterN); 60 - } else if (text.slice(prevSelectionStart - 2, prevSelectionStart) === 'ny') { 61 + kanaString = convertToKana(beforeN) + n + convertToKana(afterN); 62 + } else if (textLowered.slice(prevSelectionStart - 2, prevSelectionStart) === 'ny') { 63 + const ny = text.slice(prevSelectionStart - 2, prevSelectionStart); 61 64 const beforeN = text.slice(0, prevSelectionStart - 2); 62 65 const afterN = text.slice(prevSelectionStart); 63 - kanaString = convertToKana(beforeN) + 'ny' + convertToKana(afterN); 66 + kanaString = convertToKana(beforeN) + ny + convertToKana(afterN); 64 67 } else { 65 68 kanaString = convertToKana(text); 66 69 }
+13 -2
test/japanese-util.test.js
··· 163 163 /** @type {[input: [string, number], expected: import('language.js').KanaIMEOutput][]} */ 164 164 const data = [ 165 165 // Note: `|` represents the text cursor (newSelectionStart) position in the following comments 166 - [['KATAKANA', 8], {kanaString: 'カタカナ', newSelectionStart: 4}], // KATAKANA| -> カタカナ| 166 + // hiragana 167 167 [['hiragana', 8], {kanaString: 'ひらがな', newSelectionStart: 4}], // hiragana| -> ひらがな| 168 168 [['n', 1], {kanaString: 'n', newSelectionStart: 1}], // n| -> n| 169 169 [['nn', 2], {kanaString: 'ん', newSelectionStart: 1}], // nn| -> ん| 170 170 [['nn', 1], {kanaString: 'nん', newSelectionStart: 1}], // n|n -> n|ん 171 171 [['nの', 1], {kanaString: 'nの', newSelectionStart: 1}], // n|の -> n|の 172 - [['ttttttttttsu', 12], {kanaString: 'っっっっっっっっっつ', newSelectionStart: 10}], // ttttttttttsu| -> っっっっっっっっっつ| 173 172 [['nnn', 3], {kanaString: 'んn', newSelectionStart: 2}], // nnn| -> んn| 174 173 [['nnnnano', 7], {kanaString: 'んんあの', newSelectionStart: 4}], // nnnnano| -> んんあの| 175 174 [['ny', 2], {kanaString: 'ny', newSelectionStart: 2}], // ny| -> ny| 176 175 [['nya', 3], {kanaString: 'にゃ', newSelectionStart: 2}], // nya| -> にゃ| 176 + [['ttttttttttsu', 12], {kanaString: 'っっっっっっっっっつ', newSelectionStart: 10}], // ttttttttttsu| -> っっっっっっっっっつ| 177 177 [['tt', 2], {kanaString: 'っt', newSelectionStart: 2}], // tt| -> っt| 178 + // Katakana 179 + [['KATAKANA', 8], {kanaString: 'カタカナ', newSelectionStart: 4}], // KATAKANA| -> カタカナ| 180 + [['N', 1], {kanaString: 'N', newSelectionStart: 1}], // N| -> N| 181 + [['NN', 2], {kanaString: 'ン', newSelectionStart: 1}], // NN| -> ン| 182 + [['NN', 1], {kanaString: 'Nン', newSelectionStart: 1}], // N|N -> N|ン 183 + [['Nノ', 1], {kanaString: 'Nノ', newSelectionStart: 1}], // N|ノ -> N|ノ 184 + [['NNN', 3], {kanaString: 'ンN', newSelectionStart: 2}], // NNN| -> ンN| 185 + [['NNNNANO', 7], {kanaString: 'ンンアノ', newSelectionStart: 4}], // NNNNANO| -> ンンアノ| 186 + [['NY', 2], {kanaString: 'NY', newSelectionStart: 2}], // NY| -> NY| 187 + [['NYA', 3], {kanaString: 'ニャ', newSelectionStart: 2}], // NYA| -> ニャ| 188 + [['TTTTTTTTTTSU', 12], {kanaString: 'ッッッッッッッッッツ', newSelectionStart: 10}], // TTTTTTTTTTSU| -> ッッッッッッッッッツ| 178 189 [['TT', 2], {kanaString: 'ッT', newSelectionStart: 2}], // TT| -> ッT| 179 190 ]; 180 191