/* eslint-disable filenames/match-exported */
import Vue from 'vue'
import VueI18n from 'vue-i18n'
Vue.use(VueI18n)

// 获取浏览器设置的语言
const locale = navigator.language.replace('-', '_')
const i18n = new VueI18n({
  locale,
  fallbackLocale: 'zh_CN',
})

// 加载语言包
import(/* webpackChunkName: "lang" */ `./lang/${locale}.js`).then((module) => {
  i18n.setLocaleMessage(locale, module.default)
})

// 加载Ant Design语言包
const loadAntdLocale = () => {
  return import(
    /* webpackChunkName: "antd-lang" */ `ant-design-vue/es/locale-provider/${locale}.js`
  ).then((module) => module.default)
}

export { loadAntdLocale }
export default i18n
