import Vue from 'vue'
import VueI18n from './vue-i18n/vue-i18n.common'
import {getLocale} from '@/utils/db'
Vue.use(VueI18n)

const i18n = new VueI18n({
    locale: getLocale() || 'zh_CN',
    formatFallbackMessages: true,
    messages: {
        'en_US': require('./languages/en_US.json'),
        'zh_CN': require('./languages/zh_CN.json')
    }
})
console.log({i18n})
Vue.prototype.$l = (object, field) => {
    let prefix = i18n.locale.split('_')[0]
    let append = prefix.charAt(0).toUpperCase() + prefix.toLowerCase().substr(1)
    // 如果object是null则返回字段名
    if(!object) return field + append

    return object[field + append] || object[field]
}
/* Vue.filter('$t', Vue.$i18n)
 */
// 重新console.warn来捕获未翻译的内容
/* console.wareOrig = console.warn
console.warn = (...data) => {
    console.log('warn', typeof data)
    console.wareOrig(data)
} */
export default i18n