From 18d490f3716b86f99c00cb3150e444ead2e69021 Mon Sep 17 00:00:00 2001 From: viarotel Date: Mon, 23 Oct 2023 18:14:41 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=9A=80=20=E6=B7=BB=E5=8A=A0=20i18?= =?UTF-8?q?n=20=E5=88=9D=E6=AD=A5=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 8 +++++++- electron/helpers/process.js | 2 ++ package.json | 2 ++ src/App.vue | 6 +++--- src/locales/en_US.json | 15 +++++++++++++++ src/locales/zh_CN.json | 35 +++++++++++++++++++++++++++++++++++ src/main.js | 12 ++++++++++++ vite.config.js | 4 ++++ 8 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 src/locales/en_US.json create mode 100644 src/locales/zh_CN.json diff --git a/.vscode/settings.json b/.vscode/settings.json index 47cca10..6e2cf5c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -28,5 +28,11 @@ }, "[json]": { "editor.defaultFormatter": "esbenp.prettier-vscode" - } + }, + "i18n-ally.localesPaths": [ + "src/locales", + "dist-release/win-arm64-unpacked/locales", + "dist-release/win-unpacked/locales" + ], + "i18n-ally.sourceLanguage": "en" } diff --git a/electron/helpers/process.js b/electron/helpers/process.js index bddb7db..4a507c9 100644 --- a/electron/helpers/process.js +++ b/electron/helpers/process.js @@ -13,3 +13,5 @@ process.env.IS_PACKAGED = JSON.stringify(app.isPackaged) process.env.DESKTOP_PATH = app.getPath('desktop') process.env.CWD = process.cwd() + +process.env.LOCALE = process.env.LANG?.split('.')?.[0] || 'zh_CN' diff --git a/package.json b/package.json index 2148027..6cdf790 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "@devicefarmer/adbkit": "^3.2.5", "@electron-toolkit/preload": "^2.0.0", "@electron-toolkit/utils": "^2.0.1", + "@intlify/unplugin-vue-i18n": "^1.4.0", "@viarotel-org/design": "^0.7.0", "@viarotel-org/eslint-config": "^0.7.0", "@viarotel-org/postcss-config": "^0.7.0", @@ -45,6 +46,7 @@ "vite-plugin-electron-renderer": "^0.14.5", "vite-plugin-eslint": "^1.8.1", "vite-svg-loader": "^4.0.0", + "vue-i18n": "^9.5.0", "which": "^4.0.0" } } diff --git a/src/App.vue b/src/App.vue index fce6be6..80e4f08 100644 --- a/src/App.vue +++ b/src/App.vue @@ -29,15 +29,15 @@ export default { return { tabsModel: [ { - label: '设备列表', + label: this.$t('devices'), prop: 'Device', }, { - label: '偏好设置', + label: this.$t('preferences'), prop: 'Preference', }, { - label: '关于', + label: this.$t('about'), prop: 'About', }, ], diff --git a/src/locales/en_US.json b/src/locales/en_US.json new file mode 100644 index 0000000..f708fb4 --- /dev/null +++ b/src/locales/en_US.json @@ -0,0 +1,15 @@ +{ + "// 设备列表": true, + + "devices": "Devices", + + "// 偏好设备": true, + + "preferences": "Preferences", + + "// 关于": true, + + "about": "About", + + "// 底部占位符": true +} diff --git a/src/locales/zh_CN.json b/src/locales/zh_CN.json new file mode 100644 index 0000000..dd1e7f9 --- /dev/null +++ b/src/locales/zh_CN.json @@ -0,0 +1,35 @@ +{ + "// 设备列表": true, + + "wireless-connection": "无线连接", + "connected-device": "连接设备", + "refresh-device": "刷新设备", + "restart-service": "重启服务", + + "device-id": "设备 ID", + "device-name": "设备名称", + "devices": "设备列表", + "operate": "操作", + + "install-app": "安装应用", + "screen-capture": "截取屏幕", + "reboot-device": "重启设备", + "power-key": "电源键", + "notification-bar": "通知栏", + "return-key": "切换键", + "home-key": "切换键", + "switch-key": "切换键", + "wireless-mode": "无线模式", + "start-recording": "开始录制", + "start-mirror": "开始镜像", + + "// 偏好设备": true, + + "preferences": "偏好设置", + + "// 关于": true, + + "about": "关于", + + "// 底部占位符": true +} diff --git a/src/main.js b/src/main.js index bea59b4..9eb70ad 100644 --- a/src/main.js +++ b/src/main.js @@ -1,4 +1,6 @@ import { createApp } from 'vue' +import { createI18n } from 'vue-i18n' +import messages from '@intlify/unplugin-vue-i18n/messages' import App from './App.vue' import store from './store/index.js' @@ -16,8 +18,18 @@ const app = createApp(App) app.use(store) app.use(plugins) + app.use(icons) +const locale = window.electron?.process?.env?.LOCALE +// const locale = 'en_US' +// console.log('locale', locale) +const i18n = createI18n({ + locale, + messages, +}) +app.use(i18n) + app.config.globalProperties.$electron = window.electron app.config.globalProperties.$adb = window.adbkit app.config.globalProperties.$scrcpy = window.scrcpy diff --git a/vite.config.js b/vite.config.js index 6a5f418..5123ef6 100644 --- a/vite.config.js +++ b/vite.config.js @@ -8,6 +8,7 @@ import useVue from '@vitejs/plugin-vue' import useEslint from 'vite-plugin-eslint' import useUnoCSS from 'unocss/vite' import useSvg from 'vite-svg-loader' +import useI18n from '@intlify/unplugin-vue-i18n/vite' const merge = (config, { command = '' } = {}) => mergeConfig( @@ -37,6 +38,9 @@ export default params => useUnoCSS(), useSvg(), useVue(), + useI18n({ + include: [resolve(__dirname, './src/locales/**')], + }), useElectron([ { entry: 'electron/main.js',