feat: Support dayjs and component library in multiple languages

This commit is contained in:
vben
2024-06-30 15:42:30 +08:00
parent ca1cad0cd3
commit 1d70d71537
15 changed files with 99 additions and 20 deletions

View File

@@ -1,13 +1,22 @@
import type { LocaleSetupOptions } from './typing';
import type { LocaleSetupOptions, SupportedLanguagesType } from './typing';
import type { App } from 'vue';
import { i18n, loadLocaleMessages } from './i18n';
import { i18n, loadI18nMessages } from './i18n';
const $t = i18n.global.t;
let loadThirdPartyMessage: (lang: SupportedLanguagesType) => Promise<void>;
async function loadLocaleMessages(lang: SupportedLanguagesType) {
await loadI18nMessages(lang);
await loadThirdPartyMessage(lang);
}
async function setupI18n(app: App, options: LocaleSetupOptions = {}) {
const { defaultLocale = 'zh-CN' } = options;
// app可以自行扩展一些第三方库和组件库的国际化
loadThirdPartyMessage = options.loadThirdPartyMessage || (async () => {});
app.use(i18n);
await loadLocaleMessages(defaultLocale);
}