i18n.js 682 Bytes
import Vue from 'vue'
import locale from 'element-ui/lib/locale'
import VueI18n from 'vue-i18n'

Vue.use(VueI18n)

const i18n = new VueI18n({
    
})

var lang = ['zh_CN','en_US','zh_TW','mall_CN']
function loadI18nMessages(lang) {
    return import(/* webpackChunkName: "[request]" */`./langs/${lang}`).then(msg => {
        i18n.setLocaleMessage(lang, msg.default)
        i18n.locale = localStorage.getItem('lang') || 'mall_CN'
        return Promise.resolve()
    })
}


lang.forEach((item,index)=>{
    loadI18nMessages(item).then(() => {
        if(item=='mall_CN'){
            locale.i18n((key, value) => i18n.t(key, value))
        }
        
    })
})
export default i18n