Commit ae3f8329c25ef24c44c54690116fd7d3dc35ae85
Committed by
GitHub
1 parent
2b76b884
perf: optimize i18n to add the initial locale to the locale pool during initialization (#577)
Showing
2 changed files
with
9 additions
and
0 deletions
src/locales/setupI18n.ts
@@ -3,6 +3,7 @@ import type { I18n, I18nOptions } from 'vue-i18n'; | @@ -3,6 +3,7 @@ import type { I18n, I18nOptions } from 'vue-i18n'; | ||
3 | 3 | ||
4 | import { createI18n } from 'vue-i18n'; | 4 | import { createI18n } from 'vue-i18n'; |
5 | 5 | ||
6 | +import { setLoadLocalePool } from './useLocale'; | ||
6 | import { localeSetting } from '/@/settings/localeSetting'; | 7 | import { localeSetting } from '/@/settings/localeSetting'; |
7 | import { useLocaleStoreWithOut } from '/@/store/modules/locale'; | 8 | import { useLocaleStoreWithOut } from '/@/store/modules/locale'; |
8 | 9 | ||
@@ -16,6 +17,10 @@ async function createI18nOptions(): Promise<I18nOptions> { | @@ -16,6 +17,10 @@ async function createI18nOptions(): Promise<I18nOptions> { | ||
16 | const defaultLocal = await import(`./lang/${locale}.ts`); | 17 | const defaultLocal = await import(`./lang/${locale}.ts`); |
17 | const message = defaultLocal.default?.message ?? {}; | 18 | const message = defaultLocal.default?.message ?? {}; |
18 | 19 | ||
20 | + setLoadLocalePool((loadLocalePool) => { | ||
21 | + loadLocalePool.push(locale); | ||
22 | + }); | ||
23 | + | ||
19 | return { | 24 | return { |
20 | legacy: false, | 25 | legacy: false, |
21 | locale, | 26 | locale, |
src/locales/useLocale.ts
@@ -17,6 +17,10 @@ interface LangModule { | @@ -17,6 +17,10 @@ interface LangModule { | ||
17 | 17 | ||
18 | const loadLocalePool: LocaleType[] = []; | 18 | const loadLocalePool: LocaleType[] = []; |
19 | 19 | ||
20 | +export function setLoadLocalePool(cb: (loadLocalePool: LocaleType[]) => void) { | ||
21 | + cb(loadLocalePool); | ||
22 | +} | ||
23 | + | ||
20 | function setI18nLanguage(locale: LocaleType) { | 24 | function setI18nLanguage(locale: LocaleType) { |
21 | const localeStore = useLocaleStoreWithOut(); | 25 | const localeStore = useLocaleStoreWithOut(); |
22 | 26 |