import Vue from 'vue'
import store from '@/store'
import VueI18n from 'vue-i18n'
import elEn from 'element-ui/lib/locale/lang/en'
import elZh from 'element-ui/lib/locale/lang/zh-CN'
import en from './en'
import zh from './zh'

Vue.use(VueI18n)

const messages = {
  en: {
    ...en,
    ...elEn,
  },
  'en-US': {
    ...en,
    ...elEn,
  },
  zh: {
    ...zh,
    ...elZh,
  },
  'zh-CN': {
    ...zh,
    ...elZh,
  },
}

function getLanguage() {
  return store.getters['settings/language'] || 'zh'
}

const i18n = new VueI18n({
  locale: getLanguage(),
  messages,
})

export default i18n
