import Vue from 'vue'
import VueI18n from 'vue-i18n'
import {Language} from "@/module/menu";

// @ts-ignore
import ElLocal from 'element-ui/lib/locale'
// @ts-ignore
import enLocale from 'element-ui/lib/locale/lang/en'
// @ts-ignore
import zhLocale from 'element-ui/lib/locale/lang/zh-CN'

const langZH = require('./lang/zh.json')
const langEn = require('./lang/en.json')
Vue.use(VueI18n)
const i18n = new VueI18n({
  locale: 'zh',
  messages: {
    en: {
      message: {
        ...langEn
      },
      ...enLocale
    },
    zh: {
      message: {
        ...langZH
      },
      ...zhLocale
    }
  }
})
ElLocal.i18n((key: any, value: any) => i18n.t(key, value))
const nowL = window.localStorage.getItem('language')
if (nowL) {
  i18n.locale = nowL
} else {
  window.localStorage.setItem('language', Language.zh)
}

export default i18n
