diff --git a/components/VersionDropdown.vue b/components/VersionDropdown.vue index 9258814f7..0fafcba1b 100644 --- a/components/VersionDropdown.vue +++ b/components/VersionDropdown.vue @@ -13,6 +13,7 @@ const store = useMainStore(); const spellings: Record> = { zh: { traditional: '繁體', simplified: '简体' }, tok: { latin: 'sitelen Lasina', sitelen: 'sitelen\xa0pona' }, + hbs: { latin: 'latinica', cyrillic: 'ћирилица' }, }; const spellingCookie = useCookie('spelling', longtimeCookieSetting); diff --git a/composables/useSpelling.ts b/composables/useSpelling.ts index 202b07b9a..54a9284ee 100644 --- a/composables/useSpelling.ts +++ b/composables/useSpelling.ts @@ -14,6 +14,98 @@ declare global { } } +// TODO move to a separate file +const HBS_LATIN_TO_CYRILLIC: Record = { + '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 `${str}`; } + if (config.locale === 'hbs' && store.spelling === 'cyrillic') { + return hbsLatinToCyrillic(str); + } + return str; }, convertName(name: string): string {