import { createI18n } from 'vue-i18n';
import cn from './cn';
import en from './en';
// 判断语言--本地优先--第一次打开根据浏览器语言判断
const getLanguage = () => {
  try {
    let lan = localStorage.getItem('lang');
    let curLang = '';
    if (navigator.language === 'zh-CN' || navigator.language === 'zh-TW') {
      curLang = 'cn';
    } else if (navigator.language == 'en') {
      curLang = 'en';
    } else if (lan) {
      curLang = lan;
    } else {
      curLang = 'en';
    }
    return curLang;
  } catch (e) {
    return 'cn';
  }
};
const i18n = createI18n({
  legacy: false,
  locale: getLanguage(),
  messages: {
    cn,
    en,
  },
});
export default i18n;
