From 7042f2f755157e27ea4649434fb96b2ac89fe4b4 Mon Sep 17 00:00:00 2001 From: inter Date: Mon, 8 Sep 2025 16:36:41 +0800 Subject: [PATCH] Add File --- frontend/src/i18n/index.ts | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 frontend/src/i18n/index.ts 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 +}