i18n-jsautotranslate 3.18.60 → 3.18.62

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.
Files changed (2) hide show
  1. package/index.js +35 -11
  2. package/package.json +1 -1
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.60.20250928',
17
+ version: '3.18.62.20250928',
18
18
  // AUTO_VERSION_END
19
19
  /*
20
20
  当前使用的版本,默认使用v2. 可使用 setUseVersion2();
@@ -771,7 +771,10 @@ var translate = {
771
771
  }
772
772
  */
773
773
  replace: function(text, nomenclatureKey, nomenclatureValue, nodeObject){
774
- if(text.trim() == nomenclatureValue.trim() || nomenclatureKey.length == 0){
774
+ /*
775
+ if(text.trim() == nomenclatureValue.trim()){
776
+
777
+
775
778
 
776
779
  //这里是自定义术语被替换后,重新扫描时扫出来的,那么直接忽略,不做任何处理。因为自定义术语的结果就是最终结果了
777
780
  return {
@@ -780,6 +783,14 @@ var translate = {
780
783
  resultText:text
781
784
  }
782
785
  }
786
+ */
787
+ if(nomenclatureKey.length == 0){ //上个版本有这个,应该不会有这个情况,但是还是保留了
788
+ return {
789
+ texts:[text],
790
+ find:false,
791
+ resultText:text
792
+ }
793
+ }
783
794
 
784
795
  //判断一下原始文本是否有出现在了这个word要翻译的字符串中
785
796
  var wordKeyIndex = text.indexOf(nomenclatureKey);
@@ -831,10 +842,23 @@ var translate = {
831
842
  }
832
843
 
833
844
 
834
- //如果是自定义术语的key等于value,则是属于指定的某些文本不进行翻译的情况,所以这里要单独判断一下,它俩不相等才会去进行替换操作,免得进行性能计算浪费
835
- if(nodeObject != null && nomenclatureKey != nomenclatureValue){
836
- //console.log(nomenclatureKey+':'+nomenclatureValue);
837
- translate.element.nodeAnalyse.set(nodeObject.node, nomenclatureKey, nomenclatureValue, nodeObject.attribute);
845
+ //如果是自定义术语的key等于value,则是属于指定的某些文本不进行翻译的情况,所以这里要单独判断一下,它俩不相等才会去进行替换操作,免得进行性能计算浪费 - 虽然这一步是不会到的,因为在这个方法的入口处就已经经过这个判定了
846
+ if(nodeObject != null && typeof(nodeObject.node) !== 'undefined' && nodeObject.node !== null){
847
+
848
+ // 记录此次node的改变是有 translate.js 导致的,避免被dom改变监听给误以为别的引起的
849
+ if(translate.node.get(nodeObject.node) != null){
850
+ translate.node.get(nodeObject.node).lastTranslateRenderTime = Date.now();
851
+ }else{
852
+ //这个如果有 translate.js 内部自主触发,肯定不会没有值的。但是如果手动再其他程序里触发,那这个是会没有值的
853
+ }
854
+
855
+ if(nomenclatureKey === nomenclatureValue){
856
+ //自定义忽略翻译的文字 ,key 跟 value 相等,便是忽略翻译的
857
+ translate.element.nodeAnalyse.set(nodeObject.node, nomenclatureKey, nomenclatureValue, nodeObject.attribute);
858
+ }else{
859
+ //自定义术语的
860
+ translate.element.nodeAnalyse.set(nodeObject.node, nomenclatureKey, nomenclatureValue, nodeObject.attribute);
861
+ }
838
862
  }
839
863
 
840
864
  return {
@@ -873,6 +897,7 @@ var translate = {
873
897
  attribute: 要替换的node的attribute名称。如果传入 null,则是直接对 nodeValue 生效
874
898
  }
875
899
 
900
+
876
901
  @returns {
877
902
  find:false, //是否命中了自定义术语,命中了,则是 true,也代表 textArray 已经不是传入的那个了,已经被处理分割过了
878
903
  texts:['你','好'], //针对传入的 textArray 参数,进行术语命中完成后,将命中术语的部分剔除掉,进行分割,所返回的新的textArray . 如果没有命中术语,那么这里是只有一个值,那便是返回传入的text
@@ -4000,6 +4025,7 @@ var translate = {
4000
4025
  //translate.ignore.text = translate.ignore.text.concat(ignoreTexts)
4001
4026
  }
4002
4027
  }
4028
+
4003
4029
  //将当前节点文本的 不翻译文本规则,重新组合到 temporaryIgnoreTextsByRegex
4004
4030
  if(temporaryIgnoreTexts.length == 0){
4005
4031
  temporaryIgnoreTexts = translate.ignore.text;
@@ -4010,7 +4036,7 @@ var translate = {
4010
4036
  translate.history.translateText.add(temporaryIgnoreTexts[ti], temporaryIgnoreTexts[ti]);
4011
4037
  }
4012
4038
  }
4013
-
4039
+
4014
4040
  /**** v3.10.2.20241206 - 增加自定义忽略翻译的文本,忽略翻译的文本不会被翻译 - 当然这样会打乱翻译之后阅读的连贯性 ****/
4015
4041
  for(var ti = 0; ti<temporaryIgnoreTexts.length; ti++){
4016
4042
  if(temporaryIgnoreTexts[ti].trim().length == 0){
@@ -4074,14 +4100,12 @@ var translate = {
4074
4100
 
4075
4101
 
4076
4102
  //记录 nodeHistory - 判断text是否已经被拆分了
4077
- //console.log(textArray);
4078
- if(textArray.length > 1 || textArray[0] != text){
4103
+ if(textArray.length > 0 && textArray[0] != text){ //主要是后面的是否相等,前面的>0只是避免代码报错
4079
4104
  translate.node.get(node)[nodeAttribute.key].whole = false; //已经被拆分了,不是整体翻译了
4080
4105
  //这时,也默认给其赋值操作,将自定义术语匹配后的结果进行赋予
4081
4106
  }else{
4082
4107
  translate.node.get(node)[nodeAttribute.key].whole = true; //未拆分,是整体翻译
4083
4108
  }
4084
-
4085
4109
  //成功加入到 nodeQueue 的对象。 如果长度为0,那就是还没有加入到 translate.nodeQueue 中,可能全被自定义术语命中了
4086
4110
  var addQueueObjectArray = [];
4087
4111
 
@@ -7997,7 +8021,7 @@ var translate = {
7997
8021
  }
7998
8022
 
7999
8023
  if(ignoreUrl){
8000
- console.log('忽略:'+url);
8024
+ //console.log('忽略:'+url);
8001
8025
  continue;
8002
8026
  }
8003
8027
  if(translate.request.listener.trigger()){
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "i18n-jsautotranslate",
3
- "version": "3.18.60",
3
+ "version": "3.18.62",
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": {