INNER CODE UNIT · Python
build
smithyhq/sqladmin · scripts/seed_translations.py:43
def build(mappings_path: str, output_root: str = OUTPUT_ROOT) -> None:
"""Write ``.po``/``.mo`` catalogs (and the ``.pot`` template) from a mapping.
Args:
mappings_path: Path to the JSON file of ``{locale: {source: translation}}``.
output_root: Directory the ``gettext`` tree is written to.
"""
with open(mappings_path, encoding="utf-8") as file:
mappings: dict[str, dict[str, str]] = json.load(file)
# The full source-string set is the union of every locale's keys, so a
# partially translated locale still lists all messages.
messages = sorted({message for entries in mappings.values() for message in entries})
os.makedirs(output_root, exist_ok=True)
template = Catalog(project="SQLAdmin", domain=DOMAIN)
for message in messages:
template.add(message, string="")