import Vue from 'vue'
import VueI18n from 'vue-i18n'
import zh from './_zh'
import en from './_en'
import config from '@/config'
import browser from '@/utils/browser'

Vue.use(VueI18n)

let lang = browser.urlQueryValue('lang')
if (!lang) {
    lang = window.navigator.language || window.navigator.userLanguage || null
    if (lang && !/^zh/.test(lang)) {
        console.log('自动获取浏览器语言:' + lang)
        lang = 'en'
    }else{
        lang = 'zh'
    }
}

const i18n = new VueI18n({
    locale: lang,
    messages: {
        zh,
        en
    },
    fallbackLocale: 'zh'
})

config.lang = lang

export {i18n}