mirror of
https://github.com/bs-community/blessing-skin-server.git
synced 2025-01-30 14:09:58 +08:00
Load i18n from element-ui
This commit is contained in:
parent
005f801c0d
commit
fd01a352a4
@ -1,4 +1,5 @@
|
||||
import Vue from 'vue'
|
||||
import loadI18n from './scripts/i18n-text'
|
||||
import './scripts'
|
||||
import * as emitter from './scripts/event'
|
||||
import routes from './scripts/route'
|
||||
@ -7,22 +8,6 @@ Vue.config.productionTip = false
|
||||
|
||||
loadI18n().then(loadModules)
|
||||
|
||||
async function loadI18n() {
|
||||
const langs = [
|
||||
{ lang: 'en', load: () => import('../../lang/en/front-end.yml') },
|
||||
{ lang: 'zh_CN', load: () => import('../../lang/zh_CN/front-end.yml') },
|
||||
]
|
||||
const texts = await langs.find(({ lang }) => lang === blessing.locale)
|
||||
if (texts) {
|
||||
blessing.i18n = Object.assign(blessing.i18n || Object.create(null), await texts.load())
|
||||
} else {
|
||||
blessing.i18n = Object.assign(
|
||||
blessing.i18n || Object.create(null),
|
||||
(await langs.find(({ lang }) => lang === blessing.fallback_locale)).load()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
function loadModules() {
|
||||
const route = routes.find(
|
||||
// eslint-disable-next-line no-shadow
|
||||
|
31
resources/assets/src/scripts/i18n-text.js
Normal file
31
resources/assets/src/scripts/i18n-text.js
Normal file
@ -0,0 +1,31 @@
|
||||
import elementLocale from 'element-ui/lib/locale'
|
||||
|
||||
const langs = {
|
||||
en: {
|
||||
bs: () => import('../../../lang/en/front-end.yml'),
|
||||
element: () => import('element-ui/lib/locale/lang/en'),
|
||||
},
|
||||
zh_CN: {
|
||||
bs: () => import('../../../lang/zh_CN/front-end.yml'),
|
||||
element: () => import('element-ui/lib/locale/lang/zh-CN'),
|
||||
},
|
||||
}
|
||||
|
||||
async function load(language) {
|
||||
const { bs: loadBS, element: loadElement } = langs[language]
|
||||
await Promise.all([
|
||||
(async () => {
|
||||
const text = await loadBS()
|
||||
blessing.i18n = Object.assign(blessing.i18n || Object.create(null), text)
|
||||
})(),
|
||||
(async () => {
|
||||
elementLocale.use((await loadElement()).default)
|
||||
})(),
|
||||
])
|
||||
}
|
||||
|
||||
export default function () {
|
||||
return blessing.locale in langs
|
||||
? load(blessing.locale)
|
||||
: load(blessing.fallback_locale)
|
||||
}
|
Loading…
Reference in New Issue
Block a user