diff --git a/common/webapp/public/lang/no_nb.conf b/common/webapp/public/lang/nb.conf similarity index 100% rename from common/webapp/public/lang/no_nb.conf rename to common/webapp/public/lang/nb.conf diff --git a/common/webapp/public/lang/pt_PT.conf b/common/webapp/public/lang/pt-PT.conf similarity index 100% rename from common/webapp/public/lang/pt_PT.conf rename to common/webapp/public/lang/pt-PT.conf diff --git a/common/webapp/public/lang/settings.conf b/common/webapp/public/lang/settings.conf index 5f53f437..081e3bdc 100644 --- a/common/webapp/public/lang/settings.conf +++ b/common/webapp/public/lang/settings.conf @@ -1,5 +1,6 @@ { default: "en" + useBrowserLanguage: true languages: [ // remove the languages you don't need reorder them or add your own { locale: "cs", name: "Czech" } @@ -11,12 +12,12 @@ { locale: "lv", name: "Latviešu" } { locale: "hu", name: "Magyar" } { locale: "nl", name: "Nederlands" } - { locale: "no_nb", name: "Norsk bokmål" } + { locale: "nb", name: "Norsk bokmål" } { locale: "pl", name: "Polski" } - { locale: "pt_PT", name: "Português (Portugal)" } + { locale: "pt-PT", name: "Português (Portugal)" } { locale: "ru", name: "Русский" } - { locale: "sr_latn", name: "Srpski (latinica)" } - { locale: "sr_cyrl", name: "Српски (ћирилица)" } + { locale: "sr-Latn-RS", name: "Srpski (latinica)" } + { locale: "sr-Cyrl-RS", name: "Српски (ћирилица)" } { locale: "fi", name: "Suomi" } { locale: "es", name: "Spanish" } { locale: "sv", name: "Svenska" } @@ -24,9 +25,9 @@ { locale: "th", name: "ภาษาไทย" } { locale: "ua", name: "Українська" } { locale: "ja", name: "日本語" } - { locale: "zh_CN", name: "简体中文(中国大陆)" } - { locale: "zh_TW", name: "繁體中文(台灣)" } - { locale: "zh_HK", name: "繁體中文(香港特別行政區)" } + { locale: "zh-CN", name: "简体中文(中国大陆)" } + { locale: "zh-TW", name: "繁體中文(台灣)" } + { locale: "zh-HK", name: "繁體中文(香港特別行政區)" } { locale: "ko", name: "한국어" } { locale: "vi", name: "Tiếng Việt"} ] diff --git a/common/webapp/public/lang/sr_cyrl.conf b/common/webapp/public/lang/sr-Cyrl-RS.conf similarity index 100% rename from common/webapp/public/lang/sr_cyrl.conf rename to common/webapp/public/lang/sr-Cyrl-RS.conf diff --git a/common/webapp/public/lang/sr_latn.conf b/common/webapp/public/lang/sr-Latn-RS.conf similarity index 100% rename from common/webapp/public/lang/sr_latn.conf rename to common/webapp/public/lang/sr-Latn-RS.conf diff --git a/common/webapp/public/lang/zh_CN.conf b/common/webapp/public/lang/zh-CN.conf similarity index 100% rename from common/webapp/public/lang/zh_CN.conf rename to common/webapp/public/lang/zh-CN.conf diff --git a/common/webapp/public/lang/zh_HK.conf b/common/webapp/public/lang/zh-HK.conf similarity index 100% rename from common/webapp/public/lang/zh_HK.conf rename to common/webapp/public/lang/zh-HK.conf diff --git a/common/webapp/public/lang/zh_TW.conf b/common/webapp/public/lang/zh-TW.conf similarity index 100% rename from common/webapp/public/lang/zh_TW.conf rename to common/webapp/public/lang/zh-TW.conf diff --git a/common/webapp/src/components/Menu/SettingsMenu.vue b/common/webapp/src/components/Menu/SettingsMenu.vue index 8cc6e45e..2b2160e0 100644 --- a/common/webapp/src/components/Menu/SettingsMenu.vue +++ b/common/webapp/src/components/Menu/SettingsMenu.vue @@ -52,7 +52,7 @@ {{lang.name}} @@ -117,8 +117,9 @@ name: "SettingsMenu", let f = parseFloat(value); return f === 0 ? this.$t("renderDistance.off") : f.toFixed(0); }, - changeLanguage(lang) { - setLanguage(lang) + async changeLanguage(lang) { + await setLanguage(lang); + this.$bluemap.saveUserSettings(); } } } diff --git a/common/webapp/src/i18n.js b/common/webapp/src/i18n.js index fb5659f1..759a114f 100644 --- a/common/webapp/src/i18n.js +++ b/common/webapp/src/i18n.js @@ -32,6 +32,25 @@ export async function setLanguage(lang) { export async function loadLanguageSettings() { let settings = await fetchHocon(`./lang/settings.conf`); + let selectedLanguage = null; + + 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; + + let baseBrowserLanguage = browserLanguage.split('-')[0]; + selectedLanguage = availableLanguages.find(lang => lang.startsWith(baseBrowserLanguage)); + if (selectedLanguage) break; + } + } + + if (!selectedLanguage) { + selectedLanguage = settings.default; + } + i18n.languages = settings.languages; - await setLanguage(settings.default); + await setLanguage(selectedLanguage); }