scancscode 1.0.42 → 1.0.43
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/bin/scanliterals.js +3 -3
- package/bin/slimlangs.js +3 -3
- package/bin/translatecsvfile.js +3 -3
- package/docs/CSharpStringExtractor/344/273/243/347/240/201/347/224/237/346/210/220/346/217/220/347/244/272/350/257/215.txt +72 -72
- package/jest.config.js +9 -9
- package/package.json +4 -2
- package/src/CsvAutoTranslator.ts +261 -261
- package/src/RunConvert.ts +3 -3
- package/src/RunSlimLangs.ts +3 -3
- package/src/RunTranslateCSV.ts +3 -3
- package/src/TableScanner.ts +92 -92
- package/test/Auto.csv +348 -348
- package/test/TestSpecialString.cs +24 -24
- package/tsconfig.json +109 -109
- package/test/Auto-Out.csv +0 -12833
package/src/TableScanner.ts
CHANGED
|
@@ -1,92 +1,92 @@
|
|
|
1
|
-
import * as fs from "fs";
|
|
2
|
-
import { glob } from "glob";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export class TableScanner {
|
|
6
|
-
parseTrStrFields(content: string) {
|
|
7
|
-
let m = content.match(/\/\/ NeedTranslateFields\: \[([a-zA-Z_,\s0-9]*)\]$/m);
|
|
8
|
-
if (m != null) {
|
|
9
|
-
let wordsContent = m[1];
|
|
10
|
-
let words = wordsContent.split(", ");
|
|
11
|
-
return words;
|
|
12
|
-
} else {
|
|
13
|
-
return [];
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
scanJsonWords(jsonContent: string, fields: string[], literals: string[]) {
|
|
17
|
-
try {
|
|
18
|
-
let arr = JSON.parse(jsonContent);
|
|
19
|
-
for (const jsonRow of arr) {
|
|
20
|
-
for (const key of fields) {
|
|
21
|
-
let value = jsonRow[key];
|
|
22
|
-
if (typeof (value) == "string") {
|
|
23
|
-
literals.push(value);
|
|
24
|
-
} else if (Array.isArray(value)) {
|
|
25
|
-
literals.push(...value);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
} catch (error) {
|
|
30
|
-
console.error(`解析JSON失败: ${error}`);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
async scanTableLiterals(csFullPath: string, literals: string[], verbose: boolean) {
|
|
34
|
-
// csFullPath = "E:/DATA/Projects/ZhiYou/ProjectFClient/GameClient/Assets/Bundles/GameConfigs/Main/RefinerTable-RefinerEventTable.cs";
|
|
35
|
-
let jsonFullPath = csFullPath.replace("/Main/", "/Auto/").replace(/\.cs$/, ".json");
|
|
36
|
-
try {
|
|
37
|
-
const [csExists, jsonExists] = await Promise.all([
|
|
38
|
-
fs.promises.access(csFullPath).then(() => true).catch(() => false),
|
|
39
|
-
fs.promises.access(jsonFullPath).then(() => true).catch(() => false)
|
|
40
|
-
]);
|
|
41
|
-
|
|
42
|
-
if (jsonExists && csExists) {
|
|
43
|
-
const [csContent, jsonContent] = await Promise.all([
|
|
44
|
-
fs.promises.readFile(csFullPath, "utf-8"),
|
|
45
|
-
fs.promises.readFile(jsonFullPath, "utf-8")
|
|
46
|
-
]);
|
|
47
|
-
|
|
48
|
-
let trstrFields = this.parseTrStrFields(csContent);
|
|
49
|
-
if (trstrFields.length > 0) {
|
|
50
|
-
if (verbose) {
|
|
51
|
-
console.log(`扫描表格: ${csFullPath} , 需要翻译字段: ${trstrFields}`);
|
|
52
|
-
}
|
|
53
|
-
this.scanJsonWords(jsonContent, trstrFields, literals);
|
|
54
|
-
} else {
|
|
55
|
-
if (verbose) {
|
|
56
|
-
console.log(`跳过表格: ${csFullPath}`);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
} else {
|
|
60
|
-
if (verbose) {
|
|
61
|
-
if (!csExists) {
|
|
62
|
-
console.warn(`表格 CS 文件不存在: ${jsonFullPath}`);
|
|
63
|
-
}
|
|
64
|
-
if (!jsonExists) {
|
|
65
|
-
console.warn(`表格 JSON 文件不存在: ${csFullPath}`);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
} catch (error) {
|
|
70
|
-
console.error(`处理表格文件失败: ${csFullPath}`, error);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* 扫描
|
|
75
|
-
*/
|
|
76
|
-
async scanTablesLiterals(folder: string, literals: string[], verbose: boolean) {
|
|
77
|
-
let dir = folder;
|
|
78
|
-
let files = glob.sync("*.cs", { cwd: dir });
|
|
79
|
-
|
|
80
|
-
// 限制并行处理的文件数量,避免内存占用过高
|
|
81
|
-
const batchSize = 10;
|
|
82
|
-
for (let i = 0; i < files.length; i += batchSize) {
|
|
83
|
-
const batchFiles = files.slice(i, i + batchSize).reverse();
|
|
84
|
-
const batchPromises = batchFiles.map(async (filePath) => {
|
|
85
|
-
let csFullPath = folder + filePath;
|
|
86
|
-
await this.scanTableLiterals(csFullPath, literals, verbose);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
await Promise.all(batchPromises);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import { glob } from "glob";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export class TableScanner {
|
|
6
|
+
parseTrStrFields(content: string) {
|
|
7
|
+
let m = content.match(/\/\/ NeedTranslateFields\: \[([a-zA-Z_,\s0-9]*)\]$/m);
|
|
8
|
+
if (m != null) {
|
|
9
|
+
let wordsContent = m[1];
|
|
10
|
+
let words = wordsContent.split(", ");
|
|
11
|
+
return words;
|
|
12
|
+
} else {
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
scanJsonWords(jsonContent: string, fields: string[], literals: string[]) {
|
|
17
|
+
try {
|
|
18
|
+
let arr = JSON.parse(jsonContent);
|
|
19
|
+
for (const jsonRow of arr) {
|
|
20
|
+
for (const key of fields) {
|
|
21
|
+
let value = jsonRow[key];
|
|
22
|
+
if (typeof (value) == "string") {
|
|
23
|
+
literals.push(value);
|
|
24
|
+
} else if (Array.isArray(value)) {
|
|
25
|
+
literals.push(...value);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
} catch (error) {
|
|
30
|
+
console.error(`解析JSON失败: ${error}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async scanTableLiterals(csFullPath: string, literals: string[], verbose: boolean) {
|
|
34
|
+
// csFullPath = "E:/DATA/Projects/ZhiYou/ProjectFClient/GameClient/Assets/Bundles/GameConfigs/Main/RefinerTable-RefinerEventTable.cs";
|
|
35
|
+
let jsonFullPath = csFullPath.replace("/Main/", "/Auto/").replace(/\.cs$/, ".json");
|
|
36
|
+
try {
|
|
37
|
+
const [csExists, jsonExists] = await Promise.all([
|
|
38
|
+
fs.promises.access(csFullPath).then(() => true).catch(() => false),
|
|
39
|
+
fs.promises.access(jsonFullPath).then(() => true).catch(() => false)
|
|
40
|
+
]);
|
|
41
|
+
|
|
42
|
+
if (jsonExists && csExists) {
|
|
43
|
+
const [csContent, jsonContent] = await Promise.all([
|
|
44
|
+
fs.promises.readFile(csFullPath, "utf-8"),
|
|
45
|
+
fs.promises.readFile(jsonFullPath, "utf-8")
|
|
46
|
+
]);
|
|
47
|
+
|
|
48
|
+
let trstrFields = this.parseTrStrFields(csContent);
|
|
49
|
+
if (trstrFields.length > 0) {
|
|
50
|
+
if (verbose) {
|
|
51
|
+
console.log(`扫描表格: ${csFullPath} , 需要翻译字段: ${trstrFields}`);
|
|
52
|
+
}
|
|
53
|
+
this.scanJsonWords(jsonContent, trstrFields, literals);
|
|
54
|
+
} else {
|
|
55
|
+
if (verbose) {
|
|
56
|
+
console.log(`跳过表格: ${csFullPath}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
} else {
|
|
60
|
+
if (verbose) {
|
|
61
|
+
if (!csExists) {
|
|
62
|
+
console.warn(`表格 CS 文件不存在: ${jsonFullPath}`);
|
|
63
|
+
}
|
|
64
|
+
if (!jsonExists) {
|
|
65
|
+
console.warn(`表格 JSON 文件不存在: ${csFullPath}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
} catch (error) {
|
|
70
|
+
console.error(`处理表格文件失败: ${csFullPath}`, error);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* 扫描
|
|
75
|
+
*/
|
|
76
|
+
async scanTablesLiterals(folder: string, literals: string[], verbose: boolean) {
|
|
77
|
+
let dir = folder;
|
|
78
|
+
let files = glob.sync("*.cs", { cwd: dir });
|
|
79
|
+
|
|
80
|
+
// 限制并行处理的文件数量,避免内存占用过高
|
|
81
|
+
const batchSize = 10;
|
|
82
|
+
for (let i = 0; i < files.length; i += batchSize) {
|
|
83
|
+
const batchFiles = files.slice(i, i + batchSize).reverse();
|
|
84
|
+
const batchPromises = batchFiles.map(async (filePath) => {
|
|
85
|
+
let csFullPath = folder + filePath;
|
|
86
|
+
await this.scanTableLiterals(csFullPath, literals, verbose);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
await Promise.all(batchPromises);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|