mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-22 18:07:31 -07:00
Always fetch locales when initiating client
This commit is contained in:
parent
f793b9ecd7
commit
e875bfc5d7
1 changed files with 22 additions and 27 deletions
|
@ -22,37 +22,32 @@
|
||||||
renderError('SOMETHING_HAPPENED_IN_PROMISE', e);
|
renderError('SOMETHING_HAPPENED_IN_PROMISE', e);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//#region Detect language & fetch translations
|
||||||
const v = localStorage.getItem('v') || VERSION;
|
const v = localStorage.getItem('v') || VERSION;
|
||||||
|
|
||||||
//#region Detect language & fetch translations
|
const supportedLangs = LANGS;
|
||||||
const localeVersion = localStorage.getItem('localeVersion');
|
let lang = localStorage.getItem('lang');
|
||||||
const localeOutdated = (localeVersion == null || localeVersion !== v);
|
if (lang == null || !supportedLangs.includes(lang)) {
|
||||||
|
if (supportedLangs.includes(navigator.language)) {
|
||||||
if (!localStorage.hasOwnProperty('locale') || localeOutdated) {
|
lang = navigator.language;
|
||||||
const supportedLangs = LANGS;
|
|
||||||
let lang = localStorage.getItem('lang');
|
|
||||||
if (lang == null || !supportedLangs.includes(lang)) {
|
|
||||||
if (supportedLangs.includes(navigator.language)) {
|
|
||||||
lang = navigator.language;
|
|
||||||
} else {
|
|
||||||
lang = supportedLangs.find(x => x.split('-')[0] === navigator.language);
|
|
||||||
|
|
||||||
// Fallback
|
|
||||||
if (lang == null) lang = 'en-US';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const res = await fetch(`/assets/locales/${lang}.${v}.json`);
|
|
||||||
if (res.status === 200) {
|
|
||||||
localStorage.setItem('lang', lang);
|
|
||||||
localStorage.setItem('locale', await res.text());
|
|
||||||
localStorage.setItem('localeVersion', v);
|
|
||||||
} else {
|
} else {
|
||||||
await checkUpdate();
|
lang = supportedLangs.find(x => x.split('-')[0] === navigator.language);
|
||||||
renderError('LOCALE_FETCH');
|
|
||||||
return;
|
// Fallback
|
||||||
|
if (lang == null) lang = 'en-US';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const res = await fetch(`/assets/locales/${lang}.${v}.json`);
|
||||||
|
if (res.status === 200) {
|
||||||
|
localStorage.setItem('lang', lang);
|
||||||
|
localStorage.setItem('locale', await res.text());
|
||||||
|
localStorage.setItem('localeVersion', v);
|
||||||
|
} else {
|
||||||
|
await checkUpdate();
|
||||||
|
renderError('LOCALE_FETCH');
|
||||||
|
return;
|
||||||
|
}
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
//#region Script
|
//#region Script
|
||||||
|
|
Loading…
Reference in a new issue