vben
2021-11-10 3fcfac1f37c2aeabbb2af4897ada6ba8c225c667
src/locales/useLocale.ts
@@ -3,26 +3,15 @@
 */
import type { LocaleType } from '/#/config';
import moment from 'moment';
import { i18n } from './setupI18n';
import { useLocaleStoreWithOut } from '/@/store/modules/locale';
import { unref, computed } from 'vue';
import { loadLocalePool, setHtmlPageLang } from './helper';
interface LangModule {
  message: Recordable;
  momentLocale: Recordable;
  momentLocaleName: string;
}
const loadLocalePool: LocaleType[] = [];
export function setHtmlPageLang(locale: LocaleType) {
  document.querySelector('html')?.setAttribute('lang', locale);
}
export function setLoadLocalePool(cb: (loadLocalePool: LocaleType[]) => void) {
  cb(loadLocalePool);
  dateLocale: Recordable;
  dateLocaleName: string;
}
function setI18nLanguage(locale: LocaleType) {
@@ -34,7 +23,7 @@
    (i18n.global.locale as any).value = locale;
  }
  localeStore.setLocaleInfo({ locale });
  setHtmlPageLang(locale)
  setHtmlPageLang(locale);
}
export function useLocale() {
@@ -62,10 +51,9 @@
    const langModule = ((await import(`./lang/${locale}.ts`)) as any).default as LangModule;
    if (!langModule) return;
    const { message, momentLocale, momentLocaleName } = langModule;
    const { message } = langModule;
    globalI18n.setLocaleMessage(locale, message);
    moment.updateLocale(momentLocaleName, momentLocale);
    loadLocalePool.push(locale);
    setI18nLanguage(locale);