gc_i18n 1.0.0 → 1.0.1
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.
- package/lib/gc_i18n.js +4643 -6
- package/lib/gc_i18n.umd.cjs +12 -11
- package/package.json +2 -1
- package/packages/components/LangChange.vue +0 -1
- package/packages/index.js +14 -3
- package/packages/libs/service.js +4 -5
- package/src/main.js +5 -4
- package/src/router/index.js +2 -2
- package/src/view/Home.vue +4 -0
- package/vite.config.js +6 -6
package/packages/index.js
CHANGED
|
@@ -32,18 +32,29 @@ export default class I18n {
|
|
|
32
32
|
// 保存原始的 t 方法
|
|
33
33
|
const originalT = this.i18n.global.t;
|
|
34
34
|
// 自定义 t 方法
|
|
35
|
-
this.i18n.global.t = (key) => {
|
|
36
|
-
const routeName = router?.currentRoute?.value?.name;
|
|
35
|
+
this.i18n.global.t = (key, args) => {
|
|
36
|
+
const routeName = _.toUpper(router?.currentRoute?.value?.name);
|
|
37
37
|
// 使用原始的 t 方法进行翻译
|
|
38
38
|
const originalTranslation = originalT(key);
|
|
39
39
|
// 如果没有找到翻译值,尝试使用路由名.key
|
|
40
40
|
if (originalTranslation === key && routeName) {
|
|
41
41
|
const prefixedKey = `${routeName}.${key}`;
|
|
42
42
|
// 同样使用原始的 t 方法进行翻译
|
|
43
|
-
|
|
43
|
+
const routeTranslation = originalT(prefixedKey);
|
|
44
|
+
|
|
45
|
+
if (routeTranslation !== prefixedKey) {
|
|
46
|
+
return routeTranslation;
|
|
47
|
+
} else {
|
|
48
|
+
if (args && _.has(args, "comment")) {
|
|
49
|
+
return _.get(args, "comment");
|
|
50
|
+
} else {
|
|
51
|
+
return key;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
44
54
|
}
|
|
45
55
|
return originalTranslation;
|
|
46
56
|
};
|
|
57
|
+
|
|
47
58
|
this.i18n.global.changeLocal = (newLocale) => {
|
|
48
59
|
this.setLanguage(newLocale || this.locale);
|
|
49
60
|
};
|
package/packages/libs/service.js
CHANGED
|
@@ -3,7 +3,7 @@ import store2 from "store2";
|
|
|
3
3
|
import _ from "lodash-es";
|
|
4
4
|
import { mergeArraysByKey } from "./utils";
|
|
5
5
|
export const service = "https://test.ihotel.cn";
|
|
6
|
-
|
|
6
|
+
|
|
7
7
|
const Authorization =
|
|
8
8
|
"eyJhbGciOiJIUzUxMiJ9.eyJkZXZpY2VUeXBlIjoiQ09NUFVURVIiLCJtYWluQXBwQ29kZSI6IlNTTyIsIm9yZ0NvZGUiOiJHQ0JaRyIsInVjU2VydmVyVXJsIjoiaHR0cHM6Ly90ZXN0Lmlob3RlbC5jbi91Yy13ZWIvIiwiYXBwQ29kZSI6IlNTTyIsInVzZXJUeXBlIjoiTk9STUFMIiwibG9naW5BdCI6MTczODczNTczOTAwMCwicHJpbmNpcGFsVXNlckNvZGUiOiJHQ0JaR19BRE1JTiIsImV4cCI6MzI1MDM2NTEyMDAsInVzZXJDb2RlIjoiR0NCWkdfQURNSU4iLCJzc28iOiJTU09fU0VSVkVSIn0.KQt1YbUdJ7DfqrfXEVYT0Ux-7Zlo2GQBiIoq0rxK0cv1LHqOOMtBkv8kmChM6VavtdnlyXM2GkW6YMvIIHvu0Q";
|
|
9
9
|
export const getLanguages = async () => {
|
|
@@ -42,8 +42,6 @@ export const fetchTranslate = async ({
|
|
|
42
42
|
};
|
|
43
43
|
|
|
44
44
|
export const getAllTranslate = async (data) => {
|
|
45
|
-
console.log("data", data);
|
|
46
|
-
|
|
47
45
|
return axios({
|
|
48
46
|
url: service + "/i18n-web/kv_translate/kv_translates",
|
|
49
47
|
method: "POST",
|
|
@@ -62,7 +60,7 @@ export const saveTranslate = async (data) => {
|
|
|
62
60
|
export const getTranslate = async ({ appCode, language = "zh-CN" }) => {
|
|
63
61
|
return new Promise(async (resolve, reject) => {
|
|
64
62
|
// const appCodeStore = i18nStore.get(appCode);
|
|
65
|
-
const languageStore =
|
|
63
|
+
const languageStore = store2.namespace(`i18n_${appCode}`);
|
|
66
64
|
const options = {
|
|
67
65
|
appCode,
|
|
68
66
|
language
|
|
@@ -88,7 +86,8 @@ export const getTranslate = async ({ appCode, language = "zh-CN" }) => {
|
|
|
88
86
|
if (!_.isEmpty(res.translatesDTOs)) {
|
|
89
87
|
const data = mergeArraysByKey(langData, res.translatesDTOs);
|
|
90
88
|
const saveData = { lastPullDate, translatesDTOs: data };
|
|
91
|
-
|
|
89
|
+
const languageStore = store2.namespace(`i18n_${appCode}`);
|
|
90
|
+
languageStore.set(language, saveData, ":"); // Only update the specific key
|
|
92
91
|
resolve(data);
|
|
93
92
|
} else {
|
|
94
93
|
resolve(langData);
|
package/src/main.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { createApp } from "vue";
|
|
2
2
|
import App from "./App.vue";
|
|
3
|
-
import gc_i18n from "../packages/index
|
|
3
|
+
import gc_i18n from "../packages/index";
|
|
4
4
|
import router from "./router/index";
|
|
5
5
|
import "view-ui-plus/dist/styles/viewuiplus.css";
|
|
6
|
-
|
|
6
|
+
import iview from "view-ui-plus";
|
|
7
7
|
import zh from "view-ui-plus/dist/locale/zh-CN";
|
|
8
8
|
import en from "view-ui-plus/dist/locale/en-US";
|
|
9
9
|
|
|
10
|
-
const i18n = new gc_i18n({
|
|
10
|
+
const { i18n } = new gc_i18n({
|
|
11
11
|
appCode: "TEST",
|
|
12
12
|
router,
|
|
13
13
|
messages: {
|
|
@@ -15,7 +15,8 @@ const i18n = new gc_i18n({
|
|
|
15
15
|
"en-US": en
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
+
console.log("i18n", i18n);
|
|
18
19
|
|
|
19
|
-
const app = createApp(App).use(router).use(i18n
|
|
20
|
+
const app = createApp(App).use(router).use(iview).use(i18n);
|
|
20
21
|
|
|
21
22
|
app.mount("#app");
|
package/src/router/index.js
CHANGED
package/src/view/Home.vue
CHANGED
package/vite.config.js
CHANGED
|
@@ -3,7 +3,7 @@ import vue from "@vitejs/plugin-vue";
|
|
|
3
3
|
import vueJsx from "@vitejs/plugin-vue-jsx";
|
|
4
4
|
import { resolve } from "path";
|
|
5
5
|
import libCss from "vite-plugin-libcss";
|
|
6
|
-
import terser from "@rollup/plugin-terser"; // 不用解构出来 有默认导出
|
|
6
|
+
// import terser from "@rollup/plugin-terser"; // 不用解构出来 有默认导出
|
|
7
7
|
|
|
8
8
|
// https://vite.dev/config/
|
|
9
9
|
export default defineConfig({
|
|
@@ -28,11 +28,11 @@ export default defineConfig({
|
|
|
28
28
|
lodash: "_"
|
|
29
29
|
},
|
|
30
30
|
plugins: [
|
|
31
|
-
terser({
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
})
|
|
31
|
+
// terser({
|
|
32
|
+
// compress: {
|
|
33
|
+
// drop_console: false
|
|
34
|
+
// }
|
|
35
|
+
// })
|
|
36
36
|
]
|
|
37
37
|
}
|
|
38
38
|
},
|