INNER CODE UNIT · Python
cleanup
nielsfaber/scheduler-card · scripts/cleanup_translations.py:34
def cleanup(reference: dict, translation: dict) -> tuple[dict, int, int]:
"""Return *(cleaned, removed_count, added_count)*.
*cleaned* contains all keys from *reference*, ordered exactly like
*reference*. Keys missing in *translation* are added using the English
value as a fallback. *removed_count* is the number of keys discarded from
*translation*. *added_count* is the number of leaf keys added as English
fallback.
"""
cleaned: dict = {}
removed = 0
added = 0
for key, ref_value in reference.items():
if key not in translation:
# missing key – add English value as fallback
cleaned[key] = ref_value
added += count_leaf_keys(ref_value) if isinstance(ref_value, dict) else 1