INNER CODE UNIT · Python
load_json
blokadaorg/blokada · .github/scripts/translation_coverage.py:47
def load_json(path):
"""Load a translation file, or None if missing/unparseable (best-effort)."""
try:
with open(path, encoding="utf-8") as f:
return json.load(f)
except FileNotFoundError:
return None
except (json.JSONDecodeError, OSError) as e:
warn(f"could not read {path.name}: {e}; treating as uncovered")
return None
def coverage(en, translated):
"""(covered, total) keys: present, non-empty, and differing from English."""
total = len(en)
if translated is None or total == 0:
return 0, total
covered = 0