Minor tweak

This commit is contained in:
Rainer Simon 2020-05-19 18:18:16 +02:00
parent ad67be30f8
commit d1354ec489
1 changed files with 8 additions and 6 deletions

View File

@ -78,12 +78,14 @@ export const addPolyfills = () => {
* Helper to init the i18n class with a pre-defined or auto-detected locale.
*/
export const setLocale = locale => {
try {
const l = locale === 'auto' ?
window.navigator.userLanguage || window.navigator.language : locale;
if (locale) {
try {
const l = locale === 'auto' ?
window.navigator.userLanguage || window.navigator.language : locale;
I18n.init(l);
} catch (error) {
console.warn(`Unsupported locale '${locale}'. Falling back to default en.`);
I18n.init(l);
} catch (error) {
console.warn(`Unsupported locale '${locale}'. Falling back to default en.`);
}
}
}