From a476d34da2dba1e297212b5cd99138b7439b7c47 Mon Sep 17 00:00:00 2001 From: PleasePerfunctory <47876885+PleasePerfunctory@users.noreply.github.com> Date: Mon, 7 Nov 2022 18:53:57 +0800 Subject: [PATCH] New language switching function on the front page (#921) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Added Internationalization(vue-i18n) * feat: Adding an Internationalization Instance Co-authored-by: 冯建军 --- hippo4j-server/hippo4j-ui/package.json | 3 +- .../src/layout/components/Navbar.vue | 10 +-- .../hippo4j-ui/src/locale/config.js | 30 +++++++++ hippo4j-server/hippo4j-ui/src/locale/index.js | 10 +++ .../hippo4j-ui/src/locale/lang/en.js | 31 ++++++++++ .../hippo4j-ui/src/locale/lang/zh.js | 28 +++++++++ .../hippo4j-ui/src/locale/langChange.vue | 62 +++++++++++++++++++ hippo4j-server/hippo4j-ui/src/main.js | 3 + .../src/views/hippo4j/threadpool/index.vue | 22 +++---- .../hippo4j-ui/src/views/login/index.vue | 6 +- hippo4j-server/hippo4j-ui/vue.config.js | 2 +- 11 files changed, 187 insertions(+), 20 deletions(-) create mode 100644 hippo4j-server/hippo4j-ui/src/locale/config.js create mode 100644 hippo4j-server/hippo4j-ui/src/locale/index.js create mode 100644 hippo4j-server/hippo4j-ui/src/locale/lang/en.js create mode 100644 hippo4j-server/hippo4j-ui/src/locale/lang/zh.js create mode 100644 hippo4j-server/hippo4j-ui/src/locale/langChange.vue diff --git a/hippo4j-server/hippo4j-ui/package.json b/hippo4j-server/hippo4j-ui/package.json index bbe30325..9adc89b8 100755 --- a/hippo4j-server/hippo4j-ui/package.json +++ b/hippo4j-server/hippo4j-ui/package.json @@ -59,6 +59,7 @@ "vue": "2.6.10", "vue-cookie": "^1.1.4", "vue-count-to": "1.0.13", + "vue-i18n": "^6.1.3", "vue-router": "3.0.2", "vue-splitpane": "1.0.4", "vue2-jsoneditor": "^1.0.6", @@ -68,7 +69,7 @@ "devDependencies": { "@babel/core": "7.0.0", "@babel/register": "7.0.0", - "@vue/cli-plugin-babel": "3.5.3", + "@vue/cli-plugin-babel": "~4", "@vue/cli-plugin-eslint": "3.5.1", "@vue/cli-plugin-unit-jest": "3.5.3", "@vue/cli-service": "3.5.3", diff --git a/hippo4j-server/hippo4j-ui/src/layout/components/Navbar.vue b/hippo4j-server/hippo4j-ui/src/layout/components/Navbar.vue index 612126a8..283431ff 100755 --- a/hippo4j-server/hippo4j-ui/src/layout/components/Navbar.vue +++ b/hippo4j-server/hippo4j-ui/src/layout/components/Navbar.vue @@ -18,7 +18,7 @@ - +
@@ -32,7 +32,7 @@ Dashboard - Log Out + {{ $t('system.logOut') }} @@ -45,12 +45,14 @@ import Breadcrumb from '@/components/Breadcrumb' import Hamburger from '@/components/Hamburger' import ErrorLog from '@/components/ErrorLog' + import langChange from '@/locale/langChange' export default { components: { Breadcrumb, Hamburger, - ErrorLog + ErrorLog, + langChange }, computed: { ...mapGetters([ @@ -106,7 +108,7 @@ float: right; height: 100%; line-height: 50px; - + display: flex; &:focus { outline: none; } diff --git a/hippo4j-server/hippo4j-ui/src/locale/config.js b/hippo4j-server/hippo4j-ui/src/locale/config.js new file mode 100644 index 00000000..3262ac6d --- /dev/null +++ b/hippo4j-server/hippo4j-ui/src/locale/config.js @@ -0,0 +1,30 @@ +// 导入elementUi默认中英文语言包 +import elZh from 'element-ui/lib/locale/lang/zh-CN' +import elEn from 'element-ui/lib/locale/lang/en' + +import zh from './lang/zh' +import en from './lang/en' + +const lang = localStorage.getItem('locale_lang') + +export const i18nConfig = { + locale: lang || 'en', // 默认语种 + messages: { + zh: { ...zh, ...elZh }, // 中文包 + en: { ...en, ...elEn } // 英文包 + } +} + + +export const langSelectList = () => { + return [ + { + lang: 'zh', + name: '中文' + }, + { + lang: 'en', + name: 'English' + } + ] +} diff --git a/hippo4j-server/hippo4j-ui/src/locale/index.js b/hippo4j-server/hippo4j-ui/src/locale/index.js new file mode 100644 index 00000000..408134bc --- /dev/null +++ b/hippo4j-server/hippo4j-ui/src/locale/index.js @@ -0,0 +1,10 @@ +import Vue from 'vue' +import VueI18n from 'vue-i18n' + +import { i18nConfig } from './config' + +Vue.use(VueI18n) + +const i18n = new VueI18n(i18nConfig) + +export default i18n diff --git a/hippo4j-server/hippo4j-ui/src/locale/lang/en.js b/hippo4j-server/hippo4j-ui/src/locale/lang/en.js new file mode 100644 index 00000000..f581c3bb --- /dev/null +++ b/hippo4j-server/hippo4j-ui/src/locale/lang/en.js @@ -0,0 +1,31 @@ +export default { + // 系统 + system: { + login: 'Login Form', + username: 'Username', + password: 'Password', + logOut: 'Log Out' + }, + + // 公共 + common: { + search: 'Search', + addition: 'Addition', + serialNumber: 'Serial Number', + operation: 'Operation', + edit: 'Edit', + delete: 'Delete', + cancel: 'Cancel', + confirm: 'Confirm' + }, + + // 线程池 + threadPool: { + tenant: 'Tenant', + project: 'Project', + threadPool: 'Thread Pool', + + + } + +} diff --git a/hippo4j-server/hippo4j-ui/src/locale/lang/zh.js b/hippo4j-server/hippo4j-ui/src/locale/lang/zh.js new file mode 100644 index 00000000..f12d91c6 --- /dev/null +++ b/hippo4j-server/hippo4j-ui/src/locale/lang/zh.js @@ -0,0 +1,28 @@ +export default { + // 系统 + system: { + login: '登 陆', + username: '用户名', + password: '密码', + logOut: '注销' + }, + + // 公共 + common: { + search: '搜索', + addition: '添加', + serialNumber: '序号', + operation: '操作', + edit: '编辑', + delete: '删除', + cancel: '取消', + confirm: '确认' + }, + + // 线程池 + threadPool: { + tenant: '租户', + project: '项目', + threadPool: '线程池', + } +} diff --git a/hippo4j-server/hippo4j-ui/src/locale/langChange.vue b/hippo4j-server/hippo4j-ui/src/locale/langChange.vue new file mode 100644 index 00000000..c14dbe3c --- /dev/null +++ b/hippo4j-server/hippo4j-ui/src/locale/langChange.vue @@ -0,0 +1,62 @@ + + + diff --git a/hippo4j-server/hippo4j-ui/src/main.js b/hippo4j-server/hippo4j-ui/src/main.js index 28d415d5..44f539b8 100755 --- a/hippo4j-server/hippo4j-ui/src/main.js +++ b/hippo4j-server/hippo4j-ui/src/main.js @@ -17,6 +17,7 @@ import './icons'; // icon import './permission'; // permission control // import './utils/error-log' // error log +import i18n from '@/locale' import * as filters from './filters'; // global filters import echarts from 'echarts'; Vue.prototype.$echarts = echarts; @@ -25,6 +26,7 @@ Vue.prototype.$cookie = cookie; Vue.use(Element, { size: Cookies.get('size') || 'medium', // set element-ui default size + i18n: (key, value) => i18n.t(key, value) }); // register global utility filters @@ -38,5 +40,6 @@ new Vue({ el: '#app', router, store, + i18n, render: (h) => h(App), }); diff --git a/hippo4j-server/hippo4j-ui/src/views/hippo4j/threadpool/index.vue b/hippo4j-server/hippo4j-ui/src/views/hippo4j/threadpool/index.vue index 267cc30a..f6505f24 100755 --- a/hippo4j-server/hippo4j-ui/src/views/hippo4j/threadpool/index.vue +++ b/hippo4j-server/hippo4j-ui/src/views/hippo4j/threadpool/index.vue @@ -3,7 +3,7 @@
- 搜索 + {{ $t('common.search') }} - 添加 + {{ $t('common.addition') }}
- + @@ -129,16 +129,16 @@ @@ -327,9 +327,9 @@ diff --git a/hippo4j-server/hippo4j-ui/src/views/login/index.vue b/hippo4j-server/hippo4j-ui/src/views/login/index.vue index 19fa52d5..7710cf18 100755 --- a/hippo4j-server/hippo4j-ui/src/views/login/index.vue +++ b/hippo4j-server/hippo4j-ui/src/views/login/index.vue @@ -9,7 +9,7 @@ label-position="left" >
-

Login Form

+

{{ $t('system.login') }}

@@ -19,7 +19,7 @@