XiGuaSSR
2022-11-14 b18fc26a095ca2855d71b59975dab70d72501451
新增国际化
4 files modified
4 files added
17664 ■■■■■ changed files
package-lock.json 17570 ●●●●● patch | view | raw | blame | history
package.json 1 ●●●● patch | view | raw | blame | history
src/locales/en.js 5 ●●●●● patch | view | raw | blame | history
src/locales/index.js 75 ●●●●● patch | view | raw | blame | history
src/locales/tw.js 4 ●●●● patch | view | raw | blame | history
src/locales/zh-CN.js 4 ●●●● patch | view | raw | blame | history
src/main.js 4 ●●●● patch | view | raw | blame | history
src/page/newUser/index.vue 1 ●●●● patch | view | raw | blame | history
package-lock.json
Diff too large
package.json
@@ -14,6 +14,7 @@
    "animate.css": "^3.7.2",
    "axios": "^0.19.0",
    "bootstrap": "^4.4.1",
    "vue-i18n": "^8.14.1",
    "chokidar": "^3.3.0",
    "clipboard": "^2.0.4",
    "echarts": "^4.5.0",
src/locales/en.js
New file
@@ -0,0 +1,5 @@
/* eslint-disable */
export default {
    "MingCheng": "Name",
  }
src/locales/index.js
New file
@@ -0,0 +1,75 @@
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';
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 locales = {
  zh_cn: {
    ...chinese,
  },
  en: {
    ...english,
  },
  tw: {
    ...chinesechar,
  },
};
// en-us  zh-cn
//let langLocale = getCookie(LOCALE_KEY) || 'en';
let langLocale = window.localStorage.getItem(LOCALE_KEY) || 'en';
const i18n = new VueI18n({
  locale: langLocale,
  messages: locales,
  silentTranslationWarn: true
});
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);
    if (language) {
      langLocale = language.replace('-', '_').toLowerCase();
    }
    if (undefined !== langLocale && langLocale !== '') {
      lang = langLocale;
    }
    if (locales[lang] === undefined) {
      lang = DEFAULT_LANG;
    }
    // console.log(`lang-${lang}`);
  }
  Vue.config.lang = lang;
  i18n.locale = lang;
};
setup();
export default i18n;
src/locales/tw.js
New file
@@ -0,0 +1,4 @@
/* eslint-disable */
export default {
    "MingCheng": "名稱",
  }
src/locales/zh-CN.js
New file
@@ -0,0 +1,4 @@
/* eslint-disable */
export default {
    "MingCheng":"名称",
  }
src/main.js
@@ -12,6 +12,7 @@
import Vant from 'vant';
import 'vant/lib/index.css';
import { Swipe, SwipeItem, Skeleton, Switch, Notify } from 'vant';
import i18n from '@/locales';
import './assets/css/style.css';
@@ -47,6 +48,9 @@
Vue.use(Vant);
Vue.use(Mint)
Vue.use(Tab);
Vue.use({
  i18n: (key, value) => i18n.t(key, value),
});
Vue.use(Tabs, Popup, DatetimePicker, Switch, Notify);
Vue.component('icon', Icon)
Vue.config.productionTip = false
src/page/newUser/index.vue
@@ -207,6 +207,7 @@
import * as api from "@/axios/api";
import { Toast } from "mint-ui";
import { isNull, pwdReg } from "@/utils/utils";
import i18n from '@/locales';
export default {