import json import os
with open("assets/zh_CN.json", "r", encoding="utf-8") as zh_file:
zh_data = json.load(zh_file)
with open("assets/en_US.json", "r", encoding="utf-8") as en_file:
en_data = json.load(en_file)
output_folder = "md-outputs" if not os.path.exists(output_folder):
os.makedirs(output_folder)
for module_name in zh_data.keys():
# 跳过locale字段
if module_name == "locale":
continue
# 提取翻译词条
translations = []
for key in zh_data[module_name].keys():
translations.append((key, zh_data[module_name][key], en_data[module_name][key]))
# 将翻译词条整理成Markdown格式
md_lines = ["| 词条 | 中文 | 英文 |", "| --- | --- | --- |"]
for translation in translations:
md_line = f"| {translation[0]} | {translation[1]} | {translation[2]} |"
md_lines.append(md_line)
md_content = "\n".join(md_lines)
# 输出结果到对应的Markdown文件
with open(os.path.join(output_folder, f"{module_name}-output.md"), "w", encoding="utf-8") as md_file:
md_file.write(md_content)