gc_i18n 1.0.7 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -36,7 +36,7 @@ export default {
36
36
  }
37
37
  },
38
38
  async mounted() {
39
- this.language = store.get("i18n_language") || navigator.language;
39
+ this.language = store.get("I18N_LANGUAGE") || navigator.language;
40
40
  const res = await getLanguages(this.token);
41
41
  if (res && res.result === 0) {
42
42
  this.languages = res.retVal;
package/packages/index.js CHANGED
@@ -17,7 +17,7 @@ export default class I18n {
17
17
  this.token = token || store2.get("token");
18
18
  this.appCode = appCode;
19
19
  this.router = router;
20
- this.locale = navigator.language || "zh-CN";
20
+ this.locale = store2.get("I18N_LANGUAGE") || navigator.language || "zh-CN";
21
21
  this.modalLoad = false;
22
22
  this.name = "";
23
23
  this.messages = messages || {};
@@ -69,22 +69,9 @@ export default class I18n {
69
69
  this.configInstance && this.configInstance.closeModal();
70
70
  this.name = to.name;
71
71
  token && this.setToken(token);
72
- await this.setLanguage(language);
72
+ await this.setLanguage(language || this.locale);
73
73
  next();
74
74
  });
75
- // router.afterEach((to, from) => {
76
- // nextTick(() => {
77
- // console.log("this.configInstance", this.configInstance);
78
-
79
- // if (!this.configInstance) {
80
- // console.log("to", to, to.name);
81
- // this.name = to.name;
82
- // } else {
83
- // this.configInstance.closeModal();
84
- // this.configInstance = null;
85
- // }
86
- // });
87
- // });
88
75
  keyboardJS.bind("shift > t", (e) => {
89
76
  // 打开弹窗
90
77
  this.configInstance.openModal({ name: this.name }); // 调用 openModal 方法
@@ -109,6 +96,7 @@ export default class I18n {
109
96
  }
110
97
  this.locale = language;
111
98
  this.i18n.global.locale.value = language;
99
+ store2.set("I18N_LANGUAGE", language);
112
100
  resolve(true);
113
101
  });
114
102
  }
@@ -62,7 +62,7 @@ export const saveTranslate = async (data, token) => {
62
62
  export const getTranslate = async ({ appCode, language = "zh-CN", token }) => {
63
63
  return new Promise(async (resolve, reject) => {
64
64
  // const appCodeStore = i18nStore.get(appCode);
65
- const languageStore = store2.namespace(`i18n_${appCode}`);
65
+ const languageStore = store2.namespace(`I18N_${_.toUpper(appCode)}`);
66
66
  const options = {
67
67
  appCode,
68
68
  language,
@@ -92,7 +92,7 @@ export const getTranslate = async ({ appCode, language = "zh-CN", token }) => {
92
92
  lastPullDate: res.lastPullDate,
93
93
  translatesDTOs: data
94
94
  };
95
- const languageStore = store2.namespace(`i18n_${appCode}`);
95
+ const languageStore = store2.namespace(`I18N_${_.toUpper(appCode)}`);
96
96
  languageStore.set(language, saveData, ":"); // Only update the specific key
97
97
  resolve(data);
98
98
  } else {
package/src/main.js CHANGED
@@ -2,11 +2,14 @@ import { createApp } from "vue";
2
2
  import App from "./App.vue";
3
3
  import gc_i18n from "../packages/index";
4
4
  import router from "./router/index";
5
+ import zh from "view-ui-plus/dist/locale/zh-CN";
5
6
 
6
7
  const i18n = new gc_i18n({
7
8
  appCode: "TEST",
8
9
  router,
9
- messages: {}
10
+ messages: {
11
+ "zh-CN": zh
12
+ }
10
13
  });
11
14
  console.log("i18n", i18n);
12
15
 
@@ -7,9 +7,9 @@ const routes = [
7
7
  component: () => import("../view/Home.vue")
8
8
  },
9
9
  {
10
- path: "/BOOK",
11
- name: "BOOK",
12
- component: () => import("../view/book.vue")
10
+ path: "/BOATNOTICE",
11
+ name: "BOATNOTICE",
12
+ component: () => import("../view/BOATNOTICE.vue")
13
13
  }
14
14
  ];
15
15
  const router = createRouter({
@@ -27,7 +27,7 @@ const change = (lang) => {
27
27
 
28
28
  <template>
29
29
  <div>
30
- {{ locale }}
30
+ <div>当前语言: {{ locale }}</div>
31
31
  <Button
32
32
  v-for="item in langs"
33
33
  :type="item.code === locale ? 'primary' : 'default'"
@@ -36,21 +36,21 @@ const change = (lang) => {
36
36
  >
37
37
  <div>
38
38
  <div>带路由前缀:</div>
39
- <div>{{ $t("BOOK.BAOCUN", "找不到2") }}</div>
39
+ <div>{{ $t("BOATNOTICE.DAOCHU", "找不到2") }}</div>
40
40
  </div>
41
41
 
42
42
  <div>
43
- <div>带路由前缀:</div>
44
- <div>{{ $t("HEJI{0}", [total], "合计:{0}条") }}</div>
43
+ <div>有变量的:</div>
44
+ <div>{{ $t("HJ: {0}GT", [total], "合xxx计:{0}条") }}</div>
45
45
  </div>
46
46
  <div>
47
47
  <div>不带前缀:</div>
48
- <div>{{ $t("BAOCUN", "找不到") }}</div>
48
+ <div>{{ $t("DAOCHU", "找不到") }}</div>
49
49
  <!-- <div>{{ $t("中文{0}", [{ comment: "找不到" }]) }}</div> -->
50
50
  </div>
51
51
  <div>
52
52
  <div>完全找不到的数据:</div>
53
- <div>{{ $t("BOOK.BAOCUNABC", "找不到") }}</div>
53
+ <div>{{ $t("ggbb", "找不到") }}</div>
54
54
  </div>
55
55
  <Page
56
56
  :total="40"