setupI18n.ts 861 B

12345678910111213141516171819202122232425262728293031
  1. import type { App } from 'vue';
  2. import type { I18n, I18nOptions } from 'vue-i18n';
  3. import { createI18n } from 'vue-i18n';
  4. import 'moment/dist/locale/zh-cn';
  5. import projectSetting from '/@/settings/projectSetting';
  6. import messages from './getMessage';
  7. const { lang, availableLocales, fallback } = projectSetting?.locale;
  8. const localeData: I18nOptions = {
  9. legacy: false,
  10. locale: lang,
  11. fallbackLocale: fallback,
  12. messages,
  13. availableLocales: availableLocales,
  14. sync: true, //If you don’t want to inherit locale from global scope, you need to set sync of i18n component option to false.
  15. silentTranslationWarn: true, // true - warning off
  16. missingWarn: false,
  17. silentFallbackWarn: true,
  18. };
  19. export let i18n: I18n;
  20. // setup i18n instance with glob
  21. export function setupI18n(app: App) {
  22. i18n = createI18n(localeData) as I18n;
  23. app.use(i18n);
  24. }