diff --git a/gamefile-backup.zip b/gamefile-backup.zip index 4b21c596e..9e00385bd 100644 Binary files a/gamefile-backup.zip and b/gamefile-backup.zip differ diff --git a/translation-script.py b/translation-script.py index 2f2c0afc6..f659c9458 100644 --- a/translation-script.py +++ b/translation-script.py @@ -1,7 +1,23 @@ -import os, shutil, json +import os, shutil, json, zhconv 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文件 def read_json_files(directory, textkeylist): translation_dict = {} # 用来存储所有的m_text值 @@ -210,7 +226,7 @@ if __name__ == "__main__": # 0327补充 "controls", ] - + os.system("cd ../psoutertale-weblate && git pull") save_translation_dict( read_json_files("text/en_US", translation_key_mtext), "strings/mtext.json", @@ -233,22 +249,27 @@ if __name__ == "__main__": "translation-tools/weblate/mtext/zh_CN.json", "strings/mtext-zh_CN.json", ) - - copy_dict = { + copy_dict_str = { "strings/dialogue.json": "translation-tools/weblate/dialogue/en.json", "strings/mtext.json": "translation-tools/weblate/mtext/en.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", + } + 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/level*": 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}") if Path(f"{backup_dir}.7z").exists(): Path(f"{backup_dir}.7z").unlink() os.system(f"7z a -mx1 {backup_dir}.zip {backup_dir}/*") shutil.rmtree(backup_dir) + import_translation( "text/en_US", "text/zh_CN", @@ -258,9 +279,10 @@ if __name__ == "__main__": ) import_translation( - "text/en_US", + "text/zh_CN", "text/zh_CN", translation_key_mtext, "translation-tools/weblate/mtext/en.json", "translation-tools/weblate/mtext/zh_CN.json", ) + convert_zh_to_tw("text/zh_CN", ".json") diff --git a/zh2tw.py b/zh2tw.py deleted file mode 100644 index 56dfaac24..000000000 --- a/zh2tw.py +++ /dev/null @@ -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)