Fix language detection

This commit is contained in:
Made Baruna 2021-06-12 19:41:44 +07:00
parent 73450b37bf
commit 941be01185
No known key found for this signature in database
GPG key ID: 5AA5DA16AA5DCEAD

View file

@ -25,6 +25,7 @@ $locale.subscribe((value) => {
} }
}); });
const supportedLanguage = ['en', 'id', 'ru', 'ko', 'fr', 'zh', 'pt'];
addMessages('en', en); addMessages('en', en);
addMessages('id', id); addMessages('id', id);
addMessages('ru', ru); addMessages('ru', ru);
@ -34,11 +35,22 @@ addMessages('zh', zh);
addMessages('pt', pt); addMessages('pt', pt);
export function startClient() { export function startClient() {
let used = 'en';
const savedLocale = localStorage.getItem('locale'); const savedLocale = localStorage.getItem('locale');
const detectedLocale = getLocaleFromNavigator().substring(0, 2);
if (savedLocale !== null) {
if (!supportedLanguage.includes(savedLocale)) {
localStorage.setItem('locale', 'en');
} else {
used = savedLocale;
}
} else if (supportedLanguage.includes(detectedLocale)) {
used = detectedLocale;
}
init({ init({
...INIT_OPTIONS, ...INIT_OPTIONS,
initialLocale: savedLocale !== null ? savedLocale : getLocaleFromNavigator().substring(0, 2), initialLocale: used,
}); });
} }