From a81d5645eae04c38f467cb81a81856e9bb276b72 Mon Sep 17 00:00:00 2001 From: zhengkunwang <31820853+zhengkunwang223@users.noreply.github.com> Date: Wed, 26 Feb 2025 16:18:53 +0800 Subject: [PATCH] feat: Change frontend locale code from 'tw' to 'zh-Hant' (#8010) --- frontend/src/App.vue | 2 +- frontend/src/api/index.ts | 2 +- frontend/src/lang/index.ts | 4 ++-- frontend/src/lang/modules/{tw.ts => zh-Hant.ts} | 0 frontend/src/utils/util.ts | 13 +++++++++++++ .../src/views/app-store/detail/params/index.vue | 15 +-------------- .../views/app-store/installed/detail/index.vue | 14 +------------- frontend/src/views/log/operation/index.vue | 4 ++-- .../src/views/login/components/login-form.vue | 4 ++-- frontend/src/views/setting/panel/index.vue | 2 +- .../views/website/runtime/php/create/index.vue | 14 +------------- 11 files changed, 25 insertions(+), 49 deletions(-) rename frontend/src/lang/modules/{tw.ts => zh-Hant.ts} (100%) diff --git a/frontend/src/App.vue b/frontend/src/App.vue index fbcd57517..069daca58 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -25,7 +25,7 @@ const config = reactive({ const i18nLocale = computed(() => { if (globalStore.language === 'zh') return zhCn; - if (globalStore.language === 'tw') return zhTw; + if (globalStore.language === 'zh-Hant') return zhTw; if (globalStore.language === 'en') return en; if (globalStore.language === 'ja') return ja; if (globalStore.language === 'ms') return ms; diff --git a/frontend/src/api/index.ts b/frontend/src/api/index.ts index 2765a3cd5..b0d86ca8b 100644 --- a/frontend/src/api/index.ts +++ b/frontend/src/api/index.ts @@ -22,7 +22,7 @@ class RequestHttp { this.service = axios.create(config); this.service.interceptors.request.use( (config: AxiosRequestConfig) => { - let language = globalStore.language === 'tw' ? 'zh-Hant' : globalStore.language; + let language = globalStore.language; config.headers = { 'Accept-Language': language, ...config.headers, diff --git a/frontend/src/lang/index.ts b/frontend/src/lang/index.ts index a84e26445..8b8f03f63 100644 --- a/frontend/src/lang/index.ts +++ b/frontend/src/lang/index.ts @@ -1,6 +1,6 @@ import { createI18n } from 'vue-i18n'; import zh from './modules/zh'; -import tw from './modules/tw'; +import zhHnat from './modules/zh-Hant'; import en from './modules/en'; import ptBr from './modules/pt-br'; import ja from './modules/ja'; @@ -15,7 +15,7 @@ const i18n = createI18n({ globalInjection: true, messages: { zh, - tw, + 'zh-Hant': zhHnat, en, 'pt-BR': ptBr, ja, diff --git a/frontend/src/lang/modules/tw.ts b/frontend/src/lang/modules/zh-Hant.ts similarity index 100% rename from frontend/src/lang/modules/tw.ts rename to frontend/src/lang/modules/zh-Hant.ts diff --git a/frontend/src/utils/util.ts b/frontend/src/utils/util.ts index c147bb4cb..0bff13ebb 100644 --- a/frontend/src/utils/util.ts +++ b/frontend/src/utils/util.ts @@ -625,6 +625,19 @@ export function getLanguage() { return localStorage.getItem('lang') || 'zh'; } +export function getLabel(row: any) { + const language = localStorage.getItem('lang') || 'zh'; + let lang = language == 'tw' ? 'zh-Hant' : language; + if (row.label && row.label[lang] != '') { + return row.label[lang]; + } + if (language == 'zh' || language == 'tw') { + return row.labelZh; + } else { + return row.labelEn; + } +} + export function emptyLineFilter(str: string, spilt: string) { let list = str.split(spilt); let results = []; diff --git a/frontend/src/views/app-store/detail/params/index.vue b/frontend/src/views/app-store/detail/params/index.vue index 6dd7fdc1a..a75f86e09 100644 --- a/frontend/src/views/app-store/detail/params/index.vue +++ b/frontend/src/views/app-store/detail/params/index.vue @@ -113,7 +113,7 @@ import { getRandomStr } from '@/utils/util'; import { getAppService } from '@/api/modules/app'; import { Rules } from '@/global/form-rules'; import { App } from '@/api/interface/app'; -import { getDBName } from '@/utils/util'; +import { getDBName, getLabel } from '@/utils/util'; import { getPathByType } from '@/api/modules/files'; interface ParamObj extends App.FromField { @@ -258,19 +258,6 @@ const changeService = (value: string, services: App.AppService[]) => { updateParam(); }; -const getLabel = (row: ParamObj): string => { - const language = localStorage.getItem('lang') || 'zh'; - let lang = language == 'tw' ? 'zh-Hant' : language; - if (row.label && row.label[lang] != '') { - return row.label[lang]; - } - if (language == 'zh' || language == 'tw') { - return row.labelZh; - } else { - return row.labelEn; - } -}; - const toPage = (key: string) => { window.location.href = '/apps/all?install=' + key; }; diff --git a/frontend/src/views/app-store/installed/detail/index.vue b/frontend/src/views/app-store/installed/detail/index.vue index 0fd4b5193..8a2494d71 100644 --- a/frontend/src/views/app-store/installed/detail/index.vue +++ b/frontend/src/views/app-store/installed/detail/index.vue @@ -121,6 +121,7 @@ import { reactive, ref } from 'vue'; import { FormInstance } from 'element-plus'; import { Rules, checkNumberRange } from '@/global/form-rules'; import { MsgSuccess } from '@/utils/message'; +import { getLabel } from '@/utils/util'; import i18n from '@/lang'; interface ParamProps { @@ -228,19 +229,6 @@ const get = async () => { } }; -const getLabel = (row: EditForm): string => { - const language = localStorage.getItem('lang') || 'zh'; - let lang = language == 'tw' ? 'zh-Hant' : language; - if (row.label && row.label[lang] != '') { - return row.label[lang]; - } - if (language == 'zh' || language == 'tw') { - return row.labelZh; - } else { - return row.labelEn; - } -}; - const submit = async (formEl: FormInstance) => { if (!formEl) return; await formEl.validate((valid) => { diff --git a/frontend/src/views/log/operation/index.vue b/frontend/src/views/log/operation/index.vue index 2b7919857..fa2b7cf88 100644 --- a/frontend/src/views/log/operation/index.vue +++ b/frontend/src/views/log/operation/index.vue @@ -46,7 +46,7 @@