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
38 lines
1004 B
JavaScript
38 lines
1004 B
JavaScript
import Vue from 'vue'
|
|
import VueI18n from 'vue-i18n'
|
|
import util from '@/libs/util'
|
|
|
|
Vue.use(VueI18n)
|
|
|
|
function loadLocaleMessages () {
|
|
const locales = require.context('./locales', true, /[A-Za-z0-9-_,\s]+\.json$/i)
|
|
const messages = {}
|
|
for (const key of locales.keys()) {
|
|
const matched = key.match(/([A-Za-z0-9-_]+)\./i)
|
|
if (matched && matched.length > 1) {
|
|
const locale = matched[1]
|
|
const localeElementUI = require(`element-ui/lib/locale/lang/${locales(key)._element}`)
|
|
messages[locale] = {
|
|
...locales(key),
|
|
...localeElementUI ? localeElementUI.default : {}
|
|
}
|
|
}
|
|
}
|
|
return messages
|
|
}
|
|
|
|
const messages = loadLocaleMessages()
|
|
|
|
Vue.prototype.$languages = Object.keys(messages).map(langlage => ({
|
|
label: messages[langlage]._name,
|
|
value: langlage
|
|
}))
|
|
|
|
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
|