i18n-jsautotranslate 3.18.61 → 3.18.63
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/ArcoDesign/Vue3/LanguageSelect.vue +5 -5
- package/index.js +137 -123
- package/package.json +3 -2
- package/vue/vue3/translate.ts +54 -0
- package/vue/vue3/translateVue3TS.ts +83 -0
|
@@ -127,9 +127,9 @@ onMounted(() => {
|
|
|
127
127
|
};
|
|
128
128
|
|
|
129
129
|
|
|
130
|
-
//
|
|
131
|
-
translate.lifecycle.execute.
|
|
132
|
-
if(
|
|
130
|
+
// 当用户打开页面后,第一次过了初始化正式进行执行 translate.execute() 时,进行触发
|
|
131
|
+
translate.lifecycle.execute.start.push(function(data){
|
|
132
|
+
if(translate.selectLanguageTag.show === true && translate.selectLanguageTag.alreadyRender === false){
|
|
133
133
|
//console.log('这是打开页面后,第一次触发 translate.execute() ,因为translate.executeNumber 记录的是translate.execute() 执行完的次数。');
|
|
134
134
|
// 触发语言下拉列表出现
|
|
135
135
|
//渲染语言下拉列表出现
|
|
@@ -137,8 +137,8 @@ onMounted(() => {
|
|
|
137
137
|
}
|
|
138
138
|
});
|
|
139
139
|
//如果已经触发了 translate.execute() 那么直接就渲染
|
|
140
|
-
//console.log(translate.
|
|
141
|
-
if(translate.
|
|
140
|
+
//console.log(translate.executeNumber+ ', '+translate.state)
|
|
141
|
+
if(translate.executeNumber > 0 || translate.state > 0){
|
|
142
142
|
refreshLanguage();
|
|
143
143
|
}
|
|
144
144
|
|
package/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var translate = {
|
|
|
14
14
|
* 格式:major.minor.patch.date
|
|
15
15
|
*/
|
|
16
16
|
// AUTO_VERSION_START
|
|
17
|
-
version: '3.18.
|
|
17
|
+
version: '3.18.63.20250928',
|
|
18
18
|
// AUTO_VERSION_END
|
|
19
19
|
/*
|
|
20
20
|
当前使用的版本,默认使用v2. 可使用 setUseVersion2();
|
|
@@ -24,7 +24,7 @@ var translate = {
|
|
|
24
24
|
/*js translate.setUseVersion2 start*/
|
|
25
25
|
setUseVersion2:function(){
|
|
26
26
|
translate.useVersion = 'v2';
|
|
27
|
-
|
|
27
|
+
translate.log('提示:自 v2.10 之后的版本默认就是使用V2版本(当前版本为:'+translate.version+'), translate.setUseVersion2() 可以不用再加这一行了。当然加了也无所谓,只是加了跟不加是完全一样的。');
|
|
28
28
|
},
|
|
29
29
|
/*js translate.setUseVersion2 end*/
|
|
30
30
|
/*
|
|
@@ -49,6 +49,12 @@ var translate = {
|
|
|
49
49
|
resourcesUrl:'//res.zvo.cn/translate',
|
|
50
50
|
/*js translate.resourcesUrl end*/
|
|
51
51
|
|
|
52
|
+
/*js translate.log start*/
|
|
53
|
+
log: function(obj){
|
|
54
|
+
console.log(obj);
|
|
55
|
+
},
|
|
56
|
+
/*js translate.log end*/
|
|
57
|
+
|
|
52
58
|
/**
|
|
53
59
|
* 默认出现的选择语言的 select 选择框,可以通过这个选择切换语言。
|
|
54
60
|
*/
|
|
@@ -161,7 +167,7 @@ var translate = {
|
|
|
161
167
|
if(document.getElementById(translate.selectLanguageTag.documentId) == null){
|
|
162
168
|
var findBody = document.getElementsByTagName('body');
|
|
163
169
|
if(findBody.length == 0){
|
|
164
|
-
|
|
170
|
+
translate.log('body tag not find, translate.selectLanguageTag.render() is not show Select Language');
|
|
165
171
|
return;
|
|
166
172
|
}
|
|
167
173
|
var body_trans = findBody[0];
|
|
@@ -181,7 +187,7 @@ var translate = {
|
|
|
181
187
|
//从接口加载语种
|
|
182
188
|
translate.request.post(translate.request.api.language, {}, function(data){
|
|
183
189
|
if(data.result == 0){
|
|
184
|
-
|
|
190
|
+
translate.log('load language list error : '+data.info);
|
|
185
191
|
return;
|
|
186
192
|
}
|
|
187
193
|
//console.log(data.list);
|
|
@@ -263,8 +269,8 @@ var translate = {
|
|
|
263
269
|
* 已废弃,v1使用的
|
|
264
270
|
*/
|
|
265
271
|
execute_v1:function(){
|
|
266
|
-
|
|
267
|
-
|
|
272
|
+
translate.log('=====ERROR======');
|
|
273
|
+
translate.log('The v1 version has been discontinued since 2022. Please use the latest V3 version and refer to: http://translate.zvo.cn/41162.html');
|
|
268
274
|
},
|
|
269
275
|
/*js translate.execute_v1 end*/
|
|
270
276
|
|
|
@@ -328,7 +334,7 @@ var translate = {
|
|
|
328
334
|
var v1 = ',en,de,hi,lt,hr,lv,ht,hu,zh-CN,hy,uk,mg,id,ur,mk,ml,mn,af,mr,uz,ms,el,mt,is,it,my,es,et,eu,ar,pt-PT,ja,ne,az,fa,ro,nl,en-GB,no,be,fi,ru,bg,fr,bs,sd,se,si,sk,sl,ga,sn,so,gd,ca,sq,sr,kk,st,km,kn,sv,ko,sw,gl,zh-TW,pt-BR,co,ta,gu,ky,cs,pa,te,tg,th,la,cy,pl,da,tr,';
|
|
329
335
|
if(v1.indexOf(','+languageName+',') > -1){
|
|
330
336
|
//用的是v1.x
|
|
331
|
-
|
|
337
|
+
translate.log('您使用的是v1版本的切换语种方式,v1已在2021年就以废弃,请更换为v2,参考文档: http://translate.zvo.cn/41549.html');
|
|
332
338
|
translate.check();
|
|
333
339
|
|
|
334
340
|
var googtrans = '/'+translate.localLanguage+'/'+languageName;
|
|
@@ -380,7 +386,7 @@ var translate = {
|
|
|
380
386
|
}
|
|
381
387
|
}catch(e){
|
|
382
388
|
//增加try,避免异常导致无法用
|
|
383
|
-
|
|
389
|
+
translate.log(e);
|
|
384
390
|
}
|
|
385
391
|
|
|
386
392
|
translate.time.log('iframe 完成');
|
|
@@ -436,7 +442,7 @@ var translate = {
|
|
|
436
442
|
}
|
|
437
443
|
}catch(e){
|
|
438
444
|
//增加try,避免异常,比如跨域,中断导致无法用
|
|
439
|
-
|
|
445
|
+
translate.log(e);
|
|
440
446
|
}
|
|
441
447
|
}
|
|
442
448
|
}
|
|
@@ -460,7 +466,7 @@ var translate = {
|
|
|
460
466
|
/*js translate.check start*/
|
|
461
467
|
check:function(){
|
|
462
468
|
if(window.location.protocol == 'file:'){
|
|
463
|
-
|
|
469
|
+
translate.log('\r\n---WARNING----\r\ntranslate.js 主动翻译组件自检异常,当前协议是file协议,翻译组件要在正常的线上http、https协议下才能正常使用翻译功能\r\n------------');
|
|
464
470
|
}
|
|
465
471
|
},
|
|
466
472
|
/*js translate.check end*/
|
|
@@ -685,10 +691,10 @@ var translate = {
|
|
|
685
691
|
//如果from未传入,则自动识别当前页面的语种为from
|
|
686
692
|
//如果自动识别,也要确保是页面加载完后,免得放到了head里,那肯定啥也识别不出来
|
|
687
693
|
if(document.body == null){
|
|
688
|
-
|
|
694
|
+
translate.log('使用错误!你使用自定义术语 translate.nomenclature.append 时,from 未传值,此时 translate.js 会自动识别当前翻译区域的内容是什么语种,但是你当前吧 translate.nomenclature.append 放在了body之前就加载了,body都还没加载出来,翻译区域当前无内容,所以无法识别当前页面的语种。请将 translate.nomenclature.append 放在翻译内容加载完后再执行 (注意,要将 translate.nomenclature.append 放在 translate.execute() 的前面),建议将 translate.nomenclature.append 放在 </body> 跟 </html> 之间。');
|
|
689
695
|
}else{
|
|
690
696
|
if (document.readyState === 'loading') {
|
|
691
|
-
|
|
697
|
+
translate.log('使用异常告警:你使用的自定义术语 translate.nomenclature.append 时,from 未传值,此时 translate.js 会自动识别当前翻译区域的内容是什么语种,但页面Dom还未加载完毕时就触发了它,如果翻译区域当前无内容或者内容不是完整的,会造成识别当前页面的语种会有异常不准确,你需要仔细确认这个问题。建议将 translate.nomenclature.append 放在 </body> 跟 </html> 之间。');
|
|
692
698
|
}
|
|
693
699
|
}
|
|
694
700
|
|
|
@@ -843,7 +849,15 @@ var translate = {
|
|
|
843
849
|
|
|
844
850
|
|
|
845
851
|
//如果是自定义术语的key等于value,则是属于指定的某些文本不进行翻译的情况,所以这里要单独判断一下,它俩不相等才会去进行替换操作,免得进行性能计算浪费 - 虽然这一步是不会到的,因为在这个方法的入口处就已经经过这个判定了
|
|
846
|
-
if(nodeObject != null){
|
|
852
|
+
if(nodeObject != null && typeof(nodeObject.node) !== 'undefined' && nodeObject.node !== null){
|
|
853
|
+
|
|
854
|
+
// 记录此次node的改变是有 translate.js 导致的,避免被dom改变监听给误以为别的引起的
|
|
855
|
+
if(translate.node.get(nodeObject.node) != null){
|
|
856
|
+
translate.node.get(nodeObject.node).lastTranslateRenderTime = Date.now();
|
|
857
|
+
}else{
|
|
858
|
+
//这个如果有 translate.js 内部自主触发,肯定不会没有值的。但是如果手动再其他程序里触发,那这个是会没有值的
|
|
859
|
+
}
|
|
860
|
+
|
|
847
861
|
if(nomenclatureKey === nomenclatureValue){
|
|
848
862
|
//自定义忽略翻译的文字 ,key 跟 value 相等,便是忽略翻译的
|
|
849
863
|
translate.element.nodeAnalyse.set(nodeObject.node, nomenclatureKey, nomenclatureValue, nodeObject.attribute);
|
|
@@ -1076,7 +1090,7 @@ var translate = {
|
|
|
1076
1090
|
*/
|
|
1077
1091
|
set: async function(hash, originalText, toLanguage, translateText){
|
|
1078
1092
|
if(typeof(translate.storage.IndexedDB) == 'undefined'){
|
|
1079
|
-
|
|
1093
|
+
translate.log('ERROR: translate.storage.IndexedDB not find');
|
|
1080
1094
|
return;
|
|
1081
1095
|
}
|
|
1082
1096
|
var obj = await translate.storage.IndexedDB.get('hash_'+hash);
|
|
@@ -1096,11 +1110,11 @@ var translate = {
|
|
|
1096
1110
|
*/
|
|
1097
1111
|
export: async function(to){
|
|
1098
1112
|
if(typeof(translate.storage.IndexedDB) == 'undefined'){
|
|
1099
|
-
|
|
1113
|
+
translate.log('ERROR: translate.storage.IndexedDB not find');
|
|
1100
1114
|
return;
|
|
1101
1115
|
}
|
|
1102
1116
|
if(typeof(to) != 'string'){
|
|
1103
|
-
|
|
1117
|
+
translate.log('error : to param not find, example: "english"');
|
|
1104
1118
|
return;
|
|
1105
1119
|
}
|
|
1106
1120
|
var text = 'translate.office.append(\'';
|
|
@@ -1506,7 +1520,7 @@ var translate = {
|
|
|
1506
1520
|
try{
|
|
1507
1521
|
translate.listener.execute.renderStartByApi[i](uuid, from, to);
|
|
1508
1522
|
}catch(e){
|
|
1509
|
-
|
|
1523
|
+
translate.log(e);
|
|
1510
1524
|
}
|
|
1511
1525
|
}
|
|
1512
1526
|
},
|
|
@@ -1525,7 +1539,7 @@ var translate = {
|
|
|
1525
1539
|
try{
|
|
1526
1540
|
translate.listener.execute.renderFinishByApi[i](uuid, from, to);
|
|
1527
1541
|
}catch(e){
|
|
1528
|
-
|
|
1542
|
+
translate.log(e);
|
|
1529
1543
|
}
|
|
1530
1544
|
}
|
|
1531
1545
|
}
|
|
@@ -1685,8 +1699,8 @@ var translate = {
|
|
|
1685
1699
|
// 记录当前有 translate.js 所触发翻译之后渲染到dom界面显示的时间,13位时间戳
|
|
1686
1700
|
translate.node.get(this.nodes[hash][task_index]).lastTranslateRenderTime = Date.now();
|
|
1687
1701
|
}else{
|
|
1688
|
-
|
|
1689
|
-
|
|
1702
|
+
translate.log('执行异常,渲染时,node未在 nodeHistory 中找到, 这个理论上是不应该存在的,当前异常已被容错。 node:'+this.nodes[hash][task_index]);
|
|
1703
|
+
translate.log(this.nodes[hash][task_index]);
|
|
1690
1704
|
}
|
|
1691
1705
|
|
|
1692
1706
|
//渲染页面进行翻译显示
|
|
@@ -1697,7 +1711,7 @@ var translate = {
|
|
|
1697
1711
|
if(translate.node.data.get(this.nodes[hash][task_index]) != null){
|
|
1698
1712
|
if(typeof(translate.node.get(this.nodes[hash][task_index])[nodeAttribute.key]) == 'undefined'){
|
|
1699
1713
|
//这里不应该的
|
|
1700
|
-
|
|
1714
|
+
translate.log('执行异常,渲染时,node 的 '+(nodeAttribute.attribute.length == 0? 'nodeValue':'attribute : '+nodeAttribute.attribute)+' 未在 nodeHistory 中找到, 这个理论上是不应该存在的,当前异常已被容错。 node:'+this.nodes[hash][task_index]);
|
|
1701
1715
|
}else{
|
|
1702
1716
|
//将具体通过文本翻译接口进行翻译的文本记录到 translate.node.data
|
|
1703
1717
|
translate.node.get(this.nodes[hash][task_index])[nodeAttribute.key].translateTexts[task.originalText] = task.resultText;
|
|
@@ -1708,8 +1722,8 @@ var translate = {
|
|
|
1708
1722
|
translate.history.translateText.add(translate.node.get(this.nodes[hash][task_index])[nodeAttribute.key].originalText ,analyseSet.resultText);
|
|
1709
1723
|
}
|
|
1710
1724
|
}else{
|
|
1711
|
-
|
|
1712
|
-
|
|
1725
|
+
translate.log('执行异常,渲染时,node未在 nodeHistory 中找到, 这个理论上是不应该存在的,当前异常已被容错。 node:'+this.nodes[hash][task_index]);
|
|
1726
|
+
translate.log(this.nodes[hash][task_index]);
|
|
1713
1727
|
}
|
|
1714
1728
|
|
|
1715
1729
|
//加入 translate.listener.ignoreNode
|
|
@@ -1816,7 +1830,7 @@ var translate = {
|
|
|
1816
1830
|
if(translate.waitingExecute.queue.length > 0){
|
|
1817
1831
|
return translate.waitingExecute.queue.shift();
|
|
1818
1832
|
}else{
|
|
1819
|
-
|
|
1833
|
+
translate.log('警告, translate.waitingExecute.get 出现异常,quque已空,但还往外取。');
|
|
1820
1834
|
return null;
|
|
1821
1835
|
}
|
|
1822
1836
|
},
|
|
@@ -1896,7 +1910,7 @@ var translate = {
|
|
|
1896
1910
|
try{
|
|
1897
1911
|
translate.lifecycle.changeLanguage[i](to);
|
|
1898
1912
|
}catch(e){
|
|
1899
|
-
|
|
1913
|
+
translate.log(e);
|
|
1900
1914
|
}
|
|
1901
1915
|
}
|
|
1902
1916
|
},
|
|
@@ -1934,7 +1948,7 @@ var translate = {
|
|
|
1934
1948
|
isNextExecute = false;
|
|
1935
1949
|
}
|
|
1936
1950
|
}catch(e){
|
|
1937
|
-
|
|
1951
|
+
translate.log(e);
|
|
1938
1952
|
}
|
|
1939
1953
|
}
|
|
1940
1954
|
return isNextExecute;
|
|
@@ -1960,13 +1974,13 @@ var translate = {
|
|
|
1960
1974
|
try{
|
|
1961
1975
|
translate.lifecycle.execute.start[i](data.uuid, data.to);
|
|
1962
1976
|
}catch(e){
|
|
1963
|
-
|
|
1977
|
+
translate.log(e);
|
|
1964
1978
|
}
|
|
1965
1979
|
}else{
|
|
1966
1980
|
try{
|
|
1967
1981
|
translate.lifecycle.execute.start[i](data);
|
|
1968
1982
|
}catch(e){
|
|
1969
|
-
|
|
1983
|
+
translate.log(e);
|
|
1970
1984
|
}
|
|
1971
1985
|
}
|
|
1972
1986
|
|
|
@@ -1982,7 +1996,7 @@ var translate = {
|
|
|
1982
1996
|
try{
|
|
1983
1997
|
translate.listener.execute.renderStartByApi[i](uuid, from, to);
|
|
1984
1998
|
}catch(e){
|
|
1985
|
-
|
|
1999
|
+
translate.log(e);
|
|
1986
2000
|
}
|
|
1987
2001
|
}
|
|
1988
2002
|
},
|
|
@@ -2033,14 +2047,14 @@ var translate = {
|
|
|
2033
2047
|
try{
|
|
2034
2048
|
translate.lifecycle.execute.translateNetworkBefore[i](data.uuid, data.from, data.to, data.texts);
|
|
2035
2049
|
}catch(e){
|
|
2036
|
-
|
|
2050
|
+
translate.log(e);
|
|
2037
2051
|
}
|
|
2038
2052
|
}else{
|
|
2039
2053
|
//2025.9.15 之后的新的
|
|
2040
2054
|
try{
|
|
2041
2055
|
translate.lifecycle.execute.translateNetworkBefore[i](data);
|
|
2042
2056
|
}catch(e){
|
|
2043
|
-
|
|
2057
|
+
translate.log(e);
|
|
2044
2058
|
}
|
|
2045
2059
|
}
|
|
2046
2060
|
|
|
@@ -2065,7 +2079,7 @@ var translate = {
|
|
|
2065
2079
|
try{
|
|
2066
2080
|
translate.lifecycle.execute.translateNetworkAfter[i](data);
|
|
2067
2081
|
}catch(e){
|
|
2068
|
-
|
|
2082
|
+
translate.log(e);
|
|
2069
2083
|
}
|
|
2070
2084
|
}
|
|
2071
2085
|
},
|
|
@@ -2089,7 +2103,7 @@ var translate = {
|
|
|
2089
2103
|
try{
|
|
2090
2104
|
translate.lifecycle.execute.renderFinish[i](uuid, to);
|
|
2091
2105
|
}catch(e){
|
|
2092
|
-
|
|
2106
|
+
translate.log(e);
|
|
2093
2107
|
}
|
|
2094
2108
|
}
|
|
2095
2109
|
},
|
|
@@ -2120,7 +2134,7 @@ var translate = {
|
|
|
2120
2134
|
try{
|
|
2121
2135
|
translate.lifecycle.execute.finally[i](data);
|
|
2122
2136
|
}catch(e){
|
|
2123
|
-
|
|
2137
|
+
translate.log(e);
|
|
2124
2138
|
}
|
|
2125
2139
|
}
|
|
2126
2140
|
},
|
|
@@ -2224,7 +2238,7 @@ var translate = {
|
|
|
2224
2238
|
}
|
|
2225
2239
|
|
|
2226
2240
|
|
|
2227
|
-
|
|
2241
|
+
translate.log('当前翻译未完结,新翻译任务已加入等待翻译队列,待上个翻译任务结束后便会执行当前翻译任务'+sliceDocString);
|
|
2228
2242
|
//console.log(docs);
|
|
2229
2243
|
translate.waitingExecute.add(docs);
|
|
2230
2244
|
|
|
@@ -2259,7 +2273,7 @@ var translate = {
|
|
|
2259
2273
|
//translate.execute_v1();
|
|
2260
2274
|
//return;
|
|
2261
2275
|
//v2.5.1增加
|
|
2262
|
-
|
|
2276
|
+
translate.log('提示:https://github.com/xnx3/translate 在 v2.5 版本之后,由于谷歌翻译调整,免费翻译通道不再支持,所以v1版本的翻译接口不再被支持,v1全线下架。考虑到v1已不能使用,当前已自动切换到v2版本。如果您使用中发现什么异常,请针对v2版本进行适配。');
|
|
2263
2277
|
translate.useVersion = 'v2';
|
|
2264
2278
|
}
|
|
2265
2279
|
|
|
@@ -2288,7 +2302,7 @@ var translate = {
|
|
|
2288
2302
|
try{
|
|
2289
2303
|
translate.selectLanguageTag.render();
|
|
2290
2304
|
}catch(e){
|
|
2291
|
-
|
|
2305
|
+
translate.log(e);
|
|
2292
2306
|
}
|
|
2293
2307
|
|
|
2294
2308
|
translate.time.log('渲染出选择语言的select窗口-已完成');
|
|
@@ -2356,8 +2370,8 @@ var translate = {
|
|
|
2356
2370
|
//console.log(all)
|
|
2357
2371
|
|
|
2358
2372
|
if(all.length > 500){
|
|
2359
|
-
|
|
2360
|
-
|
|
2373
|
+
translate.log('------tip------');
|
|
2374
|
+
translate.log('translate.execute( docs ) 传入的docs.length 过大,超过500,这很不正常,当前 docs.length : '+all.length+' ,如果你感觉真的没问题,请联系作者 http://translate.zvo.cn/43006.html 说明情况,根据你的情况进行分析。 当前只取前500个元素进行翻译');
|
|
2361
2375
|
}
|
|
2362
2376
|
|
|
2363
2377
|
//初始化 translate.element.tagAttribute ,主要针对 v3.17.10 版本的适配调整,对 translate.element.tagAttribute 的设置做了改变,做旧版本的适配
|
|
@@ -2378,7 +2392,7 @@ var translate = {
|
|
|
2378
2392
|
}
|
|
2379
2393
|
}
|
|
2380
2394
|
}catch(e){
|
|
2381
|
-
|
|
2395
|
+
translate.log(e);
|
|
2382
2396
|
}
|
|
2383
2397
|
|
|
2384
2398
|
translate.time.log('开始扫描要翻译区域的元素');
|
|
@@ -2409,8 +2423,8 @@ var translate = {
|
|
|
2409
2423
|
if(typeof(translate.nodeQueue[uuid]) == 'undefined'){
|
|
2410
2424
|
translate.nodeQueue[uuid] = new Array();
|
|
2411
2425
|
translate.nodeQueue[uuid].list = [];
|
|
2412
|
-
|
|
2413
|
-
|
|
2426
|
+
translate.log('--- translate.js warn tip 警告!! ---');
|
|
2427
|
+
translate.log('您使用translate.js时可能放的位置不对,不要吧 translate.js 放在网页最顶部,这样当 translate.js 进行执行,也就是 translate.execute() 执行时,因为网页是从上往下加载,它放在网页最顶部,那么它执行时网页后面的内容都还没加载出来,这个是不会获取到网页任何内容的,也就是它是不起任何作用的');
|
|
2414
2428
|
}
|
|
2415
2429
|
for(var lang in translate.nodeQueue[uuid].list){
|
|
2416
2430
|
if (!translate.nodeQueue[uuid].list.hasOwnProperty(lang)) {
|
|
@@ -2873,7 +2887,7 @@ var translate = {
|
|
|
2873
2887
|
//console.log(lang);
|
|
2874
2888
|
//console.log(translate.nodeQueue[uuid]['list'][lang][thhash].nodes);
|
|
2875
2889
|
if(typeof(translate.nodeQueue[uuid]['list'][lang][thhash].nodes) == 'undefined' || typeof(translate.nodeQueue[uuid]['list'][lang][thhash].nodes.length) == 'undefined'){
|
|
2876
|
-
|
|
2890
|
+
translate.log('translate.nodeQueue[\''+uuid+'\'][\'list\'][\''+lang+'\'][\''+thhash+'\'].nodes.length is null ,理论上不应该存在,进行异常报出,但不影响使用,已容错。');
|
|
2877
2891
|
continue;
|
|
2878
2892
|
}
|
|
2879
2893
|
|
|
@@ -2933,9 +2947,9 @@ var translate = {
|
|
|
2933
2947
|
}
|
|
2934
2948
|
|
|
2935
2949
|
if(typeof(translateTextArray[lang]) == 'undefined' || translateTextArray[lang].length < 1){
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2950
|
+
translate.log('异常,理论上不应该存在, lang:'+lang+', translateTextArray:');
|
|
2951
|
+
translate.log(translateTextArray);
|
|
2952
|
+
translate.log('你无需担心,这个只是个提示,它并不影响你翻译的正常进行,只是个异常提示而已,它会自动容错处理的,不会影响翻译的使用。');
|
|
2939
2953
|
|
|
2940
2954
|
translate.state = 0;
|
|
2941
2955
|
translate.executeNumber++;
|
|
@@ -3011,7 +3025,7 @@ var translate = {
|
|
|
3011
3025
|
translate.translateRequest[uuid][data.from].executeFinish = 1; //1是执行完毕
|
|
3012
3026
|
translate.translateRequest[uuid][data.from].stoptime = Math.floor(Date.now() / 1000);
|
|
3013
3027
|
}else{
|
|
3014
|
-
|
|
3028
|
+
translate.log('WARINNG!!! translate.translateRequest[uuid][data.from] is not object');
|
|
3015
3029
|
}
|
|
3016
3030
|
|
|
3017
3031
|
//为了兼容 v3.14以前的translate.service 版本,做了判断
|
|
@@ -3028,17 +3042,17 @@ var translate = {
|
|
|
3028
3042
|
translate.waitingExecute.isAllExecuteFinish(uuid, from, to, 0, data.info);
|
|
3029
3043
|
|
|
3030
3044
|
|
|
3031
|
-
|
|
3032
|
-
|
|
3045
|
+
translate.log('=======ERROR START=======');
|
|
3046
|
+
translate.log(translateTextArray[data.from]);
|
|
3033
3047
|
//console.log(encodeURIComponent(JSON.stringify(translateTextArray[data.from])));
|
|
3034
|
-
|
|
3035
|
-
|
|
3048
|
+
translate.log('response : '+data.info);
|
|
3049
|
+
translate.log('=======ERROR END =======');
|
|
3036
3050
|
//translate.temp_executeFinishNumber++; //记录执行完的次数
|
|
3037
3051
|
return;
|
|
3038
3052
|
}
|
|
3039
3053
|
|
|
3040
3054
|
if(typeof(translate.nodeQueue[uuid]) == 'undefined'){
|
|
3041
|
-
|
|
3055
|
+
translate.log('提示:你很可能多次引入了 translate.js 所以造成了翻译本身的数据错乱,这只是个提示,它还是会给你正常翻译的,但是你最好不要重复引入太多次 translate.js ,正常情况下只需要引入一次 translate.js 就可以了。太多的话很可能会导致你页面卡顿');
|
|
3042
3056
|
return;
|
|
3043
3057
|
}
|
|
3044
3058
|
|
|
@@ -3078,8 +3092,8 @@ var translate = {
|
|
|
3078
3092
|
originalWord = translate.nodeQueue[uuid]['list'][lang][hash]['original'];
|
|
3079
3093
|
//console.log('bef:'+translate.nodeQueue[uuid]['list'][lang][hash]['beforeText']);
|
|
3080
3094
|
}catch(e){
|
|
3081
|
-
|
|
3082
|
-
|
|
3095
|
+
translate.log('uuid:'+uuid+', originalWord:'+originalWord+', lang:'+lang+', hash:'+hash+', text:'+text+', queue:'+translate.nodeQueue[uuid]);
|
|
3096
|
+
translate.log(e);
|
|
3083
3097
|
continue;
|
|
3084
3098
|
}
|
|
3085
3099
|
|
|
@@ -3653,8 +3667,8 @@ var translate = {
|
|
|
3653
3667
|
if(typeof(node.tagName) == 'string' && node.tagName.length > 0){
|
|
3654
3668
|
return node.tagName;
|
|
3655
3669
|
}else{
|
|
3656
|
-
|
|
3657
|
-
|
|
3670
|
+
translate.log('warn : get nodeName is null, this node ignore translate. node : ');
|
|
3671
|
+
translate.log(node);
|
|
3658
3672
|
return '';
|
|
3659
3673
|
}
|
|
3660
3674
|
}
|
|
@@ -4092,14 +4106,12 @@ var translate = {
|
|
|
4092
4106
|
|
|
4093
4107
|
|
|
4094
4108
|
//记录 nodeHistory - 判断text是否已经被拆分了
|
|
4095
|
-
|
|
4096
|
-
if(textArray.length > 1 || textArray[0] != text){
|
|
4109
|
+
if(textArray.length > 0 && textArray[0] != text){ //主要是后面的是否相等,前面的>0只是避免代码报错
|
|
4097
4110
|
translate.node.get(node)[nodeAttribute.key].whole = false; //已经被拆分了,不是整体翻译了
|
|
4098
4111
|
//这时,也默认给其赋值操作,将自定义术语匹配后的结果进行赋予
|
|
4099
4112
|
}else{
|
|
4100
4113
|
translate.node.get(node)[nodeAttribute.key].whole = true; //未拆分,是整体翻译
|
|
4101
4114
|
}
|
|
4102
|
-
|
|
4103
4115
|
//成功加入到 nodeQueue 的对象。 如果长度为0,那就是还没有加入到 translate.nodeQueue 中,可能全被自定义术语命中了
|
|
4104
4116
|
var addQueueObjectArray = [];
|
|
4105
4117
|
|
|
@@ -4416,11 +4428,11 @@ var translate = {
|
|
|
4416
4428
|
if(translate.whole.class.length == 0 && translate.whole.tag.length == 0 && translate.whole.id.length == 0){
|
|
4417
4429
|
|
|
4418
4430
|
}else{
|
|
4419
|
-
|
|
4431
|
+
translate.log('您开启了 translate.whole 此次行为避开了浏览器端的文本语种自动识别,而是暴力的直接对某个元素的整个文本进行翻译,很可能会产生非常大的翻译量,请谨慎!有关每日翻译字符的说明,可参考: http://translate.zvo.cn/42557.html ');
|
|
4420
4432
|
}
|
|
4421
4433
|
|
|
4422
4434
|
if(translate.whole.tag.indexOf('html') > -1){
|
|
4423
|
-
|
|
4435
|
+
translate.log('自检发现您设置了 translate.whole.tag 其中有 html ,这个是不生效的,最大只允许设置到 body ');
|
|
4424
4436
|
}
|
|
4425
4437
|
},
|
|
4426
4438
|
|
|
@@ -4684,10 +4696,10 @@ var translate = {
|
|
|
4684
4696
|
clearCacheLanguage:function(){
|
|
4685
4697
|
if(typeof(translate.language.setUrlParamControl_use) != 'undefined'){
|
|
4686
4698
|
if(translate.language.setUrlParamControl_use){
|
|
4687
|
-
|
|
4688
|
-
|
|
4689
|
-
|
|
4690
|
-
|
|
4699
|
+
translate.log('使用提示:')
|
|
4700
|
+
translate.log('translate.language.setUrlParamControl(...) 的作用是 可以通过URL传一个语种,来指定当前页面以什么语种显示。 参考文档: http://translate.zvo.cn/4075.html');
|
|
4701
|
+
translate.log('translate.language.clearCacheLanguage() 是清除历史翻译语种缓存,也就是清除之前指定翻译为什么语种。 参考文档:http://translate.zvo.cn/4080.html')
|
|
4702
|
+
translate.log('如果你执行了 translate.language.setUrlParamControl(...) 那么是要根据url传参来切换语种的,但是后面又出现了 translate.language.clearCacheLanguage() 它会阻止 translate.language.setUrlParamControl(...) 它的设置,即使有url传递翻译为什么语言,也会因为 translate.language.clearCacheLanguage() 给清除掉,使URL传参的语种不起任何作用。')
|
|
4691
4703
|
}
|
|
4692
4704
|
}
|
|
4693
4705
|
translate.to = '';
|
|
@@ -4989,7 +5001,7 @@ var translate = {
|
|
|
4989
5001
|
|
|
4990
5002
|
var romanceSentenceLanguage = translate.language.romanceSentenceAnaly(str);
|
|
4991
5003
|
if(romanceSentenceLanguage.length == 0){
|
|
4992
|
-
|
|
5004
|
+
translate.log('语种识别异常,应该是 法语、西班牙语、葡萄牙语、意大利语 中的一种才是,除非是除了这四种语种之外的别的 罗曼语族 中的语种,当前已将 '+ str +'识别为英语。 你可以联系我们求助 https://translate.zvo.cn/4030.html');
|
|
4993
5005
|
}else{
|
|
4994
5006
|
data.languageName = romanceSentenceLanguage;
|
|
4995
5007
|
}
|
|
@@ -5852,9 +5864,9 @@ var translate = {
|
|
|
5852
5864
|
translate.request.post(translate.request.api.ip, {}, function(data){
|
|
5853
5865
|
//console.log(data);
|
|
5854
5866
|
if(data.result == 0){
|
|
5855
|
-
|
|
5856
|
-
|
|
5857
|
-
|
|
5867
|
+
translate.log('==== ERROR 获取当前用户所在区域异常 ====');
|
|
5868
|
+
translate.log(data.info);
|
|
5869
|
+
translate.log('==== ERROR END ====');
|
|
5858
5870
|
}else{
|
|
5859
5871
|
translate.storage.set('to',data.language); //设置目标翻译语言
|
|
5860
5872
|
translate.to = data.language; //设置目标语言
|
|
@@ -6089,7 +6101,7 @@ var translate = {
|
|
|
6089
6101
|
let replaceResult = translate.util.replaceFromIndex(text, replaceIndex, replaceOriginalText, replaceResultText);
|
|
6090
6102
|
|
|
6091
6103
|
if(replaceResult.replaceEndIndex < 1){
|
|
6092
|
-
|
|
6104
|
+
translate.log('translate.util.findParticiple 中已经发现了,但是实际没有替换,出现异常了!理论上这是不应该出现的。 text:'+text+' , index:'+indexArray[i]+', translateOriginal:'+translateOriginal);
|
|
6093
6105
|
}else{
|
|
6094
6106
|
text = replaceResult.text;
|
|
6095
6107
|
}
|
|
@@ -6766,7 +6778,7 @@ var translate = {
|
|
|
6766
6778
|
var tLang = translate.util.browserLanguage[language];
|
|
6767
6779
|
if(typeof(tLang) == 'undefined'){
|
|
6768
6780
|
//没有在里面
|
|
6769
|
-
|
|
6781
|
+
translate.log('browser default language : '+language +', translate.js current translate channel not support this language ');
|
|
6770
6782
|
}else{
|
|
6771
6783
|
return tLang;
|
|
6772
6784
|
}
|
|
@@ -6925,7 +6937,7 @@ var translate = {
|
|
|
6925
6937
|
*/
|
|
6926
6938
|
use: function(serviceName){
|
|
6927
6939
|
if(typeof(translate.enterprise) != 'undefined' && translate.enterprise.isUse == true){
|
|
6928
|
-
|
|
6940
|
+
translate.log('您已启用了企业级翻译通道 translate.enterprise.use(); (文档:https://translate.zvo.cn/4087.html) , 所以您设置的 translate.service.use(\''+serviceName+'\'); (文档:https://translate.zvo.cn/4081.html) 将失效不起作用,有企业级翻译通道全部接管。');
|
|
6929
6941
|
return;
|
|
6930
6942
|
}
|
|
6931
6943
|
//console.log('--'+serviceName);
|
|
@@ -7049,8 +7061,8 @@ var translate = {
|
|
|
7049
7061
|
|
|
7050
7062
|
//进行对前后进行补齐数组
|
|
7051
7063
|
if(currentIndex < 0){
|
|
7052
|
-
|
|
7053
|
-
|
|
7064
|
+
translate.log('------ERROR--------');
|
|
7065
|
+
translate.log('翻译内容过多,进行拆分,但拆分判断出现异常,currentIndex:-1 请联系 http://translate.zvo.cn/43006.html 说明');
|
|
7054
7066
|
}
|
|
7055
7067
|
//前插入空数组填充
|
|
7056
7068
|
for(var addbeforei = 0; addbeforei<currentIndex; addbeforei++){
|
|
@@ -7080,8 +7092,8 @@ var translate = {
|
|
|
7080
7092
|
|
|
7081
7093
|
|
|
7082
7094
|
}, 'get', true, {'content-type':'application/x-www-form-urlencoded'}, function(xhr){
|
|
7083
|
-
|
|
7084
|
-
|
|
7095
|
+
translate.log('---------error--------');
|
|
7096
|
+
translate.log('edge translate service error, http code : '+xhr.status + ', response text : '+xhr.responseText);
|
|
7085
7097
|
}, true);
|
|
7086
7098
|
|
|
7087
7099
|
|
|
@@ -7190,7 +7202,7 @@ var translate = {
|
|
|
7190
7202
|
{},
|
|
7191
7203
|
function(data){
|
|
7192
7204
|
if (data.result == 0){
|
|
7193
|
-
|
|
7205
|
+
translate.log('translate.js init 初始化异常:'+data.info);
|
|
7194
7206
|
return;
|
|
7195
7207
|
}else if(data.result == 1){
|
|
7196
7208
|
//服务端返回的最新版本
|
|
@@ -7199,7 +7211,7 @@ var translate = {
|
|
|
7199
7211
|
var currentVersion = translate.util.versionStringToInt(translate.version.replace('v',''));
|
|
7200
7212
|
|
|
7201
7213
|
if(newVersion > currentVersion){
|
|
7202
|
-
|
|
7214
|
+
translate.log('Tip : translate.js find new version : '+data.version);
|
|
7203
7215
|
}
|
|
7204
7216
|
}
|
|
7205
7217
|
},
|
|
@@ -7475,7 +7487,7 @@ var translate = {
|
|
|
7475
7487
|
);
|
|
7476
7488
|
}catch(e){
|
|
7477
7489
|
//console.log('e0000');
|
|
7478
|
-
|
|
7490
|
+
translate.log(e);
|
|
7479
7491
|
//time = 300000; //无法连接的,那么赋予 300 秒吧
|
|
7480
7492
|
}
|
|
7481
7493
|
|
|
@@ -7510,7 +7522,7 @@ var translate = {
|
|
|
7510
7522
|
|
|
7511
7523
|
}else{
|
|
7512
7524
|
//异常,下标越界了!,固定返回最后一个
|
|
7513
|
-
|
|
7525
|
+
translate.log('异常,下标越界了!index:'+queueIndex);
|
|
7514
7526
|
queueIndex = queue.length-1;
|
|
7515
7527
|
}
|
|
7516
7528
|
//console.log(queueIndex);
|
|
@@ -7684,7 +7696,7 @@ var translate = {
|
|
|
7684
7696
|
try{
|
|
7685
7697
|
json = JSON.parse(xhr.responseText);
|
|
7686
7698
|
}catch(e){
|
|
7687
|
-
|
|
7699
|
+
translate.log(e);
|
|
7688
7700
|
}
|
|
7689
7701
|
}
|
|
7690
7702
|
}
|
|
@@ -7703,17 +7715,17 @@ var translate = {
|
|
|
7703
7715
|
//判断是否是v2版本的翻译,如果是 translate.service 模式并且没有使用企业级翻译,参会提示
|
|
7704
7716
|
//2024.3月底开始,翻译使用量增加的太快,开源的翻译服务器有点扛不住经常出故障,所以直接把这个提示加到这里
|
|
7705
7717
|
if(translate.service.name == 'translate.service'){
|
|
7706
|
-
|
|
7718
|
+
translate.log('----- translate.js 提示 -----\n翻译服务响应异常,解决这种情况可以有两种方案:\n【方案一】:使用采用最新版本 3.16.0及更高版本,js引用文件为 https://cdn.staticfile.net/translate.js/3.16.0/translate.js 并且使用 client.edge 模式 (增加一行设置代码就好,可参考 https://translate.zvo.cn/4081.html ),这样就不会再出现这种情况了,而且这个方案也是完全免费的。 \n【方案二】:采用企业级稳定翻译通道 ,但是这个相比于 方案一 来说,是有一定的收费的,大概一年600,这个就是专门为了高速及高稳定准备的,而相比于这个方案二,方案一则是全免费的。 因为方案二我们是部署了两个集群,而每个集群又下分了数个网络节点,包含中国大陆、香港、美国、欧洲、 等多个州,充分保障稳定、高效,同样也产生了不少成本,所以才需要付费。更多信息说明可以参考: http://translate.zvo.cn/4087.html \n【方案三】:私有部署你自己的翻译通道,并且启用内存级翻译缓存,毫秒级响应,但是需要依赖一台1核2G服务器,是最推荐的方式。具体参考:https://translate.zvo.cn/391129.html\n-------------');
|
|
7707
7719
|
}
|
|
7708
7720
|
|
|
7709
7721
|
//console.log(xhr);
|
|
7710
|
-
|
|
7711
|
-
|
|
7712
|
-
|
|
7713
|
-
|
|
7714
|
-
|
|
7715
|
-
|
|
7716
|
-
|
|
7722
|
+
translate.log('------- translate.js service api response error --------');
|
|
7723
|
+
translate.log(' http code : '+xhr.status);
|
|
7724
|
+
translate.log(' response : '+xhr.response);
|
|
7725
|
+
translate.log(' request url : '+url);
|
|
7726
|
+
translate.log(' request data : '+JSON.stringify(data));
|
|
7727
|
+
translate.log(' request method : '+method);
|
|
7728
|
+
translate.log('---------------------- end ----------------------');
|
|
7717
7729
|
}
|
|
7718
7730
|
|
|
7719
7731
|
}
|
|
@@ -7776,7 +7788,7 @@ var translate = {
|
|
|
7776
7788
|
}else if(type == '[object Object]'){
|
|
7777
7789
|
//案例三
|
|
7778
7790
|
if(typeof(obj.texts) == 'undefined'){
|
|
7779
|
-
|
|
7791
|
+
translate.log('translate.request.translateText 传入的值类型异常,因为你没有传入 obj.texts 要翻译的具体文本! 请查阅文档: https://translate.zvo.cn/4077.html');
|
|
7780
7792
|
}
|
|
7781
7793
|
if(typeof(obj.texts) == 'string'){
|
|
7782
7794
|
//单个字符串
|
|
@@ -7792,7 +7804,7 @@ var translate = {
|
|
|
7792
7804
|
to = obj.to;
|
|
7793
7805
|
}
|
|
7794
7806
|
}else{
|
|
7795
|
-
|
|
7807
|
+
translate.log('translate.request.translateText 传入的值类型错误,请查阅文档: https://translate.zvo.cn/4077.html');
|
|
7796
7808
|
return;
|
|
7797
7809
|
}
|
|
7798
7810
|
}
|
|
@@ -7849,12 +7861,12 @@ var translate = {
|
|
|
7849
7861
|
//console.log(resultData);
|
|
7850
7862
|
//console.log(data);
|
|
7851
7863
|
if(resultData.result == 0){
|
|
7852
|
-
|
|
7853
|
-
|
|
7854
|
-
|
|
7855
|
-
|
|
7856
|
-
|
|
7857
|
-
|
|
7864
|
+
translate.log('=======ERROR START=======');
|
|
7865
|
+
translate.log('from : '+resultData.from);
|
|
7866
|
+
translate.log('to : '+resultData.to);
|
|
7867
|
+
translate.log('translate text array : '+texts);
|
|
7868
|
+
translate.log('response : '+resultData.info);
|
|
7869
|
+
translate.log('=======ERROR END =======');
|
|
7858
7870
|
//return;
|
|
7859
7871
|
}
|
|
7860
7872
|
|
|
@@ -7972,14 +7984,14 @@ var translate = {
|
|
|
7972
7984
|
//console.log('translate.request.listener.start ... 执行翻译 --'+currentTime);
|
|
7973
7985
|
translate.execute();
|
|
7974
7986
|
}catch(e){
|
|
7975
|
-
|
|
7987
|
+
translate.log(e);
|
|
7976
7988
|
}
|
|
7977
7989
|
}
|
|
7978
7990
|
}
|
|
7979
7991
|
}, 100);
|
|
7980
7992
|
|
|
7981
7993
|
if(typeof(PerformanceObserver) == 'undefined'){
|
|
7982
|
-
|
|
7994
|
+
translate.log('因浏览器版本较低, translate.request.listener.start() 中 PerformanceObserver 对象不存在,浏览器不支持,所以 translate.request.listener.start() 未生效。');
|
|
7983
7995
|
return;
|
|
7984
7996
|
}
|
|
7985
7997
|
|
|
@@ -8052,7 +8064,7 @@ var translate = {
|
|
|
8052
8064
|
observer.observe({ entryTypes: ["resource"] });
|
|
8053
8065
|
return;
|
|
8054
8066
|
} catch (e) {
|
|
8055
|
-
|
|
8067
|
+
translate.log("PerformanceObserver entryTypes 失败,尝试 type 参数");
|
|
8056
8068
|
}
|
|
8057
8069
|
}
|
|
8058
8070
|
}
|
|
@@ -8061,9 +8073,9 @@ var translate = {
|
|
|
8061
8073
|
// 回退到 type 参数
|
|
8062
8074
|
try {
|
|
8063
8075
|
observer.observe({ type: "resource", buffered: true });
|
|
8064
|
-
|
|
8076
|
+
translate.log("使用 PerformanceObserver type");
|
|
8065
8077
|
} catch (e) {
|
|
8066
|
-
|
|
8078
|
+
translate.log("当前浏览器不支持 PerformanceObserver 的任何参数, translate.request.listener.start() 未启动");
|
|
8067
8079
|
}
|
|
8068
8080
|
|
|
8069
8081
|
}
|
|
@@ -8342,7 +8354,7 @@ var translate = {
|
|
|
8342
8354
|
|
|
8343
8355
|
if(lastUuid == ''){
|
|
8344
8356
|
if(config.selectLanguageRefreshRender){
|
|
8345
|
-
|
|
8357
|
+
translate.log('提示,当前还未执行过翻译,所以 translate.reset(); 还原至翻译前的执行指令忽略');
|
|
8346
8358
|
}
|
|
8347
8359
|
return;
|
|
8348
8360
|
}
|
|
@@ -8467,7 +8479,7 @@ var translate = {
|
|
|
8467
8479
|
//还有需要进行通过API接口进行翻译的文本,需要调用翻译接口
|
|
8468
8480
|
if(typeof(translate.request.api.translate) != 'string' || translate.request.api.translate == null || translate.request.api.translate.length < 1){
|
|
8469
8481
|
//用户已经设置了不掉翻译接口进行翻译
|
|
8470
|
-
|
|
8482
|
+
translate.log('已设置了不使用 translate 翻译接口,翻译请求被阻止');
|
|
8471
8483
|
return;
|
|
8472
8484
|
}
|
|
8473
8485
|
|
|
@@ -8523,7 +8535,7 @@ var translate = {
|
|
|
8523
8535
|
|
|
8524
8536
|
if(translate.service.name == 'client.edge'){
|
|
8525
8537
|
translate.service.name = 'translate.service';
|
|
8526
|
-
|
|
8538
|
+
translate.log('您已启用了企业级翻译通道 translate.enterprise.use(); (文档:https://translate.zvo.cn/4087.html) , 所以您设置的 translate.service.use(\'client.edge\'); (文档:https://translate.zvo.cn/4081.html) 将失效不起作用,有企业级翻译通道全部接管。');
|
|
8527
8539
|
return;
|
|
8528
8540
|
}
|
|
8529
8541
|
},
|
|
@@ -8839,7 +8851,7 @@ var translate = {
|
|
|
8839
8851
|
try{
|
|
8840
8852
|
jsObject = eval('(' + jsString + ')');
|
|
8841
8853
|
}catch(e){
|
|
8842
|
-
|
|
8854
|
+
translate.log(e)
|
|
8843
8855
|
failureFunction(e);
|
|
8844
8856
|
return;
|
|
8845
8857
|
}
|
|
@@ -9165,8 +9177,8 @@ var translate = {
|
|
|
9165
9177
|
|
|
9166
9178
|
// 检查 URL 是否匹配
|
|
9167
9179
|
if(typeof(rule.url) == 'undefined' && rule.url == ''){
|
|
9168
|
-
|
|
9169
|
-
|
|
9180
|
+
translate.log('WARINNG : translate.network.rule find url is null:');
|
|
9181
|
+
translate.log(rule);
|
|
9170
9182
|
continue;
|
|
9171
9183
|
}
|
|
9172
9184
|
//console.log(rule);
|
|
@@ -9258,8 +9270,8 @@ var translate = {
|
|
|
9258
9270
|
//console.log(url);
|
|
9259
9271
|
//console.log(rule);
|
|
9260
9272
|
if(typeof(rule.params) == 'undefined' && typeof(rule.params.length) == 'undefined' && rule.params.length < 1){
|
|
9261
|
-
|
|
9262
|
-
|
|
9273
|
+
translate.log('WARINNG: rule not find params , rule : ');
|
|
9274
|
+
translate.log(rule);
|
|
9263
9275
|
rule.params = [];
|
|
9264
9276
|
}
|
|
9265
9277
|
|
|
@@ -9278,11 +9290,11 @@ var translate = {
|
|
|
9278
9290
|
const translateResultData = await translate.network._translateText(original);
|
|
9279
9291
|
|
|
9280
9292
|
if(typeof(translateResultData) == 'undefined'){
|
|
9281
|
-
|
|
9293
|
+
translate.log('WARINNG: translateResultData is undefined');
|
|
9282
9294
|
}else if(typeof(translateResultData.result) == 'undefined'){
|
|
9283
|
-
|
|
9295
|
+
translate.log('WARINNG: translateResultData.result is undefined');
|
|
9284
9296
|
}else if(translateResultData.result != 1){
|
|
9285
|
-
|
|
9297
|
+
translate.log('WARINNG: translateResultData.result failure : '+translateResultData.info);
|
|
9286
9298
|
}else{
|
|
9287
9299
|
params.set(paramName, decodeURIComponent(translateResultData.text[0]));
|
|
9288
9300
|
}
|
|
@@ -10074,11 +10086,11 @@ var translate = {
|
|
|
10074
10086
|
//正常,body还没加载
|
|
10075
10087
|
}else{
|
|
10076
10088
|
if(config.inHeadTip){
|
|
10077
|
-
|
|
10089
|
+
translate.log('警告: translate.visual.webPageLoadTranslateBeforeHiddenText() 要在 head 标签中触发才能达到最好的效果!');
|
|
10078
10090
|
}
|
|
10079
10091
|
}
|
|
10080
10092
|
if(translate.language.local == ''){
|
|
10081
|
-
|
|
10093
|
+
translate.log('提醒:在使用 translate.visual.webPageLoadTranslateBeforeHiddenText() 之前,请先手动设置你的本地语种,参考: http://translate.zvo.cn/4066.html 如果你不设置本地语种,则不管你是否有切换语言,网页打开后都会先短暂的不显示文字');
|
|
10082
10094
|
}
|
|
10083
10095
|
|
|
10084
10096
|
if(translate.language.local == '' || translate.language.translateLocal == true || translate.language.local != translate.language.getCurrent()){
|
|
@@ -10217,7 +10229,7 @@ var translate = {
|
|
|
10217
10229
|
start:function(){
|
|
10218
10230
|
if(translate.time.execute.isUse){
|
|
10219
10231
|
//已经启动过了,不需要再启动了
|
|
10220
|
-
|
|
10232
|
+
translate.log('translate.time.execute.start() 已经启动过了,不需要再启动了');
|
|
10221
10233
|
}
|
|
10222
10234
|
|
|
10223
10235
|
translate.time.execute.data.isUse = true;
|
|
@@ -10281,7 +10293,7 @@ var translate = {
|
|
|
10281
10293
|
translate.time.execute.data[uuid].translateTexts = translateTexts;
|
|
10282
10294
|
|
|
10283
10295
|
|
|
10284
|
-
|
|
10296
|
+
translate.log('[time][translate.execute()] '+translate.time.execute.data[uuid].allTime+'ms '+(typeof(translate.time.execute.data[uuid].translateNetworkBeforeTime) != 'undefined'? '(search&cache '+(translate.time.execute.data[uuid].translateNetworkBeforeTime - translate.time.execute.data[uuid].startTime)+'ms)':'')+ (translateTexts.length > 0 ? (' , ['+translateLanguages+'] : ('+translateTexts.length+')['+translateTexts.slice(0, 3)+(translateTexts.length > 3 ? ', ...':'')+']'):''));
|
|
10285
10297
|
});
|
|
10286
10298
|
},
|
|
10287
10299
|
|
|
@@ -10333,11 +10345,11 @@ var translate = {
|
|
|
10333
10345
|
}
|
|
10334
10346
|
} catch (e) {
|
|
10335
10347
|
// 如果获取调用栈失败,使用原始log方法
|
|
10336
|
-
|
|
10348
|
+
translate.log(e);
|
|
10337
10349
|
}
|
|
10338
10350
|
|
|
10339
10351
|
functionName = functionName.replace('Object.','translate.');
|
|
10340
|
-
|
|
10352
|
+
translate.log(functionName+'() '+usetime+' -> '+remark);
|
|
10341
10353
|
}
|
|
10342
10354
|
|
|
10343
10355
|
},
|
|
@@ -10644,8 +10656,8 @@ var translate = {
|
|
|
10644
10656
|
|
|
10645
10657
|
//进行判断,DOM是否加载完成了,如果未加载完成就触发了 translate.execute 执行,那么弹出警告提示
|
|
10646
10658
|
if(document.readyState == 'loading'){
|
|
10647
|
-
|
|
10648
|
-
|
|
10659
|
+
translate.log('WARNING : The dom triggered translate.exece() before it was fully loaded, which does not comply with usage standards. The execution of translate.exece() should be done after the DOM is loaded');
|
|
10660
|
+
translate.log('警告:DOM 在完全加载之前触发了 translate.execute() ,这不符合使用规范,容易出现异常。你应该检查一下你的代码,translate.execute() 的执行应该在DOM加载完成后');
|
|
10649
10661
|
}
|
|
10650
10662
|
|
|
10651
10663
|
|
|
@@ -10728,8 +10740,10 @@ var nodeuuid = {
|
|
|
10728
10740
|
|
|
10729
10741
|
|
|
10730
10742
|
/*js copyright-notice start*/
|
|
10731
|
-
|
|
10732
|
-
|
|
10743
|
+
//延迟触发,方便拦截自定义
|
|
10744
|
+
setTimeout(function(){
|
|
10745
|
+
translate.log('------ translate.js ------\nTwo lines of js html automatic translation, page without change, no language configuration file, no API Key, SEO friendly! Open warehouse : https://github.com/xnx3/translate \n两行js实现html全自动翻译。 无需改动页面、无语言配置文件、无API Key、对SEO友好!完全开源,代码仓库:https://gitee.com/mail_osc/translate');
|
|
10746
|
+
}, 1000);
|
|
10733
10747
|
/*js copyright-notice end*/
|
|
10734
10748
|
|
|
10735
10749
|
//初始化
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "i18n-jsautotranslate",
|
|
3
|
-
"version": "3.18.
|
|
3
|
+
"version": "3.18.63",
|
|
4
4
|
"description": "Two lines of js realize automatic html translation. No need to change the page, no language configuration file, no API key, SEO friendly!",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
],
|
|
15
15
|
"files": [
|
|
16
16
|
"index.js",
|
|
17
|
-
"ArcoDesign/**"
|
|
17
|
+
"ArcoDesign/**",
|
|
18
|
+
"vue/**"
|
|
18
19
|
],
|
|
19
20
|
"homepage": "https://github.com/xnx3/translate#readme",
|
|
20
21
|
"bugs": {
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {translateJsVueUseModel, translate} from './translateVue3TS' // 导入 translate 的 VUE3 的 ts 插件
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
|
|
5
|
+
translate.js AI 多语言切换模块的自定义配置。
|
|
6
|
+
如果不想启用,你可以通过以下方式中的任何一种进行禁用
|
|
7
|
+
1. 直接将所有配置全部注释掉
|
|
8
|
+
2. 将 /src/main.ts 中的这一行 app.use(translateJsVueUseModel) 注释掉即可。
|
|
9
|
+
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
//打印包含具体执行时间的debug日志
|
|
13
|
+
//translate.time.use = true;
|
|
14
|
+
//window.translate.time.printTime = 100;
|
|
15
|
+
|
|
16
|
+
// 针对翻译动作的性能监控 https://translate.zvo.cn/549733.html
|
|
17
|
+
translate.time.execute.start();
|
|
18
|
+
|
|
19
|
+
// 设置当前切换所支持的语言 http://translate.zvo.cn/4056.html
|
|
20
|
+
window.translate.selectLanguageTag.languages = 'chinese_simplified,english,korean,latin,french,russian';
|
|
21
|
+
|
|
22
|
+
// 设置本地语种(当前网页的语种) ,如果你网页语种很多,比如国际化论坛,哪个国家发言的都有,那这里你可以不用设置,交给 translate.js 自动去识别当前网页语种 http://translate.zvo.cn/4066.html
|
|
23
|
+
window.translate.language.setLocal('chinese_simplified');
|
|
24
|
+
|
|
25
|
+
// 本地语种也进行强制翻译 http://translate.zvo.cn/289574.html
|
|
26
|
+
//translate.language.translateLocal = true;
|
|
27
|
+
|
|
28
|
+
// 翻译时忽略指定的文字不翻译 http://translate.zvo.cn/283381.html
|
|
29
|
+
translate.ignore.text.push('ContiNew Admin');
|
|
30
|
+
|
|
31
|
+
// 网页打开时自动隐藏文字,翻译完成后显示译文 http://translate.zvo.cn/549731.html
|
|
32
|
+
// 注意,如果不启用本多语言切换能力,这个要注释掉,不然你网页的文本是会被隐藏的
|
|
33
|
+
//window.translate.visual.webPageLoadTranslateBeforeHiddenText({inHeadTip: false});
|
|
34
|
+
|
|
35
|
+
// 启用翻译中的遮罩层 http://translate.zvo.cn/407105.html
|
|
36
|
+
window.translate.progress.api.startUITip();
|
|
37
|
+
|
|
38
|
+
// 设置采用开源免费的 client.edge 无服务端翻译服务通道,无需任何注册接入即可直接使用 http://translate.zvo.cn/4081.html
|
|
39
|
+
translate.service.use('client.edge');
|
|
40
|
+
|
|
41
|
+
// 网页ajax请求触发自动翻译 http://translate.zvo.cn/4086.html
|
|
42
|
+
translate.request.listener.start();
|
|
43
|
+
|
|
44
|
+
// 开启页面元素动态监控,js改变的内容也会被翻译,参考文档: http://translate.zvo.cn/4067.html
|
|
45
|
+
translate.listener.start();
|
|
46
|
+
|
|
47
|
+
// 元素的内容整体翻译能力配置 ,提高翻译的语义 http://translate.zvo.cn/4078.html
|
|
48
|
+
translate.whole.enableAll();
|
|
49
|
+
|
|
50
|
+
//触发翻译执行,有关这个的说明可参考 http://translate.zvo.cn/547814.html
|
|
51
|
+
translate.execute();
|
|
52
|
+
|
|
53
|
+
//导出,其中translateJsVueUseModel为vue插件,translate为js函数
|
|
54
|
+
export { translateJsVueUseModel, translate };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { nextTick } from 'vue';
|
|
2
|
+
import translate from 'i18n-jsautotranslate'
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
|
|
6
|
+
因为这个文件没什么需要用户单独设置的,只是整体对vue的适配,所以这个文件后续调好了会放到 npm 上,当前因为下面DOM渲染完毕触发的问题没有精准触发,所以暂时先放到这里进行方便优化调试
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
//vue3框架的一些单独设置
|
|
12
|
+
translate.vue3 = {
|
|
13
|
+
/*
|
|
14
|
+
是否有 translate.execute() 代码的触发
|
|
15
|
+
有则是true,没有则是false
|
|
16
|
+
false则不会再dom渲染完后自动进行翻译,自然也不会显示 select 选择语言
|
|
17
|
+
*/
|
|
18
|
+
isExecute: false,
|
|
19
|
+
}
|
|
20
|
+
//如果网页上有 translate.execute() 代码的触发,那么就设置 isExecute 为 true
|
|
21
|
+
translate.lifecycle.execute.trigger.push(function(data){
|
|
22
|
+
if(data.executeTriggerNumber === 1){
|
|
23
|
+
translate.vue3.isExecute = true;
|
|
24
|
+
translate.time.log('打开页面后,第一次触发 translate.execute() - 设置 translate.vue3.isExecute = true;');
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
translate.time.log('设置vue3初始化配置 - translate.vue3');
|
|
29
|
+
|
|
30
|
+
//将 translate 参数挂载到 window 上,方便在全局调用
|
|
31
|
+
if(typeof(window.translate) === 'undefined'){
|
|
32
|
+
window.translate = translate;
|
|
33
|
+
}
|
|
34
|
+
translate.time.log('将 translate 参数挂载到 window 上,方便在全局调用');
|
|
35
|
+
|
|
36
|
+
const translateJsVueUseModel = {
|
|
37
|
+
install(app) {
|
|
38
|
+
// 直接监听应用挂载完成
|
|
39
|
+
const originalMount = app.mount;
|
|
40
|
+
app.mount = function(...args) {
|
|
41
|
+
const root = originalMount.apply(this, args);
|
|
42
|
+
// 应用挂载完成后执行
|
|
43
|
+
// 使用双重nextTick确保DOM完全稳定后再执行翻译
|
|
44
|
+
// 第一个nextTick确保初始DOM渲染完成
|
|
45
|
+
nextTick(() => {
|
|
46
|
+
// 第二个nextTick确保可能的异步更新也完成
|
|
47
|
+
nextTick(() => {
|
|
48
|
+
|
|
49
|
+
/*
|
|
50
|
+
|
|
51
|
+
这里有问题,应该是vue的DOM渲染完毕后触发,但是实际打断点测试,DOM还没有渲染完就触发了,这里还需要跟踪优化
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
if(translate.vue3.isExecute){
|
|
58
|
+
translate.time.log('组件渲染完成,触发 translate.execute();');
|
|
59
|
+
|
|
60
|
+
//对vue3的某些第三方组件进行容错处理
|
|
61
|
+
translate.faultTolerance.documentCreateTextNode.use(); //对VUE的某些组件频繁渲染dom进行容错
|
|
62
|
+
translate.time.log('对vue3的某些第三方组件进行容错处理 - translate.faultTolerance.documentCreateTextNode.use();');
|
|
63
|
+
|
|
64
|
+
console.log(translate.getDocuments());
|
|
65
|
+
translate.execute();
|
|
66
|
+
setTimeout(() => {
|
|
67
|
+
translate.execute();
|
|
68
|
+
}, 100);
|
|
69
|
+
setTimeout(() => {
|
|
70
|
+
translate.execute();
|
|
71
|
+
}, 2000);
|
|
72
|
+
}else{
|
|
73
|
+
translate.time.log('组件渲染完成,但未发现translate.execute();存在,不进行翻译');
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
return root;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
//export default translateJsVueUseModel;
|
|
83
|
+
export { translateJsVueUseModel, translate };
|