From 0b83bfbbd212c442f5f97a8f92f89414988edef2 Mon Sep 17 00:00:00 2001 From: baiqi Date: Tue, 13 Aug 2024 09:46:49 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E8=AF=AD=E8=A8=80):=20=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E8=AF=AD=E8=A8=80=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/locale/useLocale.ts | 1 + frontend/src/main.ts | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/frontend/src/locale/useLocale.ts b/frontend/src/locale/useLocale.ts index 435d2062d2..c4b53690cd 100644 --- a/frontend/src/locale/useLocale.ts +++ b/frontend/src/locale/useLocale.ts @@ -35,6 +35,7 @@ async function changeLocale(locale: LocaleType) { const globalI18n = i18n.global; const currentLocale = unref(globalI18n.locale); if (currentLocale === locale) { + setI18nLanguage(locale); // 初始化的时候需要设置一次本地语言 return locale; } Message.loading(currentLocale === 'zh-CN' ? '语言切换中...' : 'Language switching...'); diff --git a/frontend/src/main.ts b/frontend/src/main.ts index c8c5da371f..ff9bc095b9 100644 --- a/frontend/src/main.ts +++ b/frontend/src/main.ts @@ -27,9 +27,10 @@ async function bootstrap() { // 注册国际化,需要异步阻塞,确保语言包加载完毕 await setupI18n(app); // 获取默认语言 - const defaultLocale = await getDefaultLocale(); - const { currentLocale, changeLocale } = useLocale(); - if (currentLocale.value !== defaultLocale) { + const localLocale = localStorage.getItem('MS-locale'); + if (!localLocale) { + const defaultLocale = await getDefaultLocale(); + const { changeLocale } = useLocale(); changeLocale(defaultLocale); }