From 2723b259dcbf06f3410654a1f9b8c8276834d65f Mon Sep 17 00:00:00 2001 From: umbor <14857490+umbors@users.noreply.github.com> Date: Sun, 11 Jun 2023 12:53:30 +0800 Subject: [PATCH] Add language detection and storage Save language setting to localstorage (first time using browser language) and fix some bugs in en-US.yaml --- webui/src/components/layout/ab-topbar.vue | 10 +++++++--- webui/src/locales/index.ts | 11 ++++++++++- webui/src/locales/lang/{en.yaml => en-US.yaml} | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-) rename webui/src/locales/lang/{en.yaml => en-US.yaml} (98%) diff --git a/webui/src/components/layout/ab-topbar.vue b/webui/src/components/layout/ab-topbar.vue index 4e13dd3c..5f8629ec 100644 --- a/webui/src/components/layout/ab-topbar.vue +++ b/webui/src/components/layout/ab-topbar.vue @@ -67,10 +67,14 @@ onUnmounted(() => { }); function changeLocale(){ - if(t.value === 'zh-CN'){ - t.value = locale.value = 'en' + if(localStorage.getItem('lang') === 'zh-CN'){ + locale.value = 'en-US'; + localStorage.setItem('lang', locale.value); + location.reload(); } else { - t.value = locale.value = 'zh-CN'; + locale.value = 'zh-CN'; + localStorage.setItem('lang', locale.value); + location.reload(); } } diff --git a/webui/src/locales/index.ts b/webui/src/locales/index.ts index cb6d0b77..d9faf181 100644 --- a/webui/src/locales/index.ts +++ b/webui/src/locales/index.ts @@ -1,9 +1,18 @@ import { createI18n } from 'vue-i18n'; import messages from '@intlify/unplugin-vue-i18n/messages' +//Default language is the same as last setting (undefined is browser language) +let lang = localStorage.getItem('lang'); +if(lang === null){ + const navLang = navigator.language || navigator.userLanguage; + let localLang = navLang || false; + lang = localLang || 'en-US'; +} +localStorage.setItem('lang', lang); + const i18n = createI18n({ legacy: false, - locale: 'zh-CN', + locale: lang, globalInjection: true, silentTranslationWarn: true, globalInstall: true, diff --git a/webui/src/locales/lang/en.yaml b/webui/src/locales/lang/en-US.yaml similarity index 98% rename from webui/src/locales/lang/en.yaml rename to webui/src/locales/lang/en-US.yaml index e23fcf00..ed748707 100644 --- a/webui/src/locales/lang/en.yaml +++ b/webui/src/locales/lang/en-US.yaml @@ -94,7 +94,7 @@ config: ssl: 'SSL' manageset: - title: 'Manage SEtting' + title: 'Manage Setting' enable: 'Enable' method: 'Rename Method' eps: 'EPS complete'