diff --git a/frontend/package.json b/frontend/package.json index afbbafa4..3e8fc9a1 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -24,6 +24,7 @@ "path": "^0.12.7", "vue": "^2.5.22", "vue-codemirror-lite": "^1.0.4", + "vue-i18n": "^8.9.0", "vue-router": "^3.0.1", "vuex": "^3.0.1" }, diff --git a/frontend/src/components/InfoView/TaskInfoView.vue b/frontend/src/components/InfoView/TaskInfoView.vue index 6ffcec22..98ba7c8f 100644 --- a/frontend/src/components/InfoView/TaskInfoView.vue +++ b/frontend/src/components/InfoView/TaskInfoView.vue @@ -6,31 +6,31 @@ ref="nodeForm" class="node-form" label-position="right"> - + - - SUCCESS - STARTED - FAILURE - {{taskForm.status}} + + {{$t('SUCCESS')}} + {{$t('STARTED')}} + {{$t('FAILURE')}} + {{$t(taskForm.status)}} - + - + - + - + - +
{{taskForm.result}}
diff --git a/frontend/src/i18n/en.js b/frontend/src/i18n/en.js new file mode 100644 index 00000000..b1c6ea43 --- /dev/null +++ b/frontend/src/i18n/en.js @@ -0,0 +1 @@ +export default {} diff --git a/frontend/src/i18n/index.js b/frontend/src/i18n/index.js new file mode 100644 index 00000000..e5f6618e --- /dev/null +++ b/frontend/src/i18n/index.js @@ -0,0 +1,16 @@ +import Vue from 'vue' +import VueI18n from 'vue-i18n' +import en from './en' +import zh from './zh' + +Vue.use(VueI18n) + +const i18n = new VueI18n({ + locale: localStorage.getItem('lang') || 'en', + messages: { + en, + zh + } +}) + +export default i18n diff --git a/frontend/src/i18n/zh.js b/frontend/src/i18n/zh.js new file mode 100644 index 00000000..89eb2e99 --- /dev/null +++ b/frontend/src/i18n/zh.js @@ -0,0 +1,16 @@ +export default { + // 状态 + PENDING: '待定', + STARTED: '已开始', + SUCCESS: '成功', + FAILURE: '错误', + + // 任务 + 'Task ID': '任务ID', + 'Status': '状态', + 'Log File Path': '日志文件路径', + 'Create Timestamp': '创建时间', + 'Finish Timestamp': '完成时间', + 'Duration (sec)': '用时(秒)', + 'Error Message': '错误信息' +} diff --git a/frontend/src/main.js b/frontend/src/main.js index 93076c64..d90e7bcf 100644 --- a/frontend/src/main.js +++ b/frontend/src/main.js @@ -20,6 +20,7 @@ import '@/icons' // icon import '@/permission' // permission control import request from './api/request' +import i18n from './i18n' Vue.use(ElementUI, { locale }) @@ -29,6 +30,7 @@ Vue.prototype.$request = request const app = new Vue({ el: '#app', + i18n, router, store, render: h => h(App) diff --git a/frontend/src/store/index.js b/frontend/src/store/index.js index cb73ec4a..25c179ba 100644 --- a/frontend/src/store/index.js +++ b/frontend/src/store/index.js @@ -9,6 +9,7 @@ import spider from './modules/spider' import deploy from './modules/deploy' import task from './modules/task' import file from './modules/file' +import lang from './modules/lang' import getters from './getters' Vue.use(Vuex) @@ -23,7 +24,8 @@ const store = new Vuex.Store({ spider, deploy, task, - file + file, + lang }, getters }) diff --git a/frontend/src/store/modules/lang.js b/frontend/src/store/modules/lang.js new file mode 100644 index 00000000..b1e57a04 --- /dev/null +++ b/frontend/src/store/modules/lang.js @@ -0,0 +1,31 @@ +const state = { + lang: window.localStorage.getItem('lang') || 'en' +} + +const getters = { + lang (state) { + if (state.lang === 'en') { + return 'English' + } else if (state.lang === 'zh') { + return '中文' + } else { + return state.lang + } + } +} + +const mutations = { + SET_LANG (state, value) { + state.lang = value + } +} + +const actions = {} + +export default { + namespaced: true, + state, + getters, + mutations, + actions +} diff --git a/frontend/src/views/layout/components/Navbar.vue b/frontend/src/views/layout/components/Navbar.vue index e11b6b1f..6ed77a90 100644 --- a/frontend/src/views/layout/components/Navbar.vue +++ b/frontend/src/views/layout/components/Navbar.vue @@ -1,24 +1,32 @@ @@ -44,6 +52,11 @@ export default { }, logout () { this.$router.push('/login') + }, + setLang (lang) { + window.localStorage.setItem('lang', lang) + this.$i18n.locale = lang + this.$store.commit('lang/SET_LANG', lang) } } } @@ -62,6 +75,15 @@ export default { padding: 0 10px; } + .lang-list { + cursor: pointer; + display: inline-block; + float: right; + margin-right: 35px; + /*position: absolute;*/ + /*right: 80px;*/ + } + .screenfull { position: absolute; right: 90px; @@ -70,30 +92,13 @@ export default { } .avatar-container { + cursor: pointer; height: 50px; display: inline-block; - position: absolute; - right: 35px; - - .avatar-wrapper { - cursor: pointer; - margin-top: 5px; - position: relative; - line-height: initial; - - .user-avatar { - width: 40px; - height: 40px; - border-radius: 10px; - } - - .el-icon-caret-bottom { - position: absolute; - right: -20px; - top: 25px; - font-size: 12px; - } - } + float: right; + margin-right: 35px; + /*position: absolute;*/ + /*right: 35px;*/ } } diff --git a/frontend/yarn.lock b/frontend/yarn.lock index 19bfda0c..159ea9c1 100644 --- a/frontend/yarn.lock +++ b/frontend/yarn.lock @@ -8433,6 +8433,11 @@ vue-hot-reload-api@^2.3.0: version "2.3.2" resolved "http://registry.npm.taobao.org/vue-hot-reload-api/download/vue-hot-reload-api-2.3.2.tgz#1fcc1495effe08a790909b46bf7b5c4cfeb6f21b" +vue-i18n@^8.9.0: + version "8.9.0" + resolved "http://registry.npm.taobao.org/vue-i18n/download/vue-i18n-8.9.0.tgz#5f084001fe5b4c7ad8c00ee5f11396a88ff2e55b" + integrity sha1-XwhAAf5bTHrYwA7l8ROWqI/y5Vs= + vue-jest@^3.0.2: version "3.0.3" resolved "http://registry.npm.taobao.org/vue-jest/download/vue-jest-3.0.3.tgz#80f664712f2678b1d8bb3af0f2c0bef5efa8de31"