i18n-jsautotranslate 3.18.62 → 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 +127 -119
- 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
|
|
|
@@ -1084,7 +1090,7 @@ var translate = {
|
|
|
1084
1090
|
*/
|
|
1085
1091
|
set: async function(hash, originalText, toLanguage, translateText){
|
|
1086
1092
|
if(typeof(translate.storage.IndexedDB) == 'undefined'){
|
|
1087
|
-
|
|
1093
|
+
translate.log('ERROR: translate.storage.IndexedDB not find');
|
|
1088
1094
|
return;
|
|
1089
1095
|
}
|
|
1090
1096
|
var obj = await translate.storage.IndexedDB.get('hash_'+hash);
|
|
@@ -1104,11 +1110,11 @@ var translate = {
|
|
|
1104
1110
|
*/
|
|
1105
1111
|
export: async function(to){
|
|
1106
1112
|
if(typeof(translate.storage.IndexedDB) == 'undefined'){
|
|
1107
|
-
|
|
1113
|
+
translate.log('ERROR: translate.storage.IndexedDB not find');
|
|
1108
1114
|
return;
|
|
1109
1115
|
}
|
|
1110
1116
|
if(typeof(to) != 'string'){
|
|
1111
|
-
|
|
1117
|
+
translate.log('error : to param not find, example: "english"');
|
|
1112
1118
|
return;
|
|
1113
1119
|
}
|
|
1114
1120
|
var text = 'translate.office.append(\'';
|
|
@@ -1514,7 +1520,7 @@ var translate = {
|
|
|
1514
1520
|
try{
|
|
1515
1521
|
translate.listener.execute.renderStartByApi[i](uuid, from, to);
|
|
1516
1522
|
}catch(e){
|
|
1517
|
-
|
|
1523
|
+
translate.log(e);
|
|
1518
1524
|
}
|
|
1519
1525
|
}
|
|
1520
1526
|
},
|
|
@@ -1533,7 +1539,7 @@ var translate = {
|
|
|
1533
1539
|
try{
|
|
1534
1540
|
translate.listener.execute.renderFinishByApi[i](uuid, from, to);
|
|
1535
1541
|
}catch(e){
|
|
1536
|
-
|
|
1542
|
+
translate.log(e);
|
|
1537
1543
|
}
|
|
1538
1544
|
}
|
|
1539
1545
|
}
|
|
@@ -1693,8 +1699,8 @@ var translate = {
|
|
|
1693
1699
|
// 记录当前有 translate.js 所触发翻译之后渲染到dom界面显示的时间,13位时间戳
|
|
1694
1700
|
translate.node.get(this.nodes[hash][task_index]).lastTranslateRenderTime = Date.now();
|
|
1695
1701
|
}else{
|
|
1696
|
-
|
|
1697
|
-
|
|
1702
|
+
translate.log('执行异常,渲染时,node未在 nodeHistory 中找到, 这个理论上是不应该存在的,当前异常已被容错。 node:'+this.nodes[hash][task_index]);
|
|
1703
|
+
translate.log(this.nodes[hash][task_index]);
|
|
1698
1704
|
}
|
|
1699
1705
|
|
|
1700
1706
|
//渲染页面进行翻译显示
|
|
@@ -1705,7 +1711,7 @@ var translate = {
|
|
|
1705
1711
|
if(translate.node.data.get(this.nodes[hash][task_index]) != null){
|
|
1706
1712
|
if(typeof(translate.node.get(this.nodes[hash][task_index])[nodeAttribute.key]) == 'undefined'){
|
|
1707
1713
|
//这里不应该的
|
|
1708
|
-
|
|
1714
|
+
translate.log('执行异常,渲染时,node 的 '+(nodeAttribute.attribute.length == 0? 'nodeValue':'attribute : '+nodeAttribute.attribute)+' 未在 nodeHistory 中找到, 这个理论上是不应该存在的,当前异常已被容错。 node:'+this.nodes[hash][task_index]);
|
|
1709
1715
|
}else{
|
|
1710
1716
|
//将具体通过文本翻译接口进行翻译的文本记录到 translate.node.data
|
|
1711
1717
|
translate.node.get(this.nodes[hash][task_index])[nodeAttribute.key].translateTexts[task.originalText] = task.resultText;
|
|
@@ -1716,8 +1722,8 @@ var translate = {
|
|
|
1716
1722
|
translate.history.translateText.add(translate.node.get(this.nodes[hash][task_index])[nodeAttribute.key].originalText ,analyseSet.resultText);
|
|
1717
1723
|
}
|
|
1718
1724
|
}else{
|
|
1719
|
-
|
|
1720
|
-
|
|
1725
|
+
translate.log('执行异常,渲染时,node未在 nodeHistory 中找到, 这个理论上是不应该存在的,当前异常已被容错。 node:'+this.nodes[hash][task_index]);
|
|
1726
|
+
translate.log(this.nodes[hash][task_index]);
|
|
1721
1727
|
}
|
|
1722
1728
|
|
|
1723
1729
|
//加入 translate.listener.ignoreNode
|
|
@@ -1824,7 +1830,7 @@ var translate = {
|
|
|
1824
1830
|
if(translate.waitingExecute.queue.length > 0){
|
|
1825
1831
|
return translate.waitingExecute.queue.shift();
|
|
1826
1832
|
}else{
|
|
1827
|
-
|
|
1833
|
+
translate.log('警告, translate.waitingExecute.get 出现异常,quque已空,但还往外取。');
|
|
1828
1834
|
return null;
|
|
1829
1835
|
}
|
|
1830
1836
|
},
|
|
@@ -1904,7 +1910,7 @@ var translate = {
|
|
|
1904
1910
|
try{
|
|
1905
1911
|
translate.lifecycle.changeLanguage[i](to);
|
|
1906
1912
|
}catch(e){
|
|
1907
|
-
|
|
1913
|
+
translate.log(e);
|
|
1908
1914
|
}
|
|
1909
1915
|
}
|
|
1910
1916
|
},
|
|
@@ -1942,7 +1948,7 @@ var translate = {
|
|
|
1942
1948
|
isNextExecute = false;
|
|
1943
1949
|
}
|
|
1944
1950
|
}catch(e){
|
|
1945
|
-
|
|
1951
|
+
translate.log(e);
|
|
1946
1952
|
}
|
|
1947
1953
|
}
|
|
1948
1954
|
return isNextExecute;
|
|
@@ -1968,13 +1974,13 @@ var translate = {
|
|
|
1968
1974
|
try{
|
|
1969
1975
|
translate.lifecycle.execute.start[i](data.uuid, data.to);
|
|
1970
1976
|
}catch(e){
|
|
1971
|
-
|
|
1977
|
+
translate.log(e);
|
|
1972
1978
|
}
|
|
1973
1979
|
}else{
|
|
1974
1980
|
try{
|
|
1975
1981
|
translate.lifecycle.execute.start[i](data);
|
|
1976
1982
|
}catch(e){
|
|
1977
|
-
|
|
1983
|
+
translate.log(e);
|
|
1978
1984
|
}
|
|
1979
1985
|
}
|
|
1980
1986
|
|
|
@@ -1990,7 +1996,7 @@ var translate = {
|
|
|
1990
1996
|
try{
|
|
1991
1997
|
translate.listener.execute.renderStartByApi[i](uuid, from, to);
|
|
1992
1998
|
}catch(e){
|
|
1993
|
-
|
|
1999
|
+
translate.log(e);
|
|
1994
2000
|
}
|
|
1995
2001
|
}
|
|
1996
2002
|
},
|
|
@@ -2041,14 +2047,14 @@ var translate = {
|
|
|
2041
2047
|
try{
|
|
2042
2048
|
translate.lifecycle.execute.translateNetworkBefore[i](data.uuid, data.from, data.to, data.texts);
|
|
2043
2049
|
}catch(e){
|
|
2044
|
-
|
|
2050
|
+
translate.log(e);
|
|
2045
2051
|
}
|
|
2046
2052
|
}else{
|
|
2047
2053
|
//2025.9.15 之后的新的
|
|
2048
2054
|
try{
|
|
2049
2055
|
translate.lifecycle.execute.translateNetworkBefore[i](data);
|
|
2050
2056
|
}catch(e){
|
|
2051
|
-
|
|
2057
|
+
translate.log(e);
|
|
2052
2058
|
}
|
|
2053
2059
|
}
|
|
2054
2060
|
|
|
@@ -2073,7 +2079,7 @@ var translate = {
|
|
|
2073
2079
|
try{
|
|
2074
2080
|
translate.lifecycle.execute.translateNetworkAfter[i](data);
|
|
2075
2081
|
}catch(e){
|
|
2076
|
-
|
|
2082
|
+
translate.log(e);
|
|
2077
2083
|
}
|
|
2078
2084
|
}
|
|
2079
2085
|
},
|
|
@@ -2097,7 +2103,7 @@ var translate = {
|
|
|
2097
2103
|
try{
|
|
2098
2104
|
translate.lifecycle.execute.renderFinish[i](uuid, to);
|
|
2099
2105
|
}catch(e){
|
|
2100
|
-
|
|
2106
|
+
translate.log(e);
|
|
2101
2107
|
}
|
|
2102
2108
|
}
|
|
2103
2109
|
},
|
|
@@ -2128,7 +2134,7 @@ var translate = {
|
|
|
2128
2134
|
try{
|
|
2129
2135
|
translate.lifecycle.execute.finally[i](data);
|
|
2130
2136
|
}catch(e){
|
|
2131
|
-
|
|
2137
|
+
translate.log(e);
|
|
2132
2138
|
}
|
|
2133
2139
|
}
|
|
2134
2140
|
},
|
|
@@ -2232,7 +2238,7 @@ var translate = {
|
|
|
2232
2238
|
}
|
|
2233
2239
|
|
|
2234
2240
|
|
|
2235
|
-
|
|
2241
|
+
translate.log('当前翻译未完结,新翻译任务已加入等待翻译队列,待上个翻译任务结束后便会执行当前翻译任务'+sliceDocString);
|
|
2236
2242
|
//console.log(docs);
|
|
2237
2243
|
translate.waitingExecute.add(docs);
|
|
2238
2244
|
|
|
@@ -2267,7 +2273,7 @@ var translate = {
|
|
|
2267
2273
|
//translate.execute_v1();
|
|
2268
2274
|
//return;
|
|
2269
2275
|
//v2.5.1增加
|
|
2270
|
-
|
|
2276
|
+
translate.log('提示:https://github.com/xnx3/translate 在 v2.5 版本之后,由于谷歌翻译调整,免费翻译通道不再支持,所以v1版本的翻译接口不再被支持,v1全线下架。考虑到v1已不能使用,当前已自动切换到v2版本。如果您使用中发现什么异常,请针对v2版本进行适配。');
|
|
2271
2277
|
translate.useVersion = 'v2';
|
|
2272
2278
|
}
|
|
2273
2279
|
|
|
@@ -2296,7 +2302,7 @@ var translate = {
|
|
|
2296
2302
|
try{
|
|
2297
2303
|
translate.selectLanguageTag.render();
|
|
2298
2304
|
}catch(e){
|
|
2299
|
-
|
|
2305
|
+
translate.log(e);
|
|
2300
2306
|
}
|
|
2301
2307
|
|
|
2302
2308
|
translate.time.log('渲染出选择语言的select窗口-已完成');
|
|
@@ -2364,8 +2370,8 @@ var translate = {
|
|
|
2364
2370
|
//console.log(all)
|
|
2365
2371
|
|
|
2366
2372
|
if(all.length > 500){
|
|
2367
|
-
|
|
2368
|
-
|
|
2373
|
+
translate.log('------tip------');
|
|
2374
|
+
translate.log('translate.execute( docs ) 传入的docs.length 过大,超过500,这很不正常,当前 docs.length : '+all.length+' ,如果你感觉真的没问题,请联系作者 http://translate.zvo.cn/43006.html 说明情况,根据你的情况进行分析。 当前只取前500个元素进行翻译');
|
|
2369
2375
|
}
|
|
2370
2376
|
|
|
2371
2377
|
//初始化 translate.element.tagAttribute ,主要针对 v3.17.10 版本的适配调整,对 translate.element.tagAttribute 的设置做了改变,做旧版本的适配
|
|
@@ -2386,7 +2392,7 @@ var translate = {
|
|
|
2386
2392
|
}
|
|
2387
2393
|
}
|
|
2388
2394
|
}catch(e){
|
|
2389
|
-
|
|
2395
|
+
translate.log(e);
|
|
2390
2396
|
}
|
|
2391
2397
|
|
|
2392
2398
|
translate.time.log('开始扫描要翻译区域的元素');
|
|
@@ -2417,8 +2423,8 @@ var translate = {
|
|
|
2417
2423
|
if(typeof(translate.nodeQueue[uuid]) == 'undefined'){
|
|
2418
2424
|
translate.nodeQueue[uuid] = new Array();
|
|
2419
2425
|
translate.nodeQueue[uuid].list = [];
|
|
2420
|
-
|
|
2421
|
-
|
|
2426
|
+
translate.log('--- translate.js warn tip 警告!! ---');
|
|
2427
|
+
translate.log('您使用translate.js时可能放的位置不对,不要吧 translate.js 放在网页最顶部,这样当 translate.js 进行执行,也就是 translate.execute() 执行时,因为网页是从上往下加载,它放在网页最顶部,那么它执行时网页后面的内容都还没加载出来,这个是不会获取到网页任何内容的,也就是它是不起任何作用的');
|
|
2422
2428
|
}
|
|
2423
2429
|
for(var lang in translate.nodeQueue[uuid].list){
|
|
2424
2430
|
if (!translate.nodeQueue[uuid].list.hasOwnProperty(lang)) {
|
|
@@ -2881,7 +2887,7 @@ var translate = {
|
|
|
2881
2887
|
//console.log(lang);
|
|
2882
2888
|
//console.log(translate.nodeQueue[uuid]['list'][lang][thhash].nodes);
|
|
2883
2889
|
if(typeof(translate.nodeQueue[uuid]['list'][lang][thhash].nodes) == 'undefined' || typeof(translate.nodeQueue[uuid]['list'][lang][thhash].nodes.length) == 'undefined'){
|
|
2884
|
-
|
|
2890
|
+
translate.log('translate.nodeQueue[\''+uuid+'\'][\'list\'][\''+lang+'\'][\''+thhash+'\'].nodes.length is null ,理论上不应该存在,进行异常报出,但不影响使用,已容错。');
|
|
2885
2891
|
continue;
|
|
2886
2892
|
}
|
|
2887
2893
|
|
|
@@ -2941,9 +2947,9 @@ var translate = {
|
|
|
2941
2947
|
}
|
|
2942
2948
|
|
|
2943
2949
|
if(typeof(translateTextArray[lang]) == 'undefined' || translateTextArray[lang].length < 1){
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2950
|
+
translate.log('异常,理论上不应该存在, lang:'+lang+', translateTextArray:');
|
|
2951
|
+
translate.log(translateTextArray);
|
|
2952
|
+
translate.log('你无需担心,这个只是个提示,它并不影响你翻译的正常进行,只是个异常提示而已,它会自动容错处理的,不会影响翻译的使用。');
|
|
2947
2953
|
|
|
2948
2954
|
translate.state = 0;
|
|
2949
2955
|
translate.executeNumber++;
|
|
@@ -3019,7 +3025,7 @@ var translate = {
|
|
|
3019
3025
|
translate.translateRequest[uuid][data.from].executeFinish = 1; //1是执行完毕
|
|
3020
3026
|
translate.translateRequest[uuid][data.from].stoptime = Math.floor(Date.now() / 1000);
|
|
3021
3027
|
}else{
|
|
3022
|
-
|
|
3028
|
+
translate.log('WARINNG!!! translate.translateRequest[uuid][data.from] is not object');
|
|
3023
3029
|
}
|
|
3024
3030
|
|
|
3025
3031
|
//为了兼容 v3.14以前的translate.service 版本,做了判断
|
|
@@ -3036,17 +3042,17 @@ var translate = {
|
|
|
3036
3042
|
translate.waitingExecute.isAllExecuteFinish(uuid, from, to, 0, data.info);
|
|
3037
3043
|
|
|
3038
3044
|
|
|
3039
|
-
|
|
3040
|
-
|
|
3045
|
+
translate.log('=======ERROR START=======');
|
|
3046
|
+
translate.log(translateTextArray[data.from]);
|
|
3041
3047
|
//console.log(encodeURIComponent(JSON.stringify(translateTextArray[data.from])));
|
|
3042
|
-
|
|
3043
|
-
|
|
3048
|
+
translate.log('response : '+data.info);
|
|
3049
|
+
translate.log('=======ERROR END =======');
|
|
3044
3050
|
//translate.temp_executeFinishNumber++; //记录执行完的次数
|
|
3045
3051
|
return;
|
|
3046
3052
|
}
|
|
3047
3053
|
|
|
3048
3054
|
if(typeof(translate.nodeQueue[uuid]) == 'undefined'){
|
|
3049
|
-
|
|
3055
|
+
translate.log('提示:你很可能多次引入了 translate.js 所以造成了翻译本身的数据错乱,这只是个提示,它还是会给你正常翻译的,但是你最好不要重复引入太多次 translate.js ,正常情况下只需要引入一次 translate.js 就可以了。太多的话很可能会导致你页面卡顿');
|
|
3050
3056
|
return;
|
|
3051
3057
|
}
|
|
3052
3058
|
|
|
@@ -3086,8 +3092,8 @@ var translate = {
|
|
|
3086
3092
|
originalWord = translate.nodeQueue[uuid]['list'][lang][hash]['original'];
|
|
3087
3093
|
//console.log('bef:'+translate.nodeQueue[uuid]['list'][lang][hash]['beforeText']);
|
|
3088
3094
|
}catch(e){
|
|
3089
|
-
|
|
3090
|
-
|
|
3095
|
+
translate.log('uuid:'+uuid+', originalWord:'+originalWord+', lang:'+lang+', hash:'+hash+', text:'+text+', queue:'+translate.nodeQueue[uuid]);
|
|
3096
|
+
translate.log(e);
|
|
3091
3097
|
continue;
|
|
3092
3098
|
}
|
|
3093
3099
|
|
|
@@ -3661,8 +3667,8 @@ var translate = {
|
|
|
3661
3667
|
if(typeof(node.tagName) == 'string' && node.tagName.length > 0){
|
|
3662
3668
|
return node.tagName;
|
|
3663
3669
|
}else{
|
|
3664
|
-
|
|
3665
|
-
|
|
3670
|
+
translate.log('warn : get nodeName is null, this node ignore translate. node : ');
|
|
3671
|
+
translate.log(node);
|
|
3666
3672
|
return '';
|
|
3667
3673
|
}
|
|
3668
3674
|
}
|
|
@@ -4422,11 +4428,11 @@ var translate = {
|
|
|
4422
4428
|
if(translate.whole.class.length == 0 && translate.whole.tag.length == 0 && translate.whole.id.length == 0){
|
|
4423
4429
|
|
|
4424
4430
|
}else{
|
|
4425
|
-
|
|
4431
|
+
translate.log('您开启了 translate.whole 此次行为避开了浏览器端的文本语种自动识别,而是暴力的直接对某个元素的整个文本进行翻译,很可能会产生非常大的翻译量,请谨慎!有关每日翻译字符的说明,可参考: http://translate.zvo.cn/42557.html ');
|
|
4426
4432
|
}
|
|
4427
4433
|
|
|
4428
4434
|
if(translate.whole.tag.indexOf('html') > -1){
|
|
4429
|
-
|
|
4435
|
+
translate.log('自检发现您设置了 translate.whole.tag 其中有 html ,这个是不生效的,最大只允许设置到 body ');
|
|
4430
4436
|
}
|
|
4431
4437
|
},
|
|
4432
4438
|
|
|
@@ -4690,10 +4696,10 @@ var translate = {
|
|
|
4690
4696
|
clearCacheLanguage:function(){
|
|
4691
4697
|
if(typeof(translate.language.setUrlParamControl_use) != 'undefined'){
|
|
4692
4698
|
if(translate.language.setUrlParamControl_use){
|
|
4693
|
-
|
|
4694
|
-
|
|
4695
|
-
|
|
4696
|
-
|
|
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传参的语种不起任何作用。')
|
|
4697
4703
|
}
|
|
4698
4704
|
}
|
|
4699
4705
|
translate.to = '';
|
|
@@ -4995,7 +5001,7 @@ var translate = {
|
|
|
4995
5001
|
|
|
4996
5002
|
var romanceSentenceLanguage = translate.language.romanceSentenceAnaly(str);
|
|
4997
5003
|
if(romanceSentenceLanguage.length == 0){
|
|
4998
|
-
|
|
5004
|
+
translate.log('语种识别异常,应该是 法语、西班牙语、葡萄牙语、意大利语 中的一种才是,除非是除了这四种语种之外的别的 罗曼语族 中的语种,当前已将 '+ str +'识别为英语。 你可以联系我们求助 https://translate.zvo.cn/4030.html');
|
|
4999
5005
|
}else{
|
|
5000
5006
|
data.languageName = romanceSentenceLanguage;
|
|
5001
5007
|
}
|
|
@@ -5858,9 +5864,9 @@ var translate = {
|
|
|
5858
5864
|
translate.request.post(translate.request.api.ip, {}, function(data){
|
|
5859
5865
|
//console.log(data);
|
|
5860
5866
|
if(data.result == 0){
|
|
5861
|
-
|
|
5862
|
-
|
|
5863
|
-
|
|
5867
|
+
translate.log('==== ERROR 获取当前用户所在区域异常 ====');
|
|
5868
|
+
translate.log(data.info);
|
|
5869
|
+
translate.log('==== ERROR END ====');
|
|
5864
5870
|
}else{
|
|
5865
5871
|
translate.storage.set('to',data.language); //设置目标翻译语言
|
|
5866
5872
|
translate.to = data.language; //设置目标语言
|
|
@@ -6095,7 +6101,7 @@ var translate = {
|
|
|
6095
6101
|
let replaceResult = translate.util.replaceFromIndex(text, replaceIndex, replaceOriginalText, replaceResultText);
|
|
6096
6102
|
|
|
6097
6103
|
if(replaceResult.replaceEndIndex < 1){
|
|
6098
|
-
|
|
6104
|
+
translate.log('translate.util.findParticiple 中已经发现了,但是实际没有替换,出现异常了!理论上这是不应该出现的。 text:'+text+' , index:'+indexArray[i]+', translateOriginal:'+translateOriginal);
|
|
6099
6105
|
}else{
|
|
6100
6106
|
text = replaceResult.text;
|
|
6101
6107
|
}
|
|
@@ -6772,7 +6778,7 @@ var translate = {
|
|
|
6772
6778
|
var tLang = translate.util.browserLanguage[language];
|
|
6773
6779
|
if(typeof(tLang) == 'undefined'){
|
|
6774
6780
|
//没有在里面
|
|
6775
|
-
|
|
6781
|
+
translate.log('browser default language : '+language +', translate.js current translate channel not support this language ');
|
|
6776
6782
|
}else{
|
|
6777
6783
|
return tLang;
|
|
6778
6784
|
}
|
|
@@ -6931,7 +6937,7 @@ var translate = {
|
|
|
6931
6937
|
*/
|
|
6932
6938
|
use: function(serviceName){
|
|
6933
6939
|
if(typeof(translate.enterprise) != 'undefined' && translate.enterprise.isUse == true){
|
|
6934
|
-
|
|
6940
|
+
translate.log('您已启用了企业级翻译通道 translate.enterprise.use(); (文档:https://translate.zvo.cn/4087.html) , 所以您设置的 translate.service.use(\''+serviceName+'\'); (文档:https://translate.zvo.cn/4081.html) 将失效不起作用,有企业级翻译通道全部接管。');
|
|
6935
6941
|
return;
|
|
6936
6942
|
}
|
|
6937
6943
|
//console.log('--'+serviceName);
|
|
@@ -7055,8 +7061,8 @@ var translate = {
|
|
|
7055
7061
|
|
|
7056
7062
|
//进行对前后进行补齐数组
|
|
7057
7063
|
if(currentIndex < 0){
|
|
7058
|
-
|
|
7059
|
-
|
|
7064
|
+
translate.log('------ERROR--------');
|
|
7065
|
+
translate.log('翻译内容过多,进行拆分,但拆分判断出现异常,currentIndex:-1 请联系 http://translate.zvo.cn/43006.html 说明');
|
|
7060
7066
|
}
|
|
7061
7067
|
//前插入空数组填充
|
|
7062
7068
|
for(var addbeforei = 0; addbeforei<currentIndex; addbeforei++){
|
|
@@ -7086,8 +7092,8 @@ var translate = {
|
|
|
7086
7092
|
|
|
7087
7093
|
|
|
7088
7094
|
}, 'get', true, {'content-type':'application/x-www-form-urlencoded'}, function(xhr){
|
|
7089
|
-
|
|
7090
|
-
|
|
7095
|
+
translate.log('---------error--------');
|
|
7096
|
+
translate.log('edge translate service error, http code : '+xhr.status + ', response text : '+xhr.responseText);
|
|
7091
7097
|
}, true);
|
|
7092
7098
|
|
|
7093
7099
|
|
|
@@ -7196,7 +7202,7 @@ var translate = {
|
|
|
7196
7202
|
{},
|
|
7197
7203
|
function(data){
|
|
7198
7204
|
if (data.result == 0){
|
|
7199
|
-
|
|
7205
|
+
translate.log('translate.js init 初始化异常:'+data.info);
|
|
7200
7206
|
return;
|
|
7201
7207
|
}else if(data.result == 1){
|
|
7202
7208
|
//服务端返回的最新版本
|
|
@@ -7205,7 +7211,7 @@ var translate = {
|
|
|
7205
7211
|
var currentVersion = translate.util.versionStringToInt(translate.version.replace('v',''));
|
|
7206
7212
|
|
|
7207
7213
|
if(newVersion > currentVersion){
|
|
7208
|
-
|
|
7214
|
+
translate.log('Tip : translate.js find new version : '+data.version);
|
|
7209
7215
|
}
|
|
7210
7216
|
}
|
|
7211
7217
|
},
|
|
@@ -7481,7 +7487,7 @@ var translate = {
|
|
|
7481
7487
|
);
|
|
7482
7488
|
}catch(e){
|
|
7483
7489
|
//console.log('e0000');
|
|
7484
|
-
|
|
7490
|
+
translate.log(e);
|
|
7485
7491
|
//time = 300000; //无法连接的,那么赋予 300 秒吧
|
|
7486
7492
|
}
|
|
7487
7493
|
|
|
@@ -7516,7 +7522,7 @@ var translate = {
|
|
|
7516
7522
|
|
|
7517
7523
|
}else{
|
|
7518
7524
|
//异常,下标越界了!,固定返回最后一个
|
|
7519
|
-
|
|
7525
|
+
translate.log('异常,下标越界了!index:'+queueIndex);
|
|
7520
7526
|
queueIndex = queue.length-1;
|
|
7521
7527
|
}
|
|
7522
7528
|
//console.log(queueIndex);
|
|
@@ -7690,7 +7696,7 @@ var translate = {
|
|
|
7690
7696
|
try{
|
|
7691
7697
|
json = JSON.parse(xhr.responseText);
|
|
7692
7698
|
}catch(e){
|
|
7693
|
-
|
|
7699
|
+
translate.log(e);
|
|
7694
7700
|
}
|
|
7695
7701
|
}
|
|
7696
7702
|
}
|
|
@@ -7709,17 +7715,17 @@ var translate = {
|
|
|
7709
7715
|
//判断是否是v2版本的翻译,如果是 translate.service 模式并且没有使用企业级翻译,参会提示
|
|
7710
7716
|
//2024.3月底开始,翻译使用量增加的太快,开源的翻译服务器有点扛不住经常出故障,所以直接把这个提示加到这里
|
|
7711
7717
|
if(translate.service.name == 'translate.service'){
|
|
7712
|
-
|
|
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-------------');
|
|
7713
7719
|
}
|
|
7714
7720
|
|
|
7715
7721
|
//console.log(xhr);
|
|
7716
|
-
|
|
7717
|
-
|
|
7718
|
-
|
|
7719
|
-
|
|
7720
|
-
|
|
7721
|
-
|
|
7722
|
-
|
|
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 ----------------------');
|
|
7723
7729
|
}
|
|
7724
7730
|
|
|
7725
7731
|
}
|
|
@@ -7782,7 +7788,7 @@ var translate = {
|
|
|
7782
7788
|
}else if(type == '[object Object]'){
|
|
7783
7789
|
//案例三
|
|
7784
7790
|
if(typeof(obj.texts) == 'undefined'){
|
|
7785
|
-
|
|
7791
|
+
translate.log('translate.request.translateText 传入的值类型异常,因为你没有传入 obj.texts 要翻译的具体文本! 请查阅文档: https://translate.zvo.cn/4077.html');
|
|
7786
7792
|
}
|
|
7787
7793
|
if(typeof(obj.texts) == 'string'){
|
|
7788
7794
|
//单个字符串
|
|
@@ -7798,7 +7804,7 @@ var translate = {
|
|
|
7798
7804
|
to = obj.to;
|
|
7799
7805
|
}
|
|
7800
7806
|
}else{
|
|
7801
|
-
|
|
7807
|
+
translate.log('translate.request.translateText 传入的值类型错误,请查阅文档: https://translate.zvo.cn/4077.html');
|
|
7802
7808
|
return;
|
|
7803
7809
|
}
|
|
7804
7810
|
}
|
|
@@ -7855,12 +7861,12 @@ var translate = {
|
|
|
7855
7861
|
//console.log(resultData);
|
|
7856
7862
|
//console.log(data);
|
|
7857
7863
|
if(resultData.result == 0){
|
|
7858
|
-
|
|
7859
|
-
|
|
7860
|
-
|
|
7861
|
-
|
|
7862
|
-
|
|
7863
|
-
|
|
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 =======');
|
|
7864
7870
|
//return;
|
|
7865
7871
|
}
|
|
7866
7872
|
|
|
@@ -7978,14 +7984,14 @@ var translate = {
|
|
|
7978
7984
|
//console.log('translate.request.listener.start ... 执行翻译 --'+currentTime);
|
|
7979
7985
|
translate.execute();
|
|
7980
7986
|
}catch(e){
|
|
7981
|
-
|
|
7987
|
+
translate.log(e);
|
|
7982
7988
|
}
|
|
7983
7989
|
}
|
|
7984
7990
|
}
|
|
7985
7991
|
}, 100);
|
|
7986
7992
|
|
|
7987
7993
|
if(typeof(PerformanceObserver) == 'undefined'){
|
|
7988
|
-
|
|
7994
|
+
translate.log('因浏览器版本较低, translate.request.listener.start() 中 PerformanceObserver 对象不存在,浏览器不支持,所以 translate.request.listener.start() 未生效。');
|
|
7989
7995
|
return;
|
|
7990
7996
|
}
|
|
7991
7997
|
|
|
@@ -8058,7 +8064,7 @@ var translate = {
|
|
|
8058
8064
|
observer.observe({ entryTypes: ["resource"] });
|
|
8059
8065
|
return;
|
|
8060
8066
|
} catch (e) {
|
|
8061
|
-
|
|
8067
|
+
translate.log("PerformanceObserver entryTypes 失败,尝试 type 参数");
|
|
8062
8068
|
}
|
|
8063
8069
|
}
|
|
8064
8070
|
}
|
|
@@ -8067,9 +8073,9 @@ var translate = {
|
|
|
8067
8073
|
// 回退到 type 参数
|
|
8068
8074
|
try {
|
|
8069
8075
|
observer.observe({ type: "resource", buffered: true });
|
|
8070
|
-
|
|
8076
|
+
translate.log("使用 PerformanceObserver type");
|
|
8071
8077
|
} catch (e) {
|
|
8072
|
-
|
|
8078
|
+
translate.log("当前浏览器不支持 PerformanceObserver 的任何参数, translate.request.listener.start() 未启动");
|
|
8073
8079
|
}
|
|
8074
8080
|
|
|
8075
8081
|
}
|
|
@@ -8348,7 +8354,7 @@ var translate = {
|
|
|
8348
8354
|
|
|
8349
8355
|
if(lastUuid == ''){
|
|
8350
8356
|
if(config.selectLanguageRefreshRender){
|
|
8351
|
-
|
|
8357
|
+
translate.log('提示,当前还未执行过翻译,所以 translate.reset(); 还原至翻译前的执行指令忽略');
|
|
8352
8358
|
}
|
|
8353
8359
|
return;
|
|
8354
8360
|
}
|
|
@@ -8473,7 +8479,7 @@ var translate = {
|
|
|
8473
8479
|
//还有需要进行通过API接口进行翻译的文本,需要调用翻译接口
|
|
8474
8480
|
if(typeof(translate.request.api.translate) != 'string' || translate.request.api.translate == null || translate.request.api.translate.length < 1){
|
|
8475
8481
|
//用户已经设置了不掉翻译接口进行翻译
|
|
8476
|
-
|
|
8482
|
+
translate.log('已设置了不使用 translate 翻译接口,翻译请求被阻止');
|
|
8477
8483
|
return;
|
|
8478
8484
|
}
|
|
8479
8485
|
|
|
@@ -8529,7 +8535,7 @@ var translate = {
|
|
|
8529
8535
|
|
|
8530
8536
|
if(translate.service.name == 'client.edge'){
|
|
8531
8537
|
translate.service.name = 'translate.service';
|
|
8532
|
-
|
|
8538
|
+
translate.log('您已启用了企业级翻译通道 translate.enterprise.use(); (文档:https://translate.zvo.cn/4087.html) , 所以您设置的 translate.service.use(\'client.edge\'); (文档:https://translate.zvo.cn/4081.html) 将失效不起作用,有企业级翻译通道全部接管。');
|
|
8533
8539
|
return;
|
|
8534
8540
|
}
|
|
8535
8541
|
},
|
|
@@ -8845,7 +8851,7 @@ var translate = {
|
|
|
8845
8851
|
try{
|
|
8846
8852
|
jsObject = eval('(' + jsString + ')');
|
|
8847
8853
|
}catch(e){
|
|
8848
|
-
|
|
8854
|
+
translate.log(e)
|
|
8849
8855
|
failureFunction(e);
|
|
8850
8856
|
return;
|
|
8851
8857
|
}
|
|
@@ -9171,8 +9177,8 @@ var translate = {
|
|
|
9171
9177
|
|
|
9172
9178
|
// 检查 URL 是否匹配
|
|
9173
9179
|
if(typeof(rule.url) == 'undefined' && rule.url == ''){
|
|
9174
|
-
|
|
9175
|
-
|
|
9180
|
+
translate.log('WARINNG : translate.network.rule find url is null:');
|
|
9181
|
+
translate.log(rule);
|
|
9176
9182
|
continue;
|
|
9177
9183
|
}
|
|
9178
9184
|
//console.log(rule);
|
|
@@ -9264,8 +9270,8 @@ var translate = {
|
|
|
9264
9270
|
//console.log(url);
|
|
9265
9271
|
//console.log(rule);
|
|
9266
9272
|
if(typeof(rule.params) == 'undefined' && typeof(rule.params.length) == 'undefined' && rule.params.length < 1){
|
|
9267
|
-
|
|
9268
|
-
|
|
9273
|
+
translate.log('WARINNG: rule not find params , rule : ');
|
|
9274
|
+
translate.log(rule);
|
|
9269
9275
|
rule.params = [];
|
|
9270
9276
|
}
|
|
9271
9277
|
|
|
@@ -9284,11 +9290,11 @@ var translate = {
|
|
|
9284
9290
|
const translateResultData = await translate.network._translateText(original);
|
|
9285
9291
|
|
|
9286
9292
|
if(typeof(translateResultData) == 'undefined'){
|
|
9287
|
-
|
|
9293
|
+
translate.log('WARINNG: translateResultData is undefined');
|
|
9288
9294
|
}else if(typeof(translateResultData.result) == 'undefined'){
|
|
9289
|
-
|
|
9295
|
+
translate.log('WARINNG: translateResultData.result is undefined');
|
|
9290
9296
|
}else if(translateResultData.result != 1){
|
|
9291
|
-
|
|
9297
|
+
translate.log('WARINNG: translateResultData.result failure : '+translateResultData.info);
|
|
9292
9298
|
}else{
|
|
9293
9299
|
params.set(paramName, decodeURIComponent(translateResultData.text[0]));
|
|
9294
9300
|
}
|
|
@@ -10080,11 +10086,11 @@ var translate = {
|
|
|
10080
10086
|
//正常,body还没加载
|
|
10081
10087
|
}else{
|
|
10082
10088
|
if(config.inHeadTip){
|
|
10083
|
-
|
|
10089
|
+
translate.log('警告: translate.visual.webPageLoadTranslateBeforeHiddenText() 要在 head 标签中触发才能达到最好的效果!');
|
|
10084
10090
|
}
|
|
10085
10091
|
}
|
|
10086
10092
|
if(translate.language.local == ''){
|
|
10087
|
-
|
|
10093
|
+
translate.log('提醒:在使用 translate.visual.webPageLoadTranslateBeforeHiddenText() 之前,请先手动设置你的本地语种,参考: http://translate.zvo.cn/4066.html 如果你不设置本地语种,则不管你是否有切换语言,网页打开后都会先短暂的不显示文字');
|
|
10088
10094
|
}
|
|
10089
10095
|
|
|
10090
10096
|
if(translate.language.local == '' || translate.language.translateLocal == true || translate.language.local != translate.language.getCurrent()){
|
|
@@ -10223,7 +10229,7 @@ var translate = {
|
|
|
10223
10229
|
start:function(){
|
|
10224
10230
|
if(translate.time.execute.isUse){
|
|
10225
10231
|
//已经启动过了,不需要再启动了
|
|
10226
|
-
|
|
10232
|
+
translate.log('translate.time.execute.start() 已经启动过了,不需要再启动了');
|
|
10227
10233
|
}
|
|
10228
10234
|
|
|
10229
10235
|
translate.time.execute.data.isUse = true;
|
|
@@ -10287,7 +10293,7 @@ var translate = {
|
|
|
10287
10293
|
translate.time.execute.data[uuid].translateTexts = translateTexts;
|
|
10288
10294
|
|
|
10289
10295
|
|
|
10290
|
-
|
|
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 ? ', ...':'')+']'):''));
|
|
10291
10297
|
});
|
|
10292
10298
|
},
|
|
10293
10299
|
|
|
@@ -10339,11 +10345,11 @@ var translate = {
|
|
|
10339
10345
|
}
|
|
10340
10346
|
} catch (e) {
|
|
10341
10347
|
// 如果获取调用栈失败,使用原始log方法
|
|
10342
|
-
|
|
10348
|
+
translate.log(e);
|
|
10343
10349
|
}
|
|
10344
10350
|
|
|
10345
10351
|
functionName = functionName.replace('Object.','translate.');
|
|
10346
|
-
|
|
10352
|
+
translate.log(functionName+'() '+usetime+' -> '+remark);
|
|
10347
10353
|
}
|
|
10348
10354
|
|
|
10349
10355
|
},
|
|
@@ -10650,8 +10656,8 @@ var translate = {
|
|
|
10650
10656
|
|
|
10651
10657
|
//进行判断,DOM是否加载完成了,如果未加载完成就触发了 translate.execute 执行,那么弹出警告提示
|
|
10652
10658
|
if(document.readyState == 'loading'){
|
|
10653
|
-
|
|
10654
|
-
|
|
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加载完成后');
|
|
10655
10661
|
}
|
|
10656
10662
|
|
|
10657
10663
|
|
|
@@ -10734,8 +10740,10 @@ var nodeuuid = {
|
|
|
10734
10740
|
|
|
10735
10741
|
|
|
10736
10742
|
/*js copyright-notice start*/
|
|
10737
|
-
|
|
10738
|
-
|
|
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);
|
|
10739
10747
|
/*js copyright-notice end*/
|
|
10740
10748
|
|
|
10741
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 };
|