From cd652941cdf78e9d68dcd4f6053473fc7706c600 Mon Sep 17 00:00:00 2001 From: Li Kui <90845831+likui628@users.noreply.github.com> Date: Wed, 21 Aug 2024 10:06:06 +0800 Subject: [PATCH] fix: switching language does not load the translation of the component correctly (#4205) closes #4191 --- apps/web-antd/src/locales/index.ts | 2 +- apps/web-ele/src/locales/index.ts | 2 +- apps/web-naive/src/locales/index.ts | 2 +- packages/locales/src/i18n.ts | 7 ------- playground/src/locales/index.ts | 2 +- 5 files changed, 4 insertions(+), 11 deletions(-) diff --git a/apps/web-antd/src/locales/index.ts b/apps/web-antd/src/locales/index.ts index 4ee7511b9ef..c3fd8c84e3e 100644 --- a/apps/web-antd/src/locales/index.ts +++ b/apps/web-antd/src/locales/index.ts @@ -91,4 +91,4 @@ async function setupI18n(app: App, options: LocaleSetupOptions = {}) { }); } -export { $t, antdLocale, loadMessages, setupI18n }; +export { $t, antdLocale, setupI18n }; diff --git a/apps/web-ele/src/locales/index.ts b/apps/web-ele/src/locales/index.ts index 695cff56e09..0557333e08f 100644 --- a/apps/web-ele/src/locales/index.ts +++ b/apps/web-ele/src/locales/index.ts @@ -91,4 +91,4 @@ async function setupI18n(app: App, options: LocaleSetupOptions = {}) { }); } -export { $t, elementLocale, loadMessages, setupI18n }; +export { $t, elementLocale, setupI18n }; diff --git a/apps/web-naive/src/locales/index.ts b/apps/web-naive/src/locales/index.ts index a9eced60cd6..67595b0203e 100644 --- a/apps/web-naive/src/locales/index.ts +++ b/apps/web-naive/src/locales/index.ts @@ -28,4 +28,4 @@ async function setupI18n(app: App, options: LocaleSetupOptions = {}) { }); } -export { $t, loadMessages, setupI18n }; +export { $t, setupI18n }; diff --git a/packages/locales/src/i18n.ts b/packages/locales/src/i18n.ts index 82466399155..710e37c7d70 100644 --- a/packages/locales/src/i18n.ts +++ b/packages/locales/src/i18n.ts @@ -10,8 +10,6 @@ import type { import { type App, unref } from 'vue'; import { createI18n } from 'vue-i18n'; -const loadedLanguages = new Set(); - const i18n = createI18n({ globalInjection: true, legacy: false, @@ -78,10 +76,6 @@ async function loadLocaleMessages(lang: SupportedLanguagesType) { return setI18nLanguage(lang); } - if (loadedLanguages.has(lang)) { - return setI18nLanguage(lang); - } - const message = await localesMap[lang]?.(); if (message?.default) { @@ -91,7 +85,6 @@ async function loadLocaleMessages(lang: SupportedLanguagesType) { const mergeMessage = await loadMessages(lang); i18n.global.mergeLocaleMessage(lang, mergeMessage); - loadedLanguages.add(lang); return setI18nLanguage(lang); } diff --git a/playground/src/locales/index.ts b/playground/src/locales/index.ts index 4ee7511b9ef..c3fd8c84e3e 100644 --- a/playground/src/locales/index.ts +++ b/playground/src/locales/index.ts @@ -91,4 +91,4 @@ async function setupI18n(app: App, options: LocaleSetupOptions = {}) { }); } -export { $t, antdLocale, loadMessages, setupI18n }; +export { $t, antdLocale, setupI18n };