From 024783588e577a68c7e285dd83d1cae9bf9c0862 Mon Sep 17 00:00:00 2001 From: LiuHao <liuhaoai545@gmail.com> Date: 星期四, 11 一月 2024 14:27:46 +0800 Subject: [PATCH] update 升级@intlify/unplugin-vue-i18n版本依赖 update i18n使用方法。 add 新增i18n vite插件。 --- src/lang/index.ts | 14 +------ vite/plugins/i18n.ts | 6 +++ package.json | 8 ++-- src/lang/zh_CN.json | 25 ++++++++++++ vite/plugins/index.ts | 2 + src/App.vue | 3 - src/lang/en_US.json | 25 ++++++++++++ 7 files changed, 65 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 39fc03e..a93f63a 100644 --- a/package.json +++ b/package.json @@ -45,8 +45,8 @@ "vue-types": "5.1.1" }, "devDependencies": { - "@iconify/json": "2.2.157", - "@intlify/unplugin-vue-i18n": "1.6.0", + "@iconify/json": "2.2.167", + "@intlify/unplugin-vue-i18n": "2.0.0", "@types/crypto-js": "4.2.0", "@types/file-saver": "2.0.5", "@types/js-cookie": "3.0.5", @@ -82,9 +82,9 @@ "unplugin-vue-setup-extend-plus": "1.0.0", "vite-plugin-compression": "0.5.1", "vite-plugin-svg-icons": "2.0.1", - "vitest": "0.29.7", + "vitest": "1.1.3", "vue-eslint-parser": "9.3.2", - "vue-tsc": "0.35.0", + "vue-tsc": "1.8.27", "vite": "5.0.10" } } diff --git a/src/App.vue b/src/App.vue index a93790a..66dbed6 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,5 +1,5 @@ <template> - <el-config-provider :locale="appStore.locale" :size="size"> + <el-config-provider :locale="appStore.locale" :size="appStore.size"> <router-view /> </el-config-provider> </template> @@ -10,7 +10,6 @@ import useAppStore from '@/store/modules/app'; const appStore = useAppStore(); -const size = computed(() => appStore.size); onMounted(() => { nextTick(() => { diff --git a/src/lang/en_US.json b/src/lang/en_US.json new file mode 100644 index 0000000..17b472e --- /dev/null +++ b/src/lang/en_US.json @@ -0,0 +1,25 @@ +{ + "route": { + "dashboard": "Dashboard", + "document": "Document" + }, + "login": { + "username": "Username", + "password": "Password", + "login": "Login", + "code": "Verification Code", + "copyright": "" + }, + "navbar": { + "full": "Full Screen", + "language": "Language", + "dashboard": "Dashboard", + "document": "Document", + "message": "Message", + "layoutSize": "Layout Size", + "selectTenant": "Select Tenant", + "layoutSetting": "Layout Setting", + "personalCenter": "Personal Center", + "logout": "Logout" + } +} diff --git a/src/lang/index.ts b/src/lang/index.ts index 071599e..2b4c027 100644 --- a/src/lang/index.ts +++ b/src/lang/index.ts @@ -1,19 +1,8 @@ // 鑷畾涔夊浗闄呭寲閰嶇疆 import { createI18n } from 'vue-i18n'; -// 鏈湴璇█鍖� -import enUSLocale from './en_US'; -import zhCNLocale from './zh_CN'; import { LanguageEnum } from '@/enums/LanguageEnum'; - -const messages = { - zh_CN: { - ...zhCNLocale - }, - en_US: { - ...enUSLocale - } -}; +import messages from '@intlify/unplugin-vue-i18n/messages'; /** * 鑾峰彇褰撳墠璇█ @@ -28,6 +17,7 @@ }; const i18n = createI18n({ + globalInjection: true, legacy: false, locale: getLanguage(), messages diff --git a/src/lang/zh_CN.json b/src/lang/zh_CN.json new file mode 100644 index 0000000..071598d --- /dev/null +++ b/src/lang/zh_CN.json @@ -0,0 +1,25 @@ +{ + "route": { + "dashboard": "棣栭〉", + "document": "椤圭洰鏂囨。" + }, + "login": { + "username": "鐢ㄦ埛鍚�", + "password": "瀵嗙爜", + "login": "鐧� 褰�", + "code": "璇疯緭鍏ラ獙璇佺爜", + "copyright": "" + }, + "navbar": { + "full": "鍏ㄥ睆", + "language": "璇█", + "dashboard": "棣栭〉", + "document": "椤圭洰鏂囨。", + "message": "娑堟伅", + "layoutSize": "甯冨眬澶у皬", + "selectTenant": "閫夋嫨绉熸埛", + "layoutSetting": "甯冨眬璁剧疆", + "personalCenter": "涓汉涓績", + "logout": "閫�鍑虹櫥褰�" + } +} diff --git a/vite/plugins/i18n.ts b/vite/plugins/i18n.ts new file mode 100644 index 0000000..8777d1a --- /dev/null +++ b/vite/plugins/i18n.ts @@ -0,0 +1,6 @@ +import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite'; +export default (path: any) => { + return VueI18nPlugin({ + include: [path.resolve(__dirname, '../../src/lang/**.json')] + }); +}; diff --git a/vite/plugins/index.ts b/vite/plugins/index.ts index 30b2835..0ec5b8d 100644 --- a/vite/plugins/index.ts +++ b/vite/plugins/index.ts @@ -6,6 +6,7 @@ import createSvgIconsPlugin from './svg-icon'; import createCompression from './compression'; import createSetupExtend from './setup-extend'; +import createI18n from './i18n'; import path from 'path'; export default (viteEnv: any, isBuild = false): [] => { @@ -18,5 +19,6 @@ vitePlugins.push(createIcons()); vitePlugins.push(createSvgIconsPlugin(path, isBuild)); vitePlugins.push(createSetupExtend()); + vitePlugins.push(createI18n(path)); return vitePlugins; }; -- Gitblit v1.9.3