import json
import os
from pathlib import Path

GLOSSARIES_DIR = Path(os.getenv("GLOSSARIES_DIR", "data/glossaries"))
TARGET_LANGUAGES = ["de", "es", "it", "pt", "nl", "ru", "ja", "ko", "zh", "ar", "fa"]

if not GLOSSARIES_DIR.exists():
    raise SystemExit(f"Glossaries directory not found: {GLOSSARIES_DIR} (set GLOSSARIES_DIR)")

for f in GLOSSARIES_DIR.glob("*.json"):
    if f.name == "index.json":
        continue
    try:
        with open(f, "r", encoding="utf-8") as file:
            data = json.load(file)
        terms = data.get("terms", [])
        missing_count = 0
        total_count = len(terms)
        for t in terms:
            trans = t.get("translations", {})
            for lang in TARGET_LANGUAGES:
                if lang not in trans or not trans[lang]:
                    missing_count += 1
        print(f"{f.name}: {total_count} termes, {missing_count} traductions manquantes.")
    except Exception as e:
        print(f"Error {f.name}: {e}")
