import Vue from 'vue'
import VueI18n from 'vue-i18n'
import { getCookies } from '@/libs/util'
// 引入自定义的语言包
import customZhCn from './lang/zh-CN'
import customZhTw from './lang/zh-TW'
import customEnUs from './lang/en-US'
// 引入iview语言包
import zhCnLocale from 'iview/src/locale/lang/zh-CN'
import enUsLocale from 'iview/src/locale/lang/en-US'
import zhTwLocale from 'iview/src/locale/lang/zh-TW'

Vue.use(VueI18n)

// 页面初始化语言选择
// const navLang = navigator.language
// const localLang = (navLang === 'zh-CN' || navLang === 'en-US') ? navLang : false
let lang = getCookies('language') || 'zh_cn'

Vue.config.lang = lang

Vue.locale = () => {}

// 引进语言包
// vue-i18n 6.x+写法
const messages = {
  'zh_cn': Object.assign(zhCnLocale, customZhCn),
  'en': Object.assign(enUsLocale, customEnUs)
}
export const i18n = new VueI18n({
  locale: lang,
  messages
})

// 配置项目中要调用的语言包，用于界面选择语言中下拉选项调用
export const localList = {
  'zh_cn': '中文简体',
  'en': 'English'
}

// vue-i18n 5.x写法
// Vue.locale('zh-CN', Object.assign(zhCnLocale, customZhCn))
// Vue.locale('en-US', Object.assign(zhTwLocale, customZhTw))
// Vue.locale('zh-TW', Object.assign(enUsLocale, customEnUs))
