Fix fallback languages not loading (#631) (#632)

This commit is contained in:
Nikita 2024-12-15 13:21:18 +03:00 committed by GitHub
parent 7392447a35
commit af2dad1d2f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -14,20 +14,24 @@ export const i18nModule = createI18n({
export const i18n = i18nModule.global;
export async function setLanguage(lang) {
try {
if (!i18n.availableLocales.includes(lang)){
let messages = await fetchHocon(`./lang/${lang}.conf`);
i18n.setLocaleMessage(lang, messages);
}
loadLanguage(lang);
i18n.locale.value = lang;
document.querySelector('html').setAttribute('lang', lang);
return nextTick();
}
async function loadLanguage(lang) {
try {
if (!i18n.availableLocales.includes(lang)) {
let messages = await fetchHocon(`./lang/${lang}.conf`);
i18n.setLocaleMessage(lang, messages);
}
} catch (e) {
console.error(`Failed to load language '${lang}'!`, e);
}
return nextTick();
}
export async function loadLanguageSettings() {
@ -51,6 +55,10 @@ export async function loadLanguageSettings() {
selectedLanguage = settings.default;
}
await loadLanguage('en');
await loadLanguage(settings.default);
i18nModule.global.fallbackLocale = [settings.default, 'en'];
i18n.languages = settings.languages;
await setLanguage(selectedLanguage);
}