import en from './languages/en.json'
import zhCN from './languages/zh-CN.json'
import ru from './languages/ru.json'
import srLatn from './languages/sr-Latn.json'
import enLocale from 'element-ui/lib/locale/lang/en'
import zhLocale from 'element-ui/lib/locale/lang/zh-CN'
import srLocale from 'element-ui/lib/locale/lang/sr'
import ruLocale from 'element-ui/lib/locale/lang/ru-RU'
import VueI18n from 'vue-i18n'
import Vue from 'vue'

// 创建 i18n
Vue.use(VueI18n) // 新版本必须要这个，不知道为什么
function loadLanguage() {
  const languages = {
    en: {
      ...en,
      ...enLocale,
    },
    'zh-CN': {
      ...zhCN,
      ...zhLocale,
    },
    sr: {
      ...srLatn,
      ...srLocale,
    },
    'ru-RU': {
      ...ru,
      ...ruLocale,
    },
  }

  return languages
}

const i18n = new VueI18n({
  locale: localStorage.getItem('lang') || 'zh-CN', // 设置默认语言
  messages: loadLanguage(), // 设置语言包
})

export default i18n
