diff --git a/src/i18n/index.js b/src/i18n/index.js new file mode 100644 index 000000000..626653705 --- /dev/null +++ b/src/i18n/index.js @@ -0,0 +1,27 @@ +import Vue from 'vue' +import VueI18n from 'vue-i18n' + +Vue.use(VueI18n) + +const languages = [ + {value: 'en-US', label: 'English'}, + {value: 'zh-CN', label: '简体中文'}, + {value: 'zh-TW', label: '繁體中文'} +] +const messages = {} + +// combine admin and oj +for (let lang of languages) { + let locale = lang.value + let m = require(`./oj/${locale}`).m + Object.assign(m, require(`./admin/${locale}`).m) + messages[locale] = {m: m} +} +console.log(messages) +// load language packages +export default new VueI18n({ + locale: 'en-US', + messages: messages +}) + +export {languages} diff --git a/src/pages/admin/index.js b/src/pages/admin/index.js index 7b7f80c40..5a868af88 100644 --- a/src/pages/admin/index.js +++ b/src/pages/admin/index.js @@ -2,6 +2,7 @@ import 'babel-polyfill' import Vue from 'vue' import App from './App.vue' import store from '@/store' +import i18n from '@/i18n' import Element from 'element-ui' import 'element-ui/lib/theme-chalk/index.css' import locale from 'element-ui/lib/locale/lang/en' @@ -17,8 +18,6 @@ import Save from './components/btn/Save.vue' import Cancel from './components/btn/Cancel.vue' import './style.less' -import VueI18n from 'vue-i18n' - // register global utility filters. Object.keys(filters).forEach(key => { Vue.filter(key, filters[key]) @@ -34,18 +33,6 @@ Vue.component(Panel.name, Panel) Vue.component(Save.name, Save) Vue.component(Cancel.name, Cancel) -Vue.use(VueI18n) - -// load language packages -const i18n = new VueI18n({ - locale: 'en-US', - messages: { - 'en-US': require('../../i18n/admin/en-US'), - 'zh-CN': require('../../i18n/admin/zh-CN'), - 'zh-TW': require('../../i18n/admin/zh-TW') - } -}) - Vue.use(Element, { i18n: (key, value) => i18n.t(key, value) }) diff --git a/src/pages/admin/views/Home.vue b/src/pages/admin/views/Home.vue index 4e5869ce9..4d126c75c 100644 --- a/src/pages/admin/views/Home.vue +++ b/src/pages/admin/views/Home.vue @@ -17,7 +17,6 @@ @@ -61,16 +60,6 @@ this.$router.push({name: 'login'}) }) } - }, - changeLocale () { - // 通过默认locale切换语言 - if (this.$i18n.locale === 'zh-CN') { - this.$i18n.locale = 'zh-TW' - } else if (this.$i18n.locale === 'zh-TW') { - this.$i18n.locale = 'en-US' - } else { - this.$i18n.locale = 'zh-CN' - } } }, computed: { diff --git a/src/pages/oj/App.vue b/src/pages/oj/App.vue index 563207124..f85d534f3 100644 --- a/src/pages/oj/App.vue +++ b/src/pages/oj/App.vue @@ -6,8 +6,7 @@