i18n: fallback to french

This commit is contained in:
Jean-Baptiste Pasquier 2020-10-21 17:19:02 +02:00
parent 6e2738bd97
commit c279bffcaf
2 changed files with 11 additions and 4 deletions

View File

@ -16,7 +16,7 @@ class JsI18n {
this.setLocale(localStorage.getItem('language') || window.navigator.language.slice(0, 2)); this.setLocale(localStorage.getItem('language') || window.navigator.language.slice(0, 2));
} else { } else {
console.error('Language not found'); console.error('Language not found');
this.setLocale('en'); this.setLocale('fr');
} }
}; };
@ -105,14 +105,21 @@ class JsI18n {
result.json().then(e => { result.json().then(e => {
this.addLocale(locale, e); this.addLocale(locale, e);
this.processPage(); this.processPage();
}).catch(() => {
if (locale != "fr") {
console.warn(`Locale not found: ${locale}, fallback to french`);
this.setLocale("fr");
} else {
console.error("Language not found");
}
}); });
} }
}); });
this.locale = locale; this.locale = locale;
} catch { } catch {
if (locale != "en") { if (locale != "fr") {
console.warn(`Locale not found: ${locale}, fallback to english`); console.warn(`Locale not found: ${locale}, fallback to french`);
this.setLocale("en"); this.setLocale("fr");
} else { } else {
console.error("Language not found"); console.error("Language not found");
} }