index.ts 867 B

1234567891011121314151617181920212223242526
  1. import type { LocaleSetupOptions, SupportedLanguagesType } from './typing';
  2. import type { App } from 'vue';
  3. import { i18n, loadI18nMessages } from './i18n';
  4. const $t = i18n.global.t;
  5. let loadThirdPartyMessage: (lang: SupportedLanguagesType) => Promise<void>;
  6. async function loadLocaleMessages(lang: SupportedLanguagesType) {
  7. await loadI18nMessages(lang);
  8. await loadThirdPartyMessage(lang);
  9. }
  10. async function setupI18n(app: App, options: LocaleSetupOptions = {}) {
  11. const { defaultLocale = 'zh-CN' } = options;
  12. // app可以自行扩展一些第三方库和组件库的国际化
  13. loadThirdPartyMessage = options.loadThirdPartyMessage || (async () => {});
  14. app.use(i18n);
  15. await loadLocaleMessages(defaultLocale);
  16. }
  17. export { $t, loadLocaleMessages, setupI18n };
  18. export type { CompileError } from '@intlify/core-base';
  19. export { useI18n } from 'vue-i18n';