From 99f031f8ffe66c35f0ad7c86359fb11044c28b7a Mon Sep 17 00:00:00 2001 From: KUN1007 Date: Sat, 20 May 2023 02:23:25 +0800 Subject: [PATCH] i18n support --- package-lock.json | 146 ++++++++++++++++++ package.json | 1 + src/components/KUNGalgameTopBar.vue | 20 +-- .../setting-panel/KUNGalgameSettingPanel.vue | 48 +++++- src/config/setting-panel.ts | 35 +---- src/hooks/useLang.ts | 26 ++++ src/language/en.ts | 5 + src/language/i18n.ts | 19 +++ src/language/zh.ts | 5 + src/main.ts | 6 +- src/utils/cache/cache-key.ts | 2 + src/utils/cache/local-storage.ts | 17 ++ src/utils/http.ts | 3 + 13 files changed, 279 insertions(+), 54 deletions(-) create mode 100644 src/hooks/useLang.ts create mode 100644 src/language/en.ts create mode 100644 src/language/i18n.ts create mode 100644 src/language/zh.ts create mode 100644 src/utils/http.ts diff --git a/package-lock.json b/package-lock.json index 7748f8fb..8c061069 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ "axios": "^1.4.0", "pinia": "^2.0.35", "vue": "^3.2.47", + "vue-i18n": "^9.3.0-beta.17", "vue-router": "^4.1.6" }, "devDependencies": { @@ -425,6 +426,78 @@ "vue": ">=3" } }, + "node_modules/@intlify/core-base": { + "version": "9.3.0-beta.17", + "resolved": "https://registry.npmjs.org/@intlify/core-base/-/core-base-9.3.0-beta.17.tgz", + "integrity": "sha512-M/ZUU53G68YKN59E2gd/bOZB4TvFMWXvpWIgwsLJeAjktKYOt7JDSGdGHYGivKAG12pTGWeIeY6WmJCaDenloA==", + "dependencies": { + "@intlify/devtools-if": "9.3.0-beta.17", + "@intlify/message-compiler": "9.3.0-beta.17", + "@intlify/shared": "9.3.0-beta.17", + "@intlify/vue-devtools": "9.3.0-beta.17" + }, + "engines": { + "node": ">= 14" + }, + "funding": { + "url": "https://github.com/sponsors/kazupon" + } + }, + "node_modules/@intlify/devtools-if": { + "version": "9.3.0-beta.17", + "resolved": "https://registry.npmjs.org/@intlify/devtools-if/-/devtools-if-9.3.0-beta.17.tgz", + "integrity": "sha512-up5vm1ytN9Wm/loKjFlp5TuDy7dmBVgU3UOk1vLUXUfYH+EMlm07pUXNiIpSjdt4Eak+bSLfsWcqPwhsb2jknw==", + "dependencies": { + "@intlify/shared": "9.3.0-beta.17" + }, + "engines": { + "node": ">= 14" + }, + "funding": { + "url": "https://github.com/sponsors/kazupon" + } + }, + "node_modules/@intlify/message-compiler": { + "version": "9.3.0-beta.17", + "resolved": "https://registry.npmjs.org/@intlify/message-compiler/-/message-compiler-9.3.0-beta.17.tgz", + "integrity": "sha512-i7hvVIRk1Ax2uKa9xLRJCT57to08OhFMhFXXjWN07rmx5pWQYQ23MfX1xgggv9drnWTNhqEiD+u4EJeHoS5+Ww==", + "dependencies": { + "@intlify/shared": "9.3.0-beta.17", + "source-map": "0.6.1" + }, + "engines": { + "node": ">= 14" + }, + "funding": { + "url": "https://github.com/sponsors/kazupon" + } + }, + "node_modules/@intlify/shared": { + "version": "9.3.0-beta.17", + "resolved": "https://registry.npmjs.org/@intlify/shared/-/shared-9.3.0-beta.17.tgz", + "integrity": "sha512-mscf7RQsUTOil35jTij4KGW1RC9SWQjYScwLxP53Ns6g24iEd5HN7ksbt9O6FvTmlQuX77u+MXpBdfJsGqizLQ==", + "engines": { + "node": ">= 14" + }, + "funding": { + "url": "https://github.com/sponsors/kazupon" + } + }, + "node_modules/@intlify/vue-devtools": { + "version": "9.3.0-beta.17", + "resolved": "https://registry.npmjs.org/@intlify/vue-devtools/-/vue-devtools-9.3.0-beta.17.tgz", + "integrity": "sha512-Wzl+3kZONjYG3lL8I8G+4H46s7m3CkxyoZXjZgC0zMy51cq1OTlOuOohcgxpwcSSYYVj9Y86PvlSakPNqHEweA==", + "dependencies": { + "@intlify/core-base": "9.3.0-beta.17", + "@intlify/shared": "9.3.0-beta.17" + }, + "engines": { + "node": ">= 14" + }, + "funding": { + "url": "https://github.com/sponsors/kazupon" + } + }, "node_modules/@jridgewell/gen-mapping": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.3.tgz", @@ -2125,6 +2198,26 @@ "@vue/shared": "3.2.47" } }, + "node_modules/vue-i18n": { + "version": "9.3.0-beta.17", + "resolved": "https://registry.npmjs.org/vue-i18n/-/vue-i18n-9.3.0-beta.17.tgz", + "integrity": "sha512-2r6QWgwCMjzpLb6RuIU8XPw8vU9kJu8OE4zGIOOnNq1gMYrzawO1LlK/yxG7ugWmzFA/IBqSIs6ADu0Z+PO/Ow==", + "dependencies": { + "@intlify/core-base": "9.3.0-beta.17", + "@intlify/shared": "9.3.0-beta.17", + "@intlify/vue-devtools": "9.3.0-beta.17", + "@vue/devtools-api": "^6.2.1" + }, + "engines": { + "node": ">= 14" + }, + "funding": { + "url": "https://github.com/sponsors/kazupon" + }, + "peerDependencies": { + "vue": "^3.0.0" + } + }, "node_modules/vue-router": { "version": "4.1.6", "resolved": "https://registry.npmjs.org/vue-router/-/vue-router-4.1.6.tgz", @@ -2407,6 +2500,48 @@ "@iconify/types": "^2.0.0" } }, + "@intlify/core-base": { + "version": "9.3.0-beta.17", + "resolved": "https://registry.npmjs.org/@intlify/core-base/-/core-base-9.3.0-beta.17.tgz", + "integrity": "sha512-M/ZUU53G68YKN59E2gd/bOZB4TvFMWXvpWIgwsLJeAjktKYOt7JDSGdGHYGivKAG12pTGWeIeY6WmJCaDenloA==", + "requires": { + "@intlify/devtools-if": "9.3.0-beta.17", + "@intlify/message-compiler": "9.3.0-beta.17", + "@intlify/shared": "9.3.0-beta.17", + "@intlify/vue-devtools": "9.3.0-beta.17" + } + }, + "@intlify/devtools-if": { + "version": "9.3.0-beta.17", + "resolved": "https://registry.npmjs.org/@intlify/devtools-if/-/devtools-if-9.3.0-beta.17.tgz", + "integrity": "sha512-up5vm1ytN9Wm/loKjFlp5TuDy7dmBVgU3UOk1vLUXUfYH+EMlm07pUXNiIpSjdt4Eak+bSLfsWcqPwhsb2jknw==", + "requires": { + "@intlify/shared": "9.3.0-beta.17" + } + }, + "@intlify/message-compiler": { + "version": "9.3.0-beta.17", + "resolved": "https://registry.npmjs.org/@intlify/message-compiler/-/message-compiler-9.3.0-beta.17.tgz", + "integrity": "sha512-i7hvVIRk1Ax2uKa9xLRJCT57to08OhFMhFXXjWN07rmx5pWQYQ23MfX1xgggv9drnWTNhqEiD+u4EJeHoS5+Ww==", + "requires": { + "@intlify/shared": "9.3.0-beta.17", + "source-map": "0.6.1" + } + }, + "@intlify/shared": { + "version": "9.3.0-beta.17", + "resolved": "https://registry.npmjs.org/@intlify/shared/-/shared-9.3.0-beta.17.tgz", + "integrity": "sha512-mscf7RQsUTOil35jTij4KGW1RC9SWQjYScwLxP53Ns6g24iEd5HN7ksbt9O6FvTmlQuX77u+MXpBdfJsGqizLQ==" + }, + "@intlify/vue-devtools": { + "version": "9.3.0-beta.17", + "resolved": "https://registry.npmjs.org/@intlify/vue-devtools/-/vue-devtools-9.3.0-beta.17.tgz", + "integrity": "sha512-Wzl+3kZONjYG3lL8I8G+4H46s7m3CkxyoZXjZgC0zMy51cq1OTlOuOohcgxpwcSSYYVj9Y86PvlSakPNqHEweA==", + "requires": { + "@intlify/core-base": "9.3.0-beta.17", + "@intlify/shared": "9.3.0-beta.17" + } + }, "@jridgewell/gen-mapping": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.3.tgz", @@ -3678,6 +3813,17 @@ "@vue/shared": "3.2.47" } }, + "vue-i18n": { + "version": "9.3.0-beta.17", + "resolved": "https://registry.npmjs.org/vue-i18n/-/vue-i18n-9.3.0-beta.17.tgz", + "integrity": "sha512-2r6QWgwCMjzpLb6RuIU8XPw8vU9kJu8OE4zGIOOnNq1gMYrzawO1LlK/yxG7ugWmzFA/IBqSIs6ADu0Z+PO/Ow==", + "requires": { + "@intlify/core-base": "9.3.0-beta.17", + "@intlify/shared": "9.3.0-beta.17", + "@intlify/vue-devtools": "9.3.0-beta.17", + "@vue/devtools-api": "^6.2.1" + } + }, "vue-router": { "version": "4.1.6", "resolved": "https://registry.npmjs.org/vue-router/-/vue-router-4.1.6.tgz", diff --git a/package.json b/package.json index a466fec7..bbad6ff2 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "axios": "^1.4.0", "pinia": "^2.0.35", "vue": "^3.2.47", + "vue-i18n": "^9.3.0-beta.17", "vue-router": "^4.1.6" }, "devDependencies": { diff --git a/src/components/KUNGalgameTopBar.vue b/src/components/KUNGalgameTopBar.vue index 911b6056..d5d69fa8 100644 --- a/src/components/KUNGalgameTopBar.vue +++ b/src/components/KUNGalgameTopBar.vue @@ -12,6 +12,11 @@ import router from '@/router' // 导入设置面板 store import { useSettingsPanelStore } from '@/store/modules/settings' import { storeToRefs } from 'pinia' +// 导入 i18n +import { useI18n } from 'vue-i18n' + +// 引入 i18n +const { t } = useI18n() // 接收设置面板的 store const settingsStore = useSettingsPanelStore() @@ -82,7 +87,7 @@ onBeforeMount(() => {})
KUNgal - KUNGalgame + {{ t('header.name') }}