Skip to content

Commit

Permalink
fix the k consonant logic
Browse files Browse the repository at this point in the history
  • Loading branch information
khashashin committed May 26, 2024
1 parent 027313a commit 53f8aaf
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions translit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,21 @@ export function applyToWord(word: string): string {
word.substring(i, i + 1),
]) {
if (translitMap.hasOwnProperty(key)) {
const preLetter = i > 0 ? word[i - 1].toLowerCase() : '';
// if key is 'ъ' and next character is 'е', 'ё', 'ю', or 'я'
if ((key === 'ъ' || key === 'Ъ') && i + 1 < word.length && 'еёюяЕЁЮЯ'.includes(word[i + 1])) {
// if 'к' is before 'ъ', transliterate 'ъ' as 'q̇'
if (i > 0 && word[i - 1].toLowerCase() === 'к') {
match = 'q̇';
if (i > 0 && (preLetter === 'к')) {
match = word[i - 1] === 'к' ? 'q̇' : 'Q̇';
} else {
match = ''; // else skip 'ъ'
}
} else if (key === 'е' || key === 'Е') {
if (i === 0) {
match = key === 'е' ? 'ye' : 'Ye'; // 'е' at the start of the word
} else if (i > 0) {
if ((word[i - 1] === 'ъ' || word[i - 1] === 'Ъ') && (i < 2 || (word.substring(i - 2, i) !== 'къ' && word.substring(i - 2, i) !== 'Къ'))) {
const preConsonant = i > 1 ? word.substring(i - 2, i) : '';
if ((preLetter === 'ъ') && (i < 2 || (!['къ','Къ','кЪ','КЪ'].includes(preConsonant)))) {
match = key === 'е' ? 'ye' : 'Ye'; // 'е' following 'ъ' that does not follow 'къ'
} else {
match = translitMap[key]; // Regular transliteration for 'е'
Expand Down

0 comments on commit 53f8aaf

Please sign in to comment.