yh-i18n 2.1.3 → 2.1.6
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/index.js +17 -16
- package/language.vue +21 -10
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -38,7 +38,7 @@ Object.keys(zhCNBase).forEach((key) => {
|
|
|
38
38
|
keySet.add(key);
|
|
39
39
|
});
|
|
40
40
|
|
|
41
|
-
const unHandle
|
|
41
|
+
const unHandle = [];
|
|
42
42
|
|
|
43
43
|
function addTranslate(key) {
|
|
44
44
|
if (key.indexOf("vxe") === -1) {
|
|
@@ -57,32 +57,33 @@ function addTranslate(key) {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
let recursionAddTimer = null;
|
|
60
61
|
function recursionAddTranslate() {
|
|
62
|
+
if (recursionAddTimer !== null) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
61
65
|
// 当触发 content 加载完成触发递归方法后,判断是否有需要处理的键,有则处理,没有则忽略
|
|
62
|
-
if (unHandle.length) {
|
|
66
|
+
if (unHandle.length && contentReady) {
|
|
63
67
|
let key = unHandle.pop();
|
|
64
68
|
if (!keySet.has(key) && window.translateReady) {
|
|
65
69
|
keySet.add(key);
|
|
66
70
|
addTranslate(key);
|
|
67
71
|
}
|
|
68
72
|
// 通过延时降低任务密度,避免挤兑正常逻辑的运算资源
|
|
69
|
-
setTimeout(() => {
|
|
73
|
+
recursionAddTimer = setTimeout(() => {
|
|
74
|
+
cLog(`${unHandle.length} ${key}`);
|
|
75
|
+
recursionAddTimer = null;
|
|
70
76
|
recursionAddTranslate();
|
|
71
|
-
},
|
|
77
|
+
}, 150);
|
|
72
78
|
}
|
|
73
79
|
}
|
|
74
80
|
|
|
75
81
|
export const ct = (key, args) => {
|
|
76
|
-
if (isDev) {
|
|
77
|
-
//
|
|
78
|
-
if (
|
|
79
|
-
if (!keySet.has(key) && window.translateReady) {
|
|
80
|
-
keySet.add(key);
|
|
81
|
-
addTranslate(key);
|
|
82
|
-
}
|
|
83
|
-
} else {
|
|
84
|
-
// 当 content 加载未完成时,现将翻译键放入缓存中,等待加载完成后再处理。
|
|
82
|
+
if (isDev && window.translateCollect) {
|
|
83
|
+
// 将 键的处理全部放入队列中,避免挤兑正常逻辑的运算资源
|
|
84
|
+
if (!unHandle.includes(key)) {
|
|
85
85
|
unHandle.push(key);
|
|
86
|
+
recursionAddTranslate();
|
|
86
87
|
}
|
|
87
88
|
}
|
|
88
89
|
if (i18n) {
|
|
@@ -216,7 +217,7 @@ async function getRemoteMessage(list) {
|
|
|
216
217
|
});
|
|
217
218
|
} catch (err) {
|
|
218
219
|
if (isDev) {
|
|
219
|
-
console.
|
|
220
|
+
// console.count("翻译数据格式不对");
|
|
220
221
|
}
|
|
221
222
|
}
|
|
222
223
|
});
|
|
@@ -275,9 +276,9 @@ export function addI18nPage(router) {
|
|
|
275
276
|
|
|
276
277
|
export function cLog(string, isError = false) {
|
|
277
278
|
if (isError) {
|
|
278
|
-
console.error("%cyhI18n
|
|
279
|
+
console.error("%cyhI18n:%c", "font-size: 16px;font-weight: bold;color: #00ffff", "font-size: 16px;font-weight: bold;color: #ccccc", string);
|
|
279
280
|
} else {
|
|
280
|
-
console.log("%
|
|
281
|
+
console.log("%cYh-i18n%c " + string, "font-size: 18px;font-weight: bold;color: #61AFEF", "font-size: 12px;color: #999");
|
|
281
282
|
}
|
|
282
283
|
}
|
|
283
284
|
|
package/language.vue
CHANGED
|
@@ -3,29 +3,32 @@
|
|
|
3
3
|
split-button
|
|
4
4
|
class="language-dropdown"
|
|
5
5
|
trigger="click"
|
|
6
|
-
@command="setLang"
|
|
7
|
-
>
|
|
6
|
+
@command="setLang">
|
|
8
7
|
{{ title }}
|
|
9
8
|
<template #dropdown>
|
|
10
9
|
<el-dropdown-menu>
|
|
11
|
-
<el-dropdown-item
|
|
10
|
+
<el-dropdown-item
|
|
11
|
+
v-for="lo in localList"
|
|
12
|
+
:command="lo.value">
|
|
12
13
|
{{ lo.label }}
|
|
13
14
|
</el-dropdown-item>
|
|
14
15
|
</el-dropdown-menu>
|
|
15
16
|
</template>
|
|
16
17
|
</el-dropdown>
|
|
17
18
|
|
|
18
|
-
<el-link
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
<el-link
|
|
20
|
+
v-if="isDev"
|
|
21
|
+
type="warning"
|
|
22
|
+
href="/#/translate">
|
|
23
|
+
{{ ct("翻译管理") }}
|
|
24
|
+
</el-link>
|
|
21
25
|
|
|
22
26
|
<el-switch
|
|
23
27
|
active-text="收集"
|
|
24
28
|
inactive-text="不收集"
|
|
25
29
|
inline-prompt
|
|
26
30
|
v-if="isDev"
|
|
27
|
-
v-model="isCollect"
|
|
28
|
-
></el-switch>
|
|
31
|
+
v-model="isCollect"></el-switch>
|
|
29
32
|
</template>
|
|
30
33
|
|
|
31
34
|
<script setup>
|
|
@@ -36,11 +39,19 @@ import { ref, watch } from "vue";
|
|
|
36
39
|
const isDev = ref(window.translateReady);
|
|
37
40
|
|
|
38
41
|
const i18nStore = useI18nStore();
|
|
39
|
-
const isCollect = ref(
|
|
42
|
+
const isCollect = ref(!!localStorage.translateCollect);
|
|
40
43
|
watch(
|
|
41
44
|
() => isCollect.value,
|
|
42
45
|
(val) => {
|
|
43
|
-
|
|
46
|
+
if (val) {
|
|
47
|
+
localStorage.translateCollect = "1";
|
|
48
|
+
} else {
|
|
49
|
+
localStorage.removeItem("translateCollect");
|
|
50
|
+
}
|
|
51
|
+
window.translateCollect = val;
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
immediate: true,
|
|
44
55
|
}
|
|
45
56
|
);
|
|
46
57
|
|