diff --git a/frontend/src/i18n/index.ts b/frontend/src/i18n/index.ts new file mode 100644 index 0000000..7678887 --- /dev/null +++ b/frontend/src/i18n/index.ts @@ -0,0 +1,35 @@ +import { createI18n } from 'vue-i18n' +import en from './en.json' +import zhCN from './zh-CN.json' +import elementEnLocale from 'element-plus-secondary/es/locale/lang/en' +import elementZhLocale from 'element-plus-secondary/es/locale/lang/zh-cn' +import { useCache } from '@/utils/useCache' +const { wsCache } = useCache() + +const getDefaultLocale = () => { + const language = wsCache.get('user.language') + return language || 'zh-CN' +} + +const messages = { + en: { + ...en, + el: elementEnLocale, + }, + 'zh-CN': { + ...zhCN, + el: elementZhLocale, + }, +} + +export const i18n = createI18n({ + legacy: false, + locale: getDefaultLocale(), + fallbackLocale: 'en', + globalInjection: true, + messages, +}) + +export const getElementLocale = () => { + return i18n.global.locale.value === 'en' ? elementEnLocale : elementZhLocale +}