yh-i18n 2.1.3 → 2.1.5
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 +13 -12
- 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
|
+
console.log("recursionAddTimer", key, unHandle.length);
|
|
75
|
+
recursionAddTimer = null;
|
|
70
76
|
recursionAddTranslate();
|
|
71
|
-
},
|
|
77
|
+
}, 150);
|
|
72
78
|
}
|
|
73
79
|
}
|
|
74
80
|
|
|
75
81
|
export const ct = (key, args) => {
|
|
76
82
|
if (isDev) {
|
|
77
|
-
//
|
|
78
|
-
if (
|
|
79
|
-
if (!keySet.has(key) && window.translateReady) {
|
|
80
|
-
keySet.add(key);
|
|
81
|
-
addTranslate(key);
|
|
82
|
-
}
|
|
83
|
-
} else {
|
|
84
|
-
// 当 content 加载未完成时,现将翻译键放入缓存中,等待加载完成后再处理。
|
|
83
|
+
// 将 键的处理全部放入队列中,避免挤兑正常逻辑的运算资源
|
|
84
|
+
if (!unHandle.includes(key)) {
|
|
85
85
|
unHandle.push(key);
|
|
86
|
+
recursionAddTranslate();
|
|
86
87
|
}
|
|
87
88
|
}
|
|
88
89
|
if (i18n) {
|