From ae3f8329c25ef24c44c54690116fd7d3dc35ae85 Mon Sep 17 00:00:00 2001 From: 江麻妞 <50100681+jiangmaniu@users.noreply.github.com> Date: Tue, 11 May 2021 09:24:03 +0800 Subject: [PATCH] perf: optimize i18n to add the initial locale to the locale pool during initialization (#577) --- src/locales/setupI18n.ts | 5 +++++ src/locales/useLocale.ts | 4 ++++ 2 files changed, 9 insertions(+), 0 deletions(-) diff --git a/src/locales/setupI18n.ts b/src/locales/setupI18n.ts index 7f2a51f..2801a93 100644 --- a/src/locales/setupI18n.ts +++ b/src/locales/setupI18n.ts @@ -3,6 +3,7 @@ import type { I18n, I18nOptions } from 'vue-i18n'; import { createI18n } from 'vue-i18n'; +import { setLoadLocalePool } from './useLocale'; import { localeSetting } from '/@/settings/localeSetting'; import { useLocaleStoreWithOut } from '/@/store/modules/locale'; @@ -16,6 +17,10 @@ async function createI18nOptions(): Promise<I18nOptions> { const defaultLocal = await import(`./lang/${locale}.ts`); const message = defaultLocal.default?.message ?? {}; + setLoadLocalePool((loadLocalePool) => { + loadLocalePool.push(locale); + }); + return { legacy: false, locale, diff --git a/src/locales/useLocale.ts b/src/locales/useLocale.ts index 68c2ed6..f4f5b8f 100644 --- a/src/locales/useLocale.ts +++ b/src/locales/useLocale.ts @@ -17,6 +17,10 @@ interface LangModule { const loadLocalePool: LocaleType[] = []; +export function setLoadLocalePool(cb: (loadLocalePool: LocaleType[]) => void) { + cb(loadLocalePool); +} + function setI18nLanguage(locale: LocaleType) { const localeStore = useLocaleStoreWithOut(); -- libgit2 0.23.3