fix(i18n): fall back to browser language if the configured user language is invalid

This commit is contained in:
kolaente 2023-08-24 11:37:23 +02:00
parent 58a1f46668
commit a9fb306e46
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 7 additions and 2 deletions

View File

@ -47,8 +47,13 @@ export async function setLanguage(lang: SupportedLocale): Promise<SupportedLocal
// If the language hasn't been loaded yet
if (!i18n.global.availableLocales.includes(lang)) {
const messages = await import(`./lang/${lang}.json`)
i18n.global.setLocaleMessage(lang, messages.default)
try {
const messages = await import(`./lang/${lang}.json`)
i18n.global.setLocaleMessage(lang, messages.default)
} catch (e) {
console.error(`Failed to load language ${lang}:`, e)
return setLanguage(getBrowserLanguage())
}
}
i18n.global.locale.value = lang