mirror of
https://github.com/BlueMap-Minecraft/BlueMap.git
synced 2025-01-15 04:41:44 +01:00
parent
7392447a35
commit
af2dad1d2f
@ -14,20 +14,24 @@ export const i18nModule = createI18n({
|
||||
export const i18n = i18nModule.global;
|
||||
|
||||
export async function setLanguage(lang) {
|
||||
loadLanguage(lang);
|
||||
|
||||
i18n.locale.value = lang;
|
||||
|
||||
document.querySelector('html').setAttribute('lang', lang);
|
||||
|
||||
return nextTick();
|
||||
}
|
||||
|
||||
async function loadLanguage(lang) {
|
||||
try {
|
||||
if (!i18n.availableLocales.includes(lang)){
|
||||
if (!i18n.availableLocales.includes(lang)) {
|
||||
let messages = await fetchHocon(`./lang/${lang}.conf`);
|
||||
i18n.setLocaleMessage(lang, messages);
|
||||
}
|
||||
|
||||
i18n.locale.value = lang;
|
||||
|
||||
document.querySelector('html').setAttribute('lang', lang);
|
||||
} catch (e) {
|
||||
console.error(`Failed to load language '${lang}'!`, e);
|
||||
}
|
||||
|
||||
return nextTick();
|
||||
}
|
||||
|
||||
export async function loadLanguageSettings() {
|
||||
@ -37,20 +41,24 @@ export async function loadLanguageSettings() {
|
||||
if (settings.useBrowserLanguage) {
|
||||
const availableLanguages = settings.languages.map(lang => lang.locale);
|
||||
|
||||
for (let browserLanguage of navigator.languages) {
|
||||
selectedLanguage = availableLanguages.find(lang => lang === browserLanguage);
|
||||
if (selectedLanguage) break;
|
||||
for (let browserLanguage of navigator.languages) {
|
||||
selectedLanguage = availableLanguages.find(lang => lang === browserLanguage);
|
||||
if (selectedLanguage) break;
|
||||
|
||||
let baseBrowserLanguage = browserLanguage.split('-')[0];
|
||||
selectedLanguage = availableLanguages.find(lang => lang.startsWith(baseBrowserLanguage));
|
||||
if (selectedLanguage) break;
|
||||
}
|
||||
let baseBrowserLanguage = browserLanguage.split('-')[0];
|
||||
selectedLanguage = availableLanguages.find(lang => lang.startsWith(baseBrowserLanguage));
|
||||
if (selectedLanguage) break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!selectedLanguage) {
|
||||
selectedLanguage = settings.default;
|
||||
}
|
||||
|
||||
await loadLanguage('en');
|
||||
await loadLanguage(settings.default);
|
||||
i18nModule.global.fallbackLocale = [settings.default, 'en'];
|
||||
|
||||
i18n.languages = settings.languages;
|
||||
await setLanguage(selectedLanguage);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user