perf: optimize i18n to add the initial locale to the locale pool during initialization (#577)
This commit is contained in:
parent
2b76b88481
commit
ae3f8329c2
|
|
@ -3,6 +3,7 @@ import type { I18n, I18nOptions } from 'vue-i18n';
|
||||||
|
|
||||||
import { createI18n } from 'vue-i18n';
|
import { createI18n } from 'vue-i18n';
|
||||||
|
|
||||||
|
import { setLoadLocalePool } from './useLocale';
|
||||||
import { localeSetting } from '/@/settings/localeSetting';
|
import { localeSetting } from '/@/settings/localeSetting';
|
||||||
import { useLocaleStoreWithOut } from '/@/store/modules/locale';
|
import { useLocaleStoreWithOut } from '/@/store/modules/locale';
|
||||||
|
|
||||||
|
|
@ -16,6 +17,10 @@ async function createI18nOptions(): Promise<I18nOptions> {
|
||||||
const defaultLocal = await import(`./lang/${locale}.ts`);
|
const defaultLocal = await import(`./lang/${locale}.ts`);
|
||||||
const message = defaultLocal.default?.message ?? {};
|
const message = defaultLocal.default?.message ?? {};
|
||||||
|
|
||||||
|
setLoadLocalePool((loadLocalePool) => {
|
||||||
|
loadLocalePool.push(locale);
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
legacy: false,
|
legacy: false,
|
||||||
locale,
|
locale,
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,10 @@ interface LangModule {
|
||||||
|
|
||||||
const loadLocalePool: LocaleType[] = [];
|
const loadLocalePool: LocaleType[] = [];
|
||||||
|
|
||||||
|
export function setLoadLocalePool(cb: (loadLocalePool: LocaleType[]) => void) {
|
||||||
|
cb(loadLocalePool);
|
||||||
|
}
|
||||||
|
|
||||||
function setI18nLanguage(locale: LocaleType) {
|
function setI18nLanguage(locale: LocaleType) {
|
||||||
const localeStore = useLocaleStoreWithOut();
|
const localeStore = useLocaleStoreWithOut();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue