useI18n.ts 387 B

12345678910111213141516
  1. import { createI18n } from 'vue-i18n';
  2. import { ref, watch } from 'vue';
  3. import type { I18nOptions } from 'vue-i18n';
  4. export function useI18n(options?: I18nOptions) {
  5. const i18n = createI18n(options);
  6. const localeRef = ref(i18n.global.locale);
  7. watch(localeRef, () => {
  8. i18n.global.locale = localeRef.value as any;
  9. });
  10. return {
  11. t: i18n.global.t,
  12. localeRef,
  13. };
  14. }