Add try/catch fallback if file fails to load

Could be the file is not there or something wrong with the connection. Still good to include this try/catch
This commit is contained in:
Lim Chee Aun 2024-08-14 15:02:45 +08:00
parent d9bc18f557
commit e5815686a9

View file

@ -33,9 +33,15 @@ export async function activateLang(lang) {
i18n.activate(DEFAULT_LANG); i18n.activate(DEFAULT_LANG);
console.log('💬 ACTIVATE LANG', DEFAULT_LANG, lang); console.log('💬 ACTIVATE LANG', DEFAULT_LANG, lang);
} else { } else {
const { messages } = await import(`../locales/${lang}.po`); try {
i18n.loadAndActivate({ locale: lang, messages }); const { messages } = await import(`../locales/${lang}.po`);
console.log('💬 ACTIVATE LANG', lang, messages); i18n.loadAndActivate({ locale: lang, messages });
console.log('💬 ACTIVATE LANG', lang, messages);
} catch (e) {
// Fallback to default language
i18n.activate(DEFAULT_LANG);
console.log('💬 ACTIVATE LANG', DEFAULT_LANG, lang);
}
} }
} }