import Vue from 'vue'
import VueI18n from 'vue-i18n'

import enLocale from 'element-ui/lib/locale/lang/en'
import zhLocale from 'element-ui/lib/locale/lang/zh-CN'
import zhCN_vxe from 'vxe-table/lib/locale/lang/zh-CN'
import enUS_vxe from 'vxe-table/lib/locale/lang/en-US'
import VXETable from 'vxe-table'
import ElementLocale from 'element-ui/lib/locale'
import settingConfig from "@/settings";

import enLogin from "./locale/en/login.js"
import zhLogin from "./locale/zh/login.js"

Vue.use(VueI18n);

const messages = {
  en: {
    ...enLocale,
    ...enUS_vxe,
    ...enLogin
  },
  zh: {
    ...zhLocale,
    ...zhCN_vxe,
    ...zhLogin
  }
};

/*const enLocaleMine = require.context('@/lang/locale/en', false, /\w+\.js/);
const zhLocaleMine = require.context('@/lang/locale/zh', false, /\w+\.js/);

zhLocaleMine.keys().map(fileName => {
  let comp = zhLocaleMine(fileName).default;
  Object.assign(messages["zh"], comp);
});
enLocaleMine.keys().map(fileName => {
  let comp = enLocaleMine(fileName).default;
  Object.assign(messages["en"], comp);
});*/

// Create VueI18n instance with options
let i18nLang = localStorage.getItem("i18n-lang");
const i18n = new VueI18n({
  locale: i18nLang || settingConfig.languageCode || 'zh', // set locale
  messages, // set locale messages
});

ElementLocale.i18n((key, value) => i18n.t(key, value));

VXETable.setup({
  // 对组件内置的提示语进行国际化翻译
  i18n: (key, args) => i18n.t(key, args)
});

export default i18n;
