scancscode 1.0.40 → 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
  }
@@ -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() {
@@ -2562,7 +2562,7 @@ namespace FaBao
2562
2562
  }
2563
2563
  });
2564
2564
  // 测试`m_btn_xxx.title = yyy;` 形式的赋值语句要和`xxx.text = yyy;`形式的赋值语句完全等同处理
2565
- test('should handle .text = assignments contains chinese', () => {
2565
+ test('should handle m_btn_xxx.title = yyy assignments contains chinese', () => {
2566
2566
  const code = `
2567
2567
  switch (_roomData.RoomState)
2568
2568
  {
@@ -2628,4 +2628,60 @@ namespace FaBao
2628
2628
  ]);
2629
2629
  }
2630
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
+ });
2631
2687
  });
@@ -3,7 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const CmdExecutor_1 = require("../src/CmdExecutor");
4
4
  describe('TestCmdExecutor', () => {
5
5
  test("test convert", async () => {
6
- await CmdExecutor_1.CmdExecutor.testConvert();
6
+ // await CmdExecutor.testConvert();
7
+ expect(true).toBe(true);
8
+ }, 50000);
9
+ test("test slim", async () => {
10
+ await CmdExecutor_1.CmdExecutor.testSlimCsv();
7
11
  expect(true).toBe(true);
8
12
  }, 50000);
9
13
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scancscode",
3
- "version": "1.0.40",
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
  }
@@ -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() {
@@ -2803,7 +2803,7 @@ namespace FaBao
2803
2803
  });
2804
2804
 
2805
2805
  // 测试`m_btn_xxx.title = yyy;` 形式的赋值语句要和`xxx.text = yyy;`形式的赋值语句完全等同处理
2806
- test('should handle .text = assignments contains chinese', () => {
2806
+ test('should handle m_btn_xxx.title = yyy assignments contains chinese', () => {
2807
2807
  const code = `
2808
2808
  switch (_roomData.RoomState)
2809
2809
  {
@@ -2870,4 +2870,64 @@ namespace FaBao
2870
2870
  }
2871
2871
  });
2872
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
+
2873
2933
  });
@@ -2,7 +2,12 @@ import { CmdExecutor } from "../src/CmdExecutor";
2
2
 
3
3
  describe('TestCmdExecutor', () => {
4
4
  test("test convert", async () => {
5
- await CmdExecutor.testConvert();
5
+ // await CmdExecutor.testConvert();
6
+ expect(true).toBe(true);
7
+ }, 50000);
8
+
9
+ test("test slim", async () => {
10
+ await CmdExecutor.testSlimCsv()
6
11
  expect(true).toBe(true);
7
12
  }, 50000);
8
13
  });