123
This commit is contained in:
parent
5ecf946652
commit
451c2fb38f
35
02.py
Normal file
35
02.py
Normal file
@ -0,0 +1,35 @@
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def build_translation_dict(folder):
|
||||
en_path = os.path.join(folder, "en.json")
|
||||
zh_path = os.path.join(folder, "zh_CN.json")
|
||||
out_path = os.path.join(folder, "zh_CN_new.json")
|
||||
|
||||
# 加载 JSON 文件
|
||||
with open(en_path, "r", encoding="utf-8") as f:
|
||||
en_data = json.load(f)
|
||||
|
||||
with open(zh_path, "r", encoding="utf-8") as f:
|
||||
zh_data = json.load(f)
|
||||
|
||||
result = {}
|
||||
|
||||
for key, en_value in en_data.items():
|
||||
zh_value = zh_data.get(key, "")
|
||||
if zh_value == "" or zh_value == en_value:
|
||||
result[key] = ""
|
||||
else:
|
||||
result[key] = zh_value
|
||||
|
||||
# 写入新的 zh_CN_new.json 文件
|
||||
with open(out_path, "w", encoding="utf-8") as f:
|
||||
json.dump(result, f, ensure_ascii=False, indent=4)
|
||||
|
||||
print(f"已输出文件: {out_path}")
|
||||
|
||||
|
||||
# 示例调用
|
||||
if __name__ == "__main__":
|
||||
build_translation_dict("text_original/ch2") # 当前目录下执行,可替换为其他路径
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user