Skip to content

Commit

Permalink
多国语关联 element
Browse files Browse the repository at this point in the history
Former-commit-id: 1618359119a731c527e611332d701a5914f5bb9f [formerly 9feccc1938ba071e992d6404c3006d10450a9832] [formerly 1618359119a731c527e611332d701a5914f5bb9f [formerly 9feccc1938ba071e992d6404c3006d10450a9832] [formerly 1618359119a731c527e611332d701a5914f5bb9f [formerly 9feccc1938ba071e992d6404c3006d10450a9832] [formerly 9feccc1938ba071e992d6404c3006d10450a9832 [formerly e3dc55c [formerly 483f092cdca9e292945a8229077e36a0d3e41a3f]]]]]
Former-commit-id: 743f996
Former-commit-id: 0462f39
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
  • Loading branch information
FairyEver committed Sep 25, 2019
1 parent 6f42642 commit 9041b45
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 5 deletions.
25 changes: 25 additions & 0 deletions d2-admin.babel
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,31 @@
<folder_node>
<name></name>
<children>
<concept_node>
<name>_element</name>
<definition_loaded>false</definition_loaded>
<description></description>
<comment></comment>
<default_text></default_text>
<translations>
<translation>
<language>en-US</language>
<approved>false</approved>
</translation>
<translation>
<language>ja-JP</language>
<approved>false</approved>
</translation>
<translation>
<language>zh-CHS</language>
<approved>false</approved>
</translation>
<translation>
<language>zh-CHT</language>
<approved>false</approved>
</translation>
</translations>
</concept_node>
<concept_node>
<name>_name</name>
<definition_loaded>false</definition_loaded>
Expand Down
14 changes: 10 additions & 4 deletions src/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
1 change: 1 addition & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"_element": "en",
"_name": "English",
"page": {
"demo": {
Expand Down
1 change: 1 addition & 0 deletions src/locales/ja.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"_element": "ja",
"_name": "日本語",
"page": {
"demo": {
Expand Down
1 change: 1 addition & 0 deletions src/locales/zh-chs.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"_element": "zh-CN",
"_name": "简体中文",
"page": {
"demo": {
Expand Down
1 change: 1 addition & 0 deletions src/locales/zh-cht.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"_element": "zh-TW",
"_name": "繁體中文",
"page": {
"demo": {
Expand Down
6 changes: 5 additions & 1 deletion src/plugin/d2admin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import 'flex.css'
import '@/components'
// svg 图标
import '@/assets/svg-icons'
// 国际化
import i18n from '@/i18n.js'

// 功能插件
import pluginError from '@/plugin/error'
Expand All @@ -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)
Expand Down

0 comments on commit 9041b45

Please sign in to comment.