From 9041b45660ddf56ed08ea433f75f344d07ae919a Mon Sep 17 00:00:00 2001 From: FairyEver <1711467488@qq.com> Date: Wed, 25 Sep 2019 15:51:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9A=E5=9B=BD=E8=AF=AD=E5=85=B3=E8=81=94?= =?UTF-8?q?=20element?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: 1618359119a731c527e611332d701a5914f5bb9f [formerly 9feccc1938ba071e992d6404c3006d10450a9832] [formerly 1618359119a731c527e611332d701a5914f5bb9f [formerly 9feccc1938ba071e992d6404c3006d10450a9832] [formerly 1618359119a731c527e611332d701a5914f5bb9f [formerly 9feccc1938ba071e992d6404c3006d10450a9832] [formerly 9feccc1938ba071e992d6404c3006d10450a9832 [formerly e3dc55c030d03beb36dd343c4871b1d84fd95872 [formerly 483f092cdca9e292945a8229077e36a0d3e41a3f]]]]] Former-commit-id: 743f99605b2d86ff42b9410d497dc7be08099db9 Former-commit-id: 0462f3977091d82973ad54e7364e680d96f3f083 Former-commit-id: fea191928cf858337b45f51a09e815d241954728 [formerly 9a3a49e14e57a522ab96f81d15ac36fec5aa117f] Former-commit-id: d7e12ab2a74e9e73fba2f8c119a8490ad8f6d0e6 Former-commit-id: 7376ec28b4d66367efc49efa6632be9914d8cc67 Former-commit-id: e14c86ae03d8a1cf6c1213343c4789d587c8a51f Former-commit-id: 3845f9903e2faa3b1179556754e5a41a16e84e18 Former-commit-id: 0ba0b7d8746895b07604fa5ba35301fcffc00bc3 --- d2-admin.babel | 25 +++++++++++++++++++++++++ src/i18n.js | 14 ++++++++++---- src/locales/en.json | 1 + src/locales/ja.json | 1 + src/locales/zh-chs.json | 1 + src/locales/zh-cht.json | 1 + src/plugin/d2admin/index.js | 6 +++++- 7 files changed, 44 insertions(+), 5 deletions(-) diff --git a/d2-admin.babel b/d2-admin.babel index 0da7e2b77..41a40a4c9 100644 --- a/d2-admin.babel +++ b/d2-admin.babel @@ -15,6 +15,31 @@ + + _element + false + + + + + + en-US + false + + + ja-JP + false + + + zh-CHS + false + + + zh-CHT + false + + + _name false diff --git a/src/i18n.js b/src/i18n.js index d80c7edba..b00702011 100644 --- a/src/i18n.js +++ b/src/i18n.js @@ -7,13 +7,17 @@ Vue.use(VueI18n) function loadLocaleMessages () { const locales = require.context('./locales', true, /[A-Za-z0-9-_,\s]+\.json$/i) const messages = {} - locales.keys().forEach(key => { + for (const key of locales.keys()) { const matched = key.match(/([A-Za-z0-9-_]+)\./i) if (matched && matched.length > 1) { const locale = matched[1] - messages[locale] = locales(key) + const localeElementUI = require(`element-ui/lib/locale/lang/${locales(key)._element}`) + messages[locale] = { + ...locales(key), + ...localeElementUI ? localeElementUI.default : {} + } } - }) + } return messages } @@ -24,8 +28,10 @@ Vue.prototype.$languages = Object.keys(messages).map(langlage => ({ value: langlage })) -export default new VueI18n({ +const i18n = new VueI18n({ locale: util.cookies.get('lang') || process.env.VUE_APP_I18N_LOCALE, fallbackLocale: process.env.VUE_APP_I18N_FALLBACK_LOCALE, messages }) + +export default i18n diff --git a/src/locales/en.json b/src/locales/en.json index cbcf023ef..de5e8f3fb 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -1,4 +1,5 @@ { + "_element": "en", "_name": "English", "page": { "demo": { diff --git a/src/locales/ja.json b/src/locales/ja.json index 656b32358..d11fcd75b 100644 --- a/src/locales/ja.json +++ b/src/locales/ja.json @@ -1,4 +1,5 @@ { + "_element": "ja", "_name": "日本語", "page": { "demo": { diff --git a/src/locales/zh-chs.json b/src/locales/zh-chs.json index 06dad757e..8fc31fe0f 100644 --- a/src/locales/zh-chs.json +++ b/src/locales/zh-chs.json @@ -1,4 +1,5 @@ { + "_element": "zh-CN", "_name": "简体中文", "page": { "demo": { diff --git a/src/locales/zh-cht.json b/src/locales/zh-cht.json index ac5c89119..ee51ba7f9 100644 --- a/src/locales/zh-cht.json +++ b/src/locales/zh-cht.json @@ -1,4 +1,5 @@ { + "_element": "zh-TW", "_name": "繁體中文", "page": { "demo": { diff --git a/src/plugin/d2admin/index.js b/src/plugin/d2admin/index.js index 24b46cad3..7c739e91a 100644 --- a/src/plugin/d2admin/index.js +++ b/src/plugin/d2admin/index.js @@ -7,6 +7,8 @@ import 'flex.css' import '@/components' // svg 图标 import '@/assets/svg-icons' +// 国际化 +import i18n from '@/i18n.js' // 功能插件 import pluginError from '@/plugin/error' @@ -27,7 +29,9 @@ export default { // 构建时间 Vue.prototype.$buildTime = process.env.VUE_APP_BUILD_TIME // Element - Vue.use(ElementUI) + Vue.use(ElementUI, { + i18n: (key, value) => i18n.t(key, value) + }) // 插件 Vue.use(pluginError) Vue.use(pluginLog)