i18n.ts 674 B

1234567891011121314151617181920212223242526272829303132333435
  1. import { I18n, createI18n } from 'vue-i18n';
  2. import { HoppModule } from '.';
  3. import messages from '@intlify/unplugin-vue-i18n/messages';
  4. // A reference to the i18n instance
  5. let i18nInstance: I18n<
  6. Record<string, unknown>,
  7. Record<string, unknown>,
  8. Record<string, unknown>,
  9. string,
  10. false
  11. > | null = null;
  12. /**
  13. * Returns the i18n instance
  14. */
  15. export function getI18n() {
  16. return i18nInstance!.global.t;
  17. }
  18. export default <HoppModule>{
  19. onVueAppInit(app) {
  20. const i18n = createI18n({
  21. locale: 'en',
  22. messages,
  23. fallbackLocale: 'en',
  24. legacy: false,
  25. allowComposition: true,
  26. });
  27. app.use(i18n);
  28. i18nInstance = i18n;
  29. },
  30. };