Browse Source

fix: switching language does not load the translation of the component correctly (#4205)

closes #4191
pull/4212/head
Li Kui 1 year ago
committed by GitHub
parent
commit
cd652941cd
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 2
      apps/web-antd/src/locales/index.ts
  2. 2
      apps/web-ele/src/locales/index.ts
  3. 2
      apps/web-naive/src/locales/index.ts
  4. 7
      packages/locales/src/i18n.ts
  5. 2
      playground/src/locales/index.ts

2
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 };

2
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 };

2
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 };

7
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<string>();
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);
}

2
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 };

Loading…
Cancel
Save