Skip to content

Commit 55223dd

Browse files
committed
🌐 处理翻译问题
1 parent 288650e commit 55223dd

4 files changed

Lines changed: 43 additions & 5 deletions

File tree

scripts/crowdin-download.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import { execSync } from "child_process";
22
import { readdirSync, statSync, readFileSync, writeFileSync } from "fs";
33
import { join } from "path";
44

5+
console.log("Downloading translations from Crowdin...");
56
// 执行 crowdin download --skip-untranslated-strings
67
execSync("crowdin download --skip-untranslated-strings", { stdio: "inherit" });
78

89
// 将所有语言中的""删除
910
// 语言文件在 src/locales/*/*.json 排除zh-CN
1011
const localesPath = "./src/locales";
12+
console.log("Removing empty strings from locale files...");
1113
function removeEmptyStringsFromLocaleFiles(dir) {
1214
const files = readdirSync(dir);
1315
for (const file of files) {
@@ -17,7 +19,18 @@ function removeEmptyStringsFromLocaleFiles(dir) {
1719
} else if (file.endsWith(".json")) {
1820
const content = JSON.parse(readFileSync(filePath, "utf-8"));
1921
for (const key in content) {
20-
if (content[key] === "") {
22+
// 递归删除嵌套对象中的空字符串
23+
if (typeof content[key] === "object" && content[key] !== null) {
24+
for (const nestedKey in content[key]) {
25+
if (content[key][nestedKey] === "") {
26+
delete content[key][nestedKey];
27+
}
28+
}
29+
// 如果嵌套对象变为空对象,则删除该键
30+
if (Object.keys(content[key]).length === 0) {
31+
delete content[key];
32+
}
33+
} else if (content[key] === "") {
2134
delete content[key];
2235
}
2336
}

src/locales/ach-UG/translation.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@
350350
"start_guide_content": "crwdns8560:0crwdne8560:0",
351351
"guide_installed_scripts": "crwdns8562:0crwdne8562:0",
352352
"guide_script_list_title": "crwdns8564:0crwdne8564:0",
353-
"guide_script_list_content": "crwdns8566:0crwdne8566:0",
353+
"guide_script_list_content": "crwdns10802:0crwdne10802:0",
354354
"guide_script_list_enable_title": "crwdns8568:0crwdne8568:0",
355355
"guide_script_list_enable_content": "crwdns8570:0crwdne8570:0",
356356
"guide_script_list_apply_to_run_status_title": "crwdns8572:0crwdne8572:0",
@@ -451,5 +451,14 @@
451451
"light": "crwdns10794:0crwdne10794:0",
452452
"dark": "crwdns10796:0crwdne10796:0",
453453
"individual_edit": "crwdns10798:0crwdne10798:0",
454-
"batch_edit": "crwdns10800:0crwdne10800:0"
454+
"batch_edit": "crwdns10800:0crwdne10800:0",
455+
"script_code": "crwdns10804:0crwdne10804:0",
456+
"enter_search_value": "crwdns10806:0{{search}}crwdne10806:0",
457+
"script_run_env": {
458+
"title": "crwdns10808:0crwdne10808:0",
459+
"default": "crwdns10810:0crwdne10810:0",
460+
"all": "crwdns10812:0crwdne10812:0",
461+
"normal-tabs": "crwdns10814:0crwdne10814:0",
462+
"incognito-tabs": "crwdns10816:0crwdne10816:0"
463+
}
455464
}

src/locales/en-US/translation.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,5 +453,12 @@
453453
"individual_edit": "Individual Edit",
454454
"batch_edit": "Batch Edit",
455455
"script_code": "Script Code",
456-
"enter_search_value": "Enter {{search}} to search"
456+
"enter_search_value": "Enter {{search}} to search",
457+
"script_run_env": {
458+
"title": "Operating environment",
459+
"default": "default",
460+
"all": "All",
461+
"normal-tabs": "Normal tags",
462+
"incognito-tabs": "Incognito tags"
463+
}
457464
}

src/locales/zh-TW/translation.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,5 +451,14 @@
451451
"light": "淺色模式",
452452
"dark": "暗色模式",
453453
"individual_edit": "单独编辑",
454-
"batch_edit": "批量編輯"
454+
"batch_edit": "批量編輯",
455+
"script_code": "脚本代码",
456+
"enter_search_value": "請輸入 {{search}} 進行搜尋",
457+
"script_run_env": {
458+
"title": "運作環境",
459+
"default": "預設",
460+
"all": "所有標籤",
461+
"normal-tabs": "普通標籤",
462+
"incognito-tabs": "隱身標籤"
463+
}
455464
}

0 commit comments

Comments
 (0)