scancscode 1.0.39 → 1.0.41

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.
@@ -175,6 +175,9 @@ class CSVUtils {
175
175
  let csvUtils = new CSVUtils(filePath);
176
176
  let rows0 = await csvUtils.parseCsv();
177
177
  let header = rows0[0];
178
+ if (header.findIndex(title => title == null || title.match(/^Column\d+$/)) >= 0) {
179
+ console.warn(`文件 ${filePath} 包含 Column 列, 请检查title是否正确: ${header}`);
180
+ }
178
181
  if (rows2.length == 0) {
179
182
  rows2.push([header[0], ...langs]);
180
183
  }
@@ -235,7 +235,7 @@ class CSharpStringExtractor {
235
235
  snippet.originalCode = valueExpression;
236
236
  snippet.originalContext = valueExpression;
237
237
  this.variableIndex = 0;
238
- if (isCaseOrDefault) {
238
+ if (isCaseOrDefault && !isTextAssignment) {
239
239
  this.processSingleArgument(snippet, valueExpression, trClass, trFormatMethod, trMethod);
240
240
  }
241
241
  else {
@@ -1788,6 +1788,13 @@ class CSharpStringExtractor {
1788
1788
  const falseBranch = falseBranchMatch[1];
1789
1789
  let processedTrueBranch = trueBranch;
1790
1790
  let processedFalseBranch = falseBranch;
1791
+ const trueBranchTrimmed = trueBranch.trim();
1792
+ if (!trueBranchTrimmed.includes(`${trClass}.${trFormatMethod}(`) && !trueBranchTrimmed.endsWith(`.${trMethod}()`)) {
1793
+ const whitespaceBefore = trueBranch.substring(0, trueBranch.search(/\S/));
1794
+ const actualPart = trueBranch.substring(trueBranch.search(/\S/));
1795
+ const whitespaceAfter = actualPart.search(/\s*$/) === 0 ? actualPart : actualPart.substring(actualPart.search(/\S/) + trueBranchTrimmed.length);
1796
+ processedTrueBranch = whitespaceBefore + trueBranchTrimmed + `.${trMethod}()` + whitespaceAfter;
1797
+ }
1791
1798
  const falseBranchTrimmed = falseBranch.trim();
1792
1799
  if (!falseBranchTrimmed.includes(`${trClass}.${trFormatMethod}(`) && !falseBranchTrimmed.endsWith(`.${trMethod}()`)) {
1793
1800
  const whitespaceBefore = falseBranch.substring(0, falseBranch.search(/\S/));
@@ -69,11 +69,14 @@ class CmdExecutor {
69
69
  await literalCollector.convert(cscodedir, configdir, outcsv, langs, trmethod, scanonly, verbose);
70
70
  console.log("convert done.");
71
71
  }
72
- static testSlimCsv() {
73
- let inCsvFile = ["E:/DATA/Projects/e-gbl-client/client/Assets/Bundles/GameConfigs/Translation/hello.csv"];
74
- let outCsvFile = "E:/DATA/Projects/e-gbl-client/client/Assets/Bundles/GameConfigs/Translation/hello-out.csv";
75
- let langs = ["zh_cn"];
76
- CSVUtils_1.CSVUtils.slimCsvWithLangs(inCsvFile, outCsvFile, langs);
72
+ static async testSlimCsv() {
73
+ let inCsvFile = [
74
+ "E:/DATA/Projects/ZhiYou/ProjectFClient/GameClient/Assets/Editor/Translation/Auto.csv",
75
+ "E:/DATA/Projects/ZhiYou/ProjectFClient/GameClient/Assets/Editor/Translation/Manual.csv",
76
+ ];
77
+ let outCsvFile = "E:/DATA/Projects/ZhiYou/ProjectFClient/GameClient/Assets/Bundles/GameConfigs/Translation/ScriptTrans.csv";
78
+ let langs = ["zh_hk"];
79
+ await CSVUtils_1.CSVUtils.slimCsvWithLangs(inCsvFile, outCsvFile, langs);
77
80
  // node bin/slimlangs.js --incsv E:/DATA/Projects/e-gbl-client/client/Assets/Bundles/GameConfigs/Translation/hello.csv --outcsv E:/DATA/Projects/e-gbl-client/client/Assets/Bundles/GameConfigs/Translation/hello-out.csv --langs zh_cn
78
81
  }
79
82
  static async runSlimCsvWithLangs() {
@@ -2561,4 +2561,127 @@ namespace FaBao
2561
2561
  ]);
2562
2562
  }
2563
2563
  });
2564
+ // 测试`m_btn_xxx.title = yyy;` 形式的赋值语句要和`xxx.text = yyy;`形式的赋值语句完全等同处理
2565
+ test('should handle m_btn_xxx.title = yyy assignments contains chinese', () => {
2566
+ const code = `
2567
+ switch (_roomData.RoomState)
2568
+ {
2569
+ case Data.Match.RoomState.IsDismiss:
2570
+ m_btn_join.title = "已解散";
2571
+ m_btn_join.enabled = false;
2572
+ grayed = true;
2573
+ break;
2574
+ case Data.Match.RoomState.Rejected:
2575
+ {
2576
+ m_btn_join.title = $"被拒绝{Kff}";
2577
+ m_btn_join.enabled = false;
2578
+ break;
2579
+ }
2580
+ case Data.Match.RoomState.OutOfDate:
2581
+ m_dd_join.text = "已到期";
2582
+ break;
2583
+ default:
2584
+ m_btn_join.title = "申请";
2585
+ m_btn_joi23n.title = $"申请{Kjf}";
2586
+ break;
2587
+ }
2588
+ `;
2589
+ const snippets = extractor.extractStrings(code);
2590
+ {
2591
+ let snippet = snippets[0];
2592
+ expect(snippet.originalCode).toBe('"已解散"');
2593
+ expect(snippet.convertedCode).toBe('"已解散".TR()');
2594
+ expect(snippet.literals).toEqual([
2595
+ '已解散'
2596
+ ]);
2597
+ }
2598
+ {
2599
+ let snippet = snippets[1];
2600
+ expect(snippet.originalCode).toBe('$"被拒绝{Kff}"');
2601
+ expect(snippet.convertedCode).toBe('Tr.Format("被拒绝{0}", Kff)');
2602
+ expect(snippet.literals).toEqual([
2603
+ '被拒绝{0}'
2604
+ ]);
2605
+ }
2606
+ {
2607
+ let snippet = snippets[2];
2608
+ expect(snippet.originalCode).toBe('"已到期"');
2609
+ expect(snippet.convertedCode).toBe('"已到期".TR()');
2610
+ expect(snippet.literals).toEqual([
2611
+ '已到期'
2612
+ ]);
2613
+ }
2614
+ {
2615
+ let snippet = snippets[3];
2616
+ expect(snippet.originalCode).toBe('"申请"');
2617
+ expect(snippet.convertedCode).toBe('"申请".TR()');
2618
+ expect(snippet.literals).toEqual([
2619
+ '申请'
2620
+ ]);
2621
+ }
2622
+ {
2623
+ let snippet = snippets[4];
2624
+ expect(snippet.originalCode).toBe('$"申请{Kjf}"');
2625
+ expect(snippet.convertedCode).toBe('Tr.Format("申请{0}", Kjf)');
2626
+ expect(snippet.literals).toEqual([
2627
+ '申请{0}'
2628
+ ]);
2629
+ }
2630
+ });
2631
+ // 测试三元表达式中的字符串表达式处理
2632
+ test('should handle thriple expression with string expression 1', () => {
2633
+ const code = `m_btn_confirm.title = isUsed ? "使用中" : "使用";`;
2634
+ const snippets = extractor.extractStrings(code);
2635
+ {
2636
+ let snippet = snippets[0];
2637
+ expect(snippet.originalCode).toBe('isUsed ? "使用中" : "使用"');
2638
+ expect(snippet.convertedCode).toBe('isUsed ? "使用中".TR() : "使用".TR()');
2639
+ expect(snippet.literals).toEqual([
2640
+ '使用中',
2641
+ '使用'
2642
+ ]);
2643
+ }
2644
+ });
2645
+ // 测试三元表达式中的字符串表达式处理
2646
+ test('should handle thriple expression with string expression 2', () => {
2647
+ const code = `wefe.text = isUsed ? "使用中" : "使用";`;
2648
+ const snippets = extractor.extractStrings(code);
2649
+ {
2650
+ let snippet = snippets[0];
2651
+ expect(snippet.originalCode).toBe('isUsed ? "使用中" : "使用"');
2652
+ expect(snippet.convertedCode).toBe('isUsed ? "使用中".TR() : "使用".TR()');
2653
+ expect(snippet.literals).toEqual([
2654
+ '使用中',
2655
+ '使用'
2656
+ ]);
2657
+ }
2658
+ });
2659
+ // 测试三元表达式中的字符串表达式处理
2660
+ test('should handle thriple expression with string expression 3', () => {
2661
+ const code = `wefetext = isUsed ? "使用中" : "使用";`;
2662
+ const snippets = extractor.extractStrings(code);
2663
+ {
2664
+ let snippet = snippets[0];
2665
+ expect(snippet.originalCode).toBe('isUsed ? "使用中" : "使用"');
2666
+ expect(snippet.convertedCode).toBe('isUsed ? "使用中" : "使用"');
2667
+ expect(snippet.literals).toEqual([
2668
+ '使用中',
2669
+ '使用'
2670
+ ]);
2671
+ }
2672
+ });
2673
+ // 测试三元表达式中的字符串表达式处理
2674
+ test('should handle thriple expression with string expression 4', () => {
2675
+ const code = `wefetext(isUsed ? "使用中" : "使用");`;
2676
+ const snippets = extractor.extractStrings(code);
2677
+ {
2678
+ let snippet = snippets[0];
2679
+ expect(snippet.originalCode).toBe('isUsed ? "使用中" : "使用"');
2680
+ expect(snippet.convertedCode).toBe('isUsed ? "使用中" : "使用"');
2681
+ expect(snippet.literals).toEqual([
2682
+ '使用中',
2683
+ '使用'
2684
+ ]);
2685
+ }
2686
+ });
2564
2687
  });
@@ -1,8 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const CmdExecutor_1 = require("../src/CmdExecutor");
3
4
  describe('TestCmdExecutor', () => {
4
5
  test("test convert", async () => {
5
6
  // await CmdExecutor.testConvert();
6
7
  expect(true).toBe(true);
7
8
  }, 50000);
9
+ test("test slim", async () => {
10
+ await CmdExecutor_1.CmdExecutor.testSlimCsv();
11
+ expect(true).toBe(true);
12
+ }, 50000);
8
13
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scancscode",
3
- "version": "1.0.39",
3
+ "version": "1.0.41",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "bin": {
package/src/CSVUtils.ts CHANGED
@@ -110,10 +110,10 @@ export class CSVUtils {
110
110
  static async updateToFile(filePath: string, literals: string[], langs: string[]) {
111
111
  let csvUtils = new CSVUtils(filePath);
112
112
  let rows0 = await csvUtils.parseCsv();
113
-
113
+
114
114
  // 优化:使用Set去重,减少重复处理
115
115
  const uniqueLiterals = [...new Set(literals)];
116
-
116
+
117
117
  let rows2 = csvUtils.merge(rows0, uniqueLiterals, langs);
118
118
  await CSVUtils.writeCsv(filePath, rows2);
119
119
  console.log(`已经更新多语言表: ${filePath} , 共有 ${rows2.length - 1} 条目`);
@@ -139,6 +139,9 @@ export class CSVUtils {
139
139
  let csvUtils = new CSVUtils(filePath);
140
140
  let rows0 = await csvUtils.parseCsv();
141
141
  let header = rows0[0];
142
+ if (header.findIndex(title => title == null || title.match(/^Column\d+$/)) >= 0) {
143
+ console.warn(`文件 ${filePath} 包含 Column 列, 请检查title是否正确: ${header}`)
144
+ }
142
145
  if (rows2.length == 0) {
143
146
  rows2.push([header[0], ...langs]);
144
147
  }
@@ -254,7 +254,7 @@ export class CSharpStringExtractor {
254
254
 
255
255
  this.variableIndex = 0;
256
256
 
257
- if (isCaseOrDefault) {
257
+ if (isCaseOrDefault && !isTextAssignment) {
258
258
  this.processSingleArgument(snippet, valueExpression, trClass, trFormatMethod, trMethod);
259
259
  } else {
260
260
  this.processStatementAndExtractValue(snippet, statement, valueExpression, trClass, trFormatMethod, trMethod);
@@ -1976,6 +1976,15 @@ private findMatchingParenthesis(str: string, openIndex: number): number {
1976
1976
  const falseBranch = falseBranchMatch[1];
1977
1977
  let processedTrueBranch = trueBranch;
1978
1978
  let processedFalseBranch = falseBranch;
1979
+
1980
+ const trueBranchTrimmed = trueBranch.trim();
1981
+ if (!trueBranchTrimmed.includes(`${trClass}.${trFormatMethod}(`) && !trueBranchTrimmed.endsWith(`.${trMethod}()`)) {
1982
+ const whitespaceBefore = trueBranch.substring(0, trueBranch.search(/\S/));
1983
+ const actualPart = trueBranch.substring(trueBranch.search(/\S/));
1984
+ const whitespaceAfter = actualPart.search(/\s*$/) === 0 ? actualPart : actualPart.substring(actualPart.search(/\S/) + trueBranchTrimmed.length);
1985
+ processedTrueBranch = whitespaceBefore + trueBranchTrimmed + `.${trMethod}()` + whitespaceAfter;
1986
+ }
1987
+
1979
1988
  const falseBranchTrimmed = falseBranch.trim();
1980
1989
  if (!falseBranchTrimmed.includes(`${trClass}.${trFormatMethod}(`) && !falseBranchTrimmed.endsWith(`.${trMethod}()`)) {
1981
1990
  const whitespaceBefore = falseBranch.substring(0, falseBranch.search(/\S/));
@@ -68,11 +68,14 @@ export class CmdExecutor {
68
68
  await literalCollector.convert(cscodedir, configdir, outcsv, langs, trmethod, scanonly, verbose)
69
69
  console.log("convert done.")
70
70
  }
71
- static testSlimCsv() {
72
- let inCsvFile = ["E:/DATA/Projects/e-gbl-client/client/Assets/Bundles/GameConfigs/Translation/hello.csv"]
73
- let outCsvFile = "E:/DATA/Projects/e-gbl-client/client/Assets/Bundles/GameConfigs/Translation/hello-out.csv"
74
- let langs = ["zh_cn"];
75
- CSVUtils.slimCsvWithLangs(inCsvFile, outCsvFile, langs);
71
+ static async testSlimCsv() {
72
+ let inCsvFile = [
73
+ "E:/DATA/Projects/ZhiYou/ProjectFClient/GameClient/Assets/Editor/Translation/Auto.csv",
74
+ "E:/DATA/Projects/ZhiYou/ProjectFClient/GameClient/Assets/Editor/Translation/Manual.csv",
75
+ ]
76
+ let outCsvFile = "E:/DATA/Projects/ZhiYou/ProjectFClient/GameClient/Assets/Bundles/GameConfigs/Translation/ScriptTrans.csv"
77
+ let langs = ["zh_hk"];
78
+ await CSVUtils.slimCsvWithLangs(inCsvFile, outCsvFile, langs);
76
79
  // node bin/slimlangs.js --incsv E:/DATA/Projects/e-gbl-client/client/Assets/Bundles/GameConfigs/Translation/hello.csv --outcsv E:/DATA/Projects/e-gbl-client/client/Assets/Bundles/GameConfigs/Translation/hello-out.csv --langs zh_cn
77
80
  }
78
81
  static async runSlimCsvWithLangs() {
@@ -2802,4 +2802,132 @@ namespace FaBao
2802
2802
  }
2803
2803
  });
2804
2804
 
2805
+ // 测试`m_btn_xxx.title = yyy;` 形式的赋值语句要和`xxx.text = yyy;`形式的赋值语句完全等同处理
2806
+ test('should handle m_btn_xxx.title = yyy assignments contains chinese', () => {
2807
+ const code = `
2808
+ switch (_roomData.RoomState)
2809
+ {
2810
+ case Data.Match.RoomState.IsDismiss:
2811
+ m_btn_join.title = "已解散";
2812
+ m_btn_join.enabled = false;
2813
+ grayed = true;
2814
+ break;
2815
+ case Data.Match.RoomState.Rejected:
2816
+ {
2817
+ m_btn_join.title = $"被拒绝{Kff}";
2818
+ m_btn_join.enabled = false;
2819
+ break;
2820
+ }
2821
+ case Data.Match.RoomState.OutOfDate:
2822
+ m_dd_join.text = "已到期";
2823
+ break;
2824
+ default:
2825
+ m_btn_join.title = "申请";
2826
+ m_btn_joi23n.title = $"申请{Kjf}";
2827
+ break;
2828
+ }
2829
+ `;
2830
+ const snippets = extractor.extractStrings(code);
2831
+ {
2832
+ let snippet = snippets[0];
2833
+ expect(snippet.originalCode).toBe('"已解散"');
2834
+ expect(snippet.convertedCode).toBe('"已解散".TR()');
2835
+ expect(snippet.literals).toEqual([
2836
+ '已解散'
2837
+ ]);
2838
+ }
2839
+ {
2840
+ let snippet = snippets[1];
2841
+ expect(snippet.originalCode).toBe('$"被拒绝{Kff}"');
2842
+ expect(snippet.convertedCode).toBe('Tr.Format("被拒绝{0}", Kff)');
2843
+ expect(snippet.literals).toEqual([
2844
+ '被拒绝{0}'
2845
+ ]);
2846
+ }
2847
+ {
2848
+ let snippet = snippets[2];
2849
+ expect(snippet.originalCode).toBe('"已到期"');
2850
+ expect(snippet.convertedCode).toBe('"已到期".TR()');
2851
+ expect(snippet.literals).toEqual([
2852
+ '已到期'
2853
+ ]);
2854
+ }
2855
+ {
2856
+ let snippet = snippets[3];
2857
+ expect(snippet.originalCode).toBe('"申请"');
2858
+ expect(snippet.convertedCode).toBe('"申请".TR()');
2859
+ expect(snippet.literals).toEqual([
2860
+ '申请'
2861
+ ]);
2862
+ }
2863
+ {
2864
+ let snippet = snippets[4];
2865
+ expect(snippet.originalCode).toBe('$"申请{Kjf}"');
2866
+ expect(snippet.convertedCode).toBe('Tr.Format("申请{0}", Kjf)');
2867
+ expect(snippet.literals).toEqual([
2868
+ '申请{0}'
2869
+ ]);
2870
+ }
2871
+ });
2872
+
2873
+ // 测试三元表达式中的字符串表达式处理
2874
+ test('should handle thriple expression with string expression 1', () => {
2875
+ const code = `m_btn_confirm.title = isUsed ? "使用中" : "使用";`;
2876
+ const snippets = extractor.extractStrings(code);
2877
+ {
2878
+ let snippet = snippets[0];
2879
+ expect(snippet.originalCode).toBe('isUsed ? "使用中" : "使用"');
2880
+ expect(snippet.convertedCode).toBe('isUsed ? "使用中".TR() : "使用".TR()');
2881
+ expect(snippet.literals).toEqual([
2882
+ '使用中',
2883
+ '使用'
2884
+ ]);
2885
+ }
2886
+ });
2887
+
2888
+ // 测试三元表达式中的字符串表达式处理
2889
+ test('should handle thriple expression with string expression 2', () => {
2890
+ const code = `wefe.text = isUsed ? "使用中" : "使用";`;
2891
+ const snippets = extractor.extractStrings(code);
2892
+ {
2893
+ let snippet = snippets[0];
2894
+ expect(snippet.originalCode).toBe('isUsed ? "使用中" : "使用"');
2895
+ expect(snippet.convertedCode).toBe('isUsed ? "使用中".TR() : "使用".TR()');
2896
+ expect(snippet.literals).toEqual([
2897
+ '使用中',
2898
+ '使用'
2899
+ ]);
2900
+ }
2901
+ });
2902
+
2903
+ // 测试三元表达式中的字符串表达式处理
2904
+ test('should handle thriple expression with string expression 3', () => {
2905
+ const code = `wefetext = isUsed ? "使用中" : "使用";`;
2906
+ const snippets = extractor.extractStrings(code);
2907
+ {
2908
+ let snippet = snippets[0];
2909
+ expect(snippet.originalCode).toBe('isUsed ? "使用中" : "使用"');
2910
+ expect(snippet.convertedCode).toBe('isUsed ? "使用中" : "使用"');
2911
+ expect(snippet.literals).toEqual([
2912
+ '使用中',
2913
+ '使用'
2914
+ ]);
2915
+ }
2916
+ });
2917
+
2918
+ // 测试三元表达式中的字符串表达式处理
2919
+ test('should handle thriple expression with string expression 4', () => {
2920
+ const code = `wefetext(isUsed ? "使用中" : "使用");`;
2921
+ const snippets = extractor.extractStrings(code);
2922
+ {
2923
+ let snippet = snippets[0];
2924
+ expect(snippet.originalCode).toBe('isUsed ? "使用中" : "使用"');
2925
+ expect(snippet.convertedCode).toBe('isUsed ? "使用中" : "使用"');
2926
+ expect(snippet.literals).toEqual([
2927
+ '使用中',
2928
+ '使用'
2929
+ ]);
2930
+ }
2931
+ });
2932
+
2805
2933
  });
@@ -5,4 +5,9 @@ describe('TestCmdExecutor', () => {
5
5
  // await CmdExecutor.testConvert();
6
6
  expect(true).toBe(true);
7
7
  }, 50000);
8
+
9
+ test("test slim", async () => {
10
+ await CmdExecutor.testSlimCsv()
11
+ expect(true).toBe(true);
12
+ }, 50000);
8
13
  });