Skip to content

Commit

Permalink
perf: optimize i18n to add the initial locale to the locale pool duri…
Browse files Browse the repository at this point in the history
…ng initialization (#577)
  • Loading branch information
jiangmaniu authored May 11, 2021
1 parent 2b76b88 commit ae3f832
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/locales/setupI18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions src/locales/useLocale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit ae3f832

Please sign in to comment.