i18n-jsautotranslate 3.18.59 → 3.18.61

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 +26 -8
  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.59.20250928',
17
+ version: '3.18.61.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,15 @@ 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){
847
+ if(nomenclatureKey === nomenclatureValue){
848
+ //自定义忽略翻译的文字 ,key value 相等,便是忽略翻译的
849
+ translate.element.nodeAnalyse.set(nodeObject.node, nomenclatureKey, nomenclatureValue, nodeObject.attribute);
850
+ }else{
851
+ //自定义术语的
852
+ translate.element.nodeAnalyse.set(nodeObject.node, nomenclatureKey, nomenclatureValue, nodeObject.attribute);
853
+ }
838
854
  }
839
855
 
840
856
  return {
@@ -873,6 +889,7 @@ var translate = {
873
889
  attribute: 要替换的node的attribute名称。如果传入 null,则是直接对 nodeValue 生效
874
890
  }
875
891
 
892
+
876
893
  @returns {
877
894
  find:false, //是否命中了自定义术语,命中了,则是 true,也代表 textArray 已经不是传入的那个了,已经被处理分割过了
878
895
  texts:['你','好'], //针对传入的 textArray 参数,进行术语命中完成后,将命中术语的部分剔除掉,进行分割,所返回的新的textArray . 如果没有命中术语,那么这里是只有一个值,那便是返回传入的text
@@ -4000,6 +4017,7 @@ var translate = {
4000
4017
  //translate.ignore.text = translate.ignore.text.concat(ignoreTexts)
4001
4018
  }
4002
4019
  }
4020
+
4003
4021
  //将当前节点文本的 不翻译文本规则,重新组合到 temporaryIgnoreTextsByRegex
4004
4022
  if(temporaryIgnoreTexts.length == 0){
4005
4023
  temporaryIgnoreTexts = translate.ignore.text;
@@ -4010,7 +4028,7 @@ var translate = {
4010
4028
  translate.history.translateText.add(temporaryIgnoreTexts[ti], temporaryIgnoreTexts[ti]);
4011
4029
  }
4012
4030
  }
4013
-
4031
+
4014
4032
  /**** v3.10.2.20241206 - 增加自定义忽略翻译的文本,忽略翻译的文本不会被翻译 - 当然这样会打乱翻译之后阅读的连贯性 ****/
4015
4033
  for(var ti = 0; ti<temporaryIgnoreTexts.length; ti++){
4016
4034
  if(temporaryIgnoreTexts[ti].trim().length == 0){
@@ -7997,7 +8015,7 @@ var translate = {
7997
8015
  }
7998
8016
 
7999
8017
  if(ignoreUrl){
8000
- console.log('忽略:'+url);
8018
+ //console.log('忽略:'+url);
8001
8019
  continue;
8002
8020
  }
8003
8021
  if(translate.request.listener.trigger()){
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "i18n-jsautotranslate",
3
- "version": "3.18.59",
3
+ "version": "3.18.61",
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": {