zzzz
2024-03-28 91f9b7a3b7dfc4fe6b9b5008cfec4e18dfb6dcd5
src/locales/index.js
@@ -1,16 +1,20 @@
import Vue from 'vue'
import VueI18n from 'vue-i18n'
import en from './en.js'
import india from '@/locales/india'
import tw from '@/locales/tw'
import Vue from "vue";
import VueI18n from "vue-i18n";
import en from "./en.js";
// import en from "./zh.js";
import india from "@/locales/india";
import tw from "@/locales/tw";
import ty from "@/locales/taiyu.js";
import ry from "@/locales/riyu.js";
import hy from "@/locales/hanyu.js";
Vue.use(VueI18n)
Vue.use(VueI18n);
const DEFAULT_LANG = 'zh-CN'
const LOCALE_KEY = 'language'
const DEFAULT_LANG = "zh-CN";
const LOCALE_KEY = "language";
const locales = {
  'zh-CN': {
  "zh-CN": {
    ...en
  },
  en: {
@@ -18,50 +22,59 @@
  },
  tw: {
    ...tw
  },
  ty: {
    ...ty
  },
  ry: {
    ...ry
  },
  hy: {
    ...hy
  }
}
};
// en-us  zh-cn
// let langLocale = getCookie(LOCALE_KEY) || 'en';
if (!window.localStorage.getItem(LOCALE_KEY)) {
  window.localStorage.setItem(LOCALE_KEY, DEFAULT_LANG)
  window.localStorage.setItem(LOCALE_KEY, DEFAULT_LANG);
}
let langLocale = window.localStorage.getItem(LOCALE_KEY)
  ? window.localStorage.getItem(LOCALE_KEY)
  : 'zh-CN'
  : "zh-CN";
const i18n = new VueI18n({
  locale: langLocale,
  messages: locales,
  silentTranslationWarn: true
})
const init = Vue.prototype._init
Vue.prototype._init = function (options) {
});
const init = Vue.prototype._init;
Vue.prototype._init = function(options) {
  init.call(this, {
    i18n,
    ...options
  })
}
  });
};
export const setup = lang => {
  if (lang === undefined) {
    // lang = window.localStorage.getItem(LOCALE_KEY);
    // const language = getCookie(LOCALE_KEY);
    const language = window.localStorage.getItem(LOCALE_KEY)
    const language = window.localStorage.getItem(LOCALE_KEY);
    if (language) {
      langLocale = language.replace('-', '_').toLowerCase()
      langLocale = language.replace("-", "_").toLowerCase();
    }
    if (undefined !== langLocale && langLocale !== '') {
      lang = langLocale
    if (undefined !== langLocale && langLocale !== "") {
      lang = langLocale;
    }
    if (locales[lang] === undefined) {
      lang = DEFAULT_LANG
      lang = DEFAULT_LANG;
    }
    // console.log(`lang-${lang}`);
  }
  Vue.config.lang = lang
  i18n.locale = lang
}
  Vue.config.lang = lang;
  i18n.locale = lang;
};
setup()
setup();
export default i18n
export default i18n;