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);
console.log('💬 ACTIVATE LANG', DEFAULT_LANG, lang);
} else {
const { messages } = await import(`../locales/${lang}.po`);
i18n.loadAndActivate({ locale: lang, messages });
console.log('💬 ACTIVATE LANG', lang, messages);
try {
const { messages } = await import(`../locales/${lang}.po`);
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);
}
}
}