Files
fe.ems.vue3/src/hooks/useI18n.ts
2023-09-05 14:38:23 +08:00

27 lines
591 B
TypeScript

import { computed } from 'vue';
import { useI18n } from 'vue-i18n';
import { localSet } from '@/utils/cache-local-utils';
import { CACHE_LOCAL_I18N } from '@/constants/cache-keys-constants';
export default function useLocale() {
//实例化i18n
const i18n = useI18n();
// 获取当前语言设置
const currentLocale = computed(() => {
return i18n.locale.value;
});
// 切换语言
const changeLocale = (value: string) => {
i18n.locale.value = value;
localSet(CACHE_LOCAL_I18N, value);
};
return {
currentLocale,
changeLocale,
t: i18n.t,
};
}