This commit is contained in:
WS-3917 2025-04-06 19:35:28 +08:00
parent 338dce93e9
commit 2f9b955f0c
3 changed files with 28 additions and 21 deletions

Binary file not shown.

View File

@ -1,7 +1,23 @@
import os, shutil, json import os, shutil, json, zhconv
from pathlib import Path from pathlib import Path
def convert_zh_to_tw(path, format):
for root, dirs, files in os.walk(path):
for file in files:
if file.endswith(format):
input_file = os.path.join(root, file)
output_file = os.path.join(
root.replace("zh_CN", "zh_TW"), file.replace("zh_CN", "zh_TW")
)
with open(input_file, "r", encoding="utf-8") as f:
content = f.read()
content_tw = zhconv.convert(content, "zh-tw")
# 寫入檔案
with open(output_file, "w", encoding="utf-8") as f:
f.write(content_tw)
# 递归读取文件夹tmpgui中的所有JSON文件 # 递归读取文件夹tmpgui中的所有JSON文件
def read_json_files(directory, textkeylist): def read_json_files(directory, textkeylist):
translation_dict = {} # 用来存储所有的m_text值 translation_dict = {} # 用来存储所有的m_text值
@ -210,7 +226,7 @@ if __name__ == "__main__":
# 0327补充 # 0327补充
"controls", "controls",
] ]
os.system("cd ../psoutertale-weblate && git pull")
save_translation_dict( save_translation_dict(
read_json_files("text/en_US", translation_key_mtext), read_json_files("text/en_US", translation_key_mtext),
"strings/mtext.json", "strings/mtext.json",
@ -233,22 +249,27 @@ if __name__ == "__main__":
"translation-tools/weblate/mtext/zh_CN.json", "translation-tools/weblate/mtext/zh_CN.json",
"strings/mtext-zh_CN.json", "strings/mtext-zh_CN.json",
) )
copy_dict_str = {
copy_dict = {
"strings/dialogue.json": "translation-tools/weblate/dialogue/en.json", "strings/dialogue.json": "translation-tools/weblate/dialogue/en.json",
"strings/mtext.json": "translation-tools/weblate/mtext/en.json", "strings/mtext.json": "translation-tools/weblate/mtext/en.json",
"strings/dialogue-zh_CN.json": "translation-tools/weblate/dialogue/zh_CN.json", "strings/dialogue-zh_CN.json": "translation-tools/weblate/dialogue/zh_CN.json",
"strings/mtext-zh_CN.json": "translation-tools/weblate/mtext/zh_CN.json", "strings/mtext-zh_CN.json": "translation-tools/weblate/mtext/zh_CN.json",
}
for src, dst in copy_dict_str.items():
os.system(f"cp -r {src} {dst}")
copy_dict_backup = {
"translation-tools/gamedata/Managed/Assembly-CSharp.dll": f"{backup_dir}/Managed", "translation-tools/gamedata/Managed/Assembly-CSharp.dll": f"{backup_dir}/Managed",
"translation-tools/gamedata/level*": f"{backup_dir}/", "translation-tools/gamedata/level*": f"{backup_dir}/",
"translation-tools/gamedata/sharedassets*": f"{backup_dir}/", "translation-tools/gamedata/sharedassets*": f"{backup_dir}/",
} }
for src, dst in copy_dict.items(): for src, dst in copy_dict_backup.items():
os.system(f"cp -r {src} {dst}") os.system(f"cp -r {src} {dst}")
if Path(f"{backup_dir}.7z").exists(): if Path(f"{backup_dir}.7z").exists():
Path(f"{backup_dir}.7z").unlink() Path(f"{backup_dir}.7z").unlink()
os.system(f"7z a -mx1 {backup_dir}.zip {backup_dir}/*") os.system(f"7z a -mx1 {backup_dir}.zip {backup_dir}/*")
shutil.rmtree(backup_dir) shutil.rmtree(backup_dir)
import_translation( import_translation(
"text/en_US", "text/en_US",
"text/zh_CN", "text/zh_CN",
@ -258,9 +279,10 @@ if __name__ == "__main__":
) )
import_translation( import_translation(
"text/en_US", "text/zh_CN",
"text/zh_CN", "text/zh_CN",
translation_key_mtext, translation_key_mtext,
"translation-tools/weblate/mtext/en.json", "translation-tools/weblate/mtext/en.json",
"translation-tools/weblate/mtext/zh_CN.json", "translation-tools/weblate/mtext/zh_CN.json",
) )
convert_zh_to_tw("text/zh_CN", ".json")

View File

@ -1,15 +0,0 @@
import zhconv
import os
# 遍历csharp文件夹的所有.cs文件
for root, dirs, files in os.walk("text/zh_CN"):
for file in files:
if file.endswith(".json"):
input_file = os.path.join(root, file)
output_file = os.path.join(root.replace("zh_CN", "zh_TW"), file)
with open(input_file, "r", encoding="utf-8") as f:
content = f.read()
content_tw = zhconv.convert(content, "zh-tw")
# 寫入檔案
with open(output_file, "w", encoding="utf-8") as f:
f.write(content_tw)