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")  # 当前目录下执行，可替换为其他路径
