(hbs) poc transliteration

This commit is contained in:
Andrea Vos 2025-01-14 23:12:27 +01:00
parent 595c0e6222
commit cde7eef6bb
2 changed files with 97 additions and 0 deletions

View File

@ -13,6 +13,7 @@ const store = useMainStore();
const spellings: Record<string, Record<string, string>> = {
zh: { traditional: '繁體', simplified: '简体' },
tok: { latin: 'sitelen Lasina', sitelen: 'sitelen\xa0pona' },
hbs: { latin: 'latinica', cyrillic: 'ћирилица' },
};
const spellingCookie = useCookie('spelling', longtimeCookieSetting);

View File

@ -14,6 +14,98 @@ declare global {
}
}
// TODO move to a separate file
const HBS_LATIN_TO_CYRILLIC: Record<string, string> = {
'A': 'А',
'a': 'а',
'B': 'Б',
'b': 'б',
'C': 'Ц',
'c': 'ц',
'Č': 'Ч',
'č': 'ч',
'Ć': 'Ћ',
'ć': 'ћ',
'D': 'Д',
'd': 'д',
'Dž': 'Џ',
'dž': 'џ',
'Đ': 'Ђ',
'đ': 'ђ',
'E': 'Е',
'e': 'е',
'F': 'Ф',
'f': 'ф',
'G': 'Г',
'g': 'г',
'H': 'Х',
'h': 'х',
'I': 'И',
'i': 'и',
'J': 'Ј',
'j': 'ј',
'K': 'К',
'k': 'к',
'L': 'Л',
'l': 'л',
'Lj': 'Љ',
'lj': 'љ',
'M': 'М',
'm': 'м',
'N': 'Н',
'n': 'н',
'Nj': 'Њ',
'nj': 'њ',
'O': 'О',
'o': 'о',
'P': 'П',
'p': 'п',
'R': 'Р',
'r': 'р',
'S': 'С',
's': 'с',
'Š': 'Ш',
'š': 'ш',
'T': 'Т',
't': 'т',
'U': 'У',
'u': 'у',
'V': 'В',
'v': 'в',
'Z': 'З',
'z': 'з',
'Ž': 'Ж',
'ž': 'ж',
}
const hbsLatinToCyrillic = (str: string): string => {
let result = '';
let i = 0;
while (i < str.length) {
if (i + 1 < str.length) {
// check for digraphs
const digraph = str.substring(i, i + 2);
if (HBS_LATIN_TO_CYRILLIC.hasOwnProperty(digraph)) {
result += HBS_LATIN_TO_CYRILLIC[digraph];
i += 2;
continue;
}
}
const char = str[i];
if (HBS_LATIN_TO_CYRILLIC.hasOwnProperty(char)) {
result += HBS_LATIN_TO_CYRILLIC[char];
} else {
result += char;
}
i++;
}
return result;
}
export default () => {
const config = useConfig();
const store = useMainStore();
@ -50,6 +142,10 @@ export default () => {
return `<span class="sitelen">${str}</span>`;
}
if (config.locale === 'hbs' && store.spelling === 'cyrillic') {
return hbsLatinToCyrillic(str);
}
return str;
},
convertName(name: string): string {