DESKTOP-CVS3R96\我恁爹
2022-11-15 d8f6c671a613b841566c8d7b1f36eb2bb9640ea9
src/locales/index.js
@@ -1,49 +1,39 @@
import Vue from 'vue';
import VueI18n from 'vue-i18n';
import chinese from './zh-CN.js';
import english from './en.js';
import chinesechar from './tw.js';
import Vue from "vue";
import VueI18n from "vue-i18n";
import zh from "./zh.js";
import en from "./en.js";
Vue.use(VueI18n);
function getCookie(name) {
    // 获取cookie
    var arr;
    var reg = new RegExp(`(^| )${name}=([^;]*)(;|$)`);
    if (arr = document.cookie.match(reg)) {
      return unescape(arr[2]);
    }
    return null;
}
const DEFAULT_LANG = 'en-us';
const LOCALE_KEY = 'language';
const DEFAULT_LANG = "zh";
const LOCALE_KEY = "language";
const locales = {
  zh_cn: {
    ...chinese,
  zh: {
    ...zh
  },
  en: {
    ...english,
  },
  tw: {
    ...chinesechar,
  },
    ...en
  }
};
// en-us  zh-cn
//let langLocale = getCookie(LOCALE_KEY) || 'en';
let langLocale = window.localStorage.getItem(LOCALE_KEY) || 'en';
if (!window.localStorage.getItem(LOCALE_KEY)) {
  window.localStorage.setItem(LOCALE_KEY, DEFAULT_LANG);
}
let langLocale = window.localStorage.getItem(LOCALE_KEY)
  ? window.localStorage.getItem(LOCALE_KEY)
  : "zh";
const i18n = new VueI18n({
  locale: langLocale,
  messages: locales,
  silentTranslationWarn: true
});
const init = Vue.prototype._init;
Vue.prototype._init = function (options) {
Vue.prototype._init = function(options) {
  init.call(this, {
    i18n,
    ...options,
    ...options
  });
};
@@ -53,9 +43,9 @@
    //const language = getCookie(LOCALE_KEY);
    const language = window.localStorage.getItem(LOCALE_KEY);
    if (language) {
      langLocale = language.replace('-', '_').toLowerCase();
      langLocale = language.replace("-", "_").toLowerCase();
    }
    if (undefined !== langLocale && langLocale !== '') {
    if (undefined !== langLocale && langLocale !== "") {
      lang = langLocale;
    }
    if (locales[lang] === undefined) {
@@ -64,12 +54,10 @@
    // console.log(`lang-${lang}`);
  }
  Vue.config.lang = lang;
  i18n.locale = lang;
};
setup();
export default i18n;