1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-24 15:28:10 +00:00
trezor-firmware/core/tools/translations/flatten_json.py
grdddj b8ea21d24a feat(all): implement translations into Trezor
Co-authored-by matejcik <ja@matejcik.cz>
2024-02-12 14:49:32 +01:00

27 lines
789 B
Python

from __future__ import annotations
import json
from helpers import ALL_LANGUAGES, TRANSLATIONS_DIR
def flatten_data(data: dict[str, dict[str, str]]) -> dict[str, str]:
items: list[tuple[str, str]] = []
for section_name, section in data.items():
for k, v in section.items():
name = f"{section_name}__{k}"
items.append((name, v))
items.sort(key=lambda x: x[0])
return dict(items)
for lang in ALL_LANGUAGES:
lang_file = TRANSLATIONS_DIR / f"{lang}.json"
lang_data = json.loads(lang_file.read_text())
translations_data = lang_data["translations"]
lang_data["translations"] = flatten_data(translations_data)
lang_file.write_text(
json.dumps(lang_data, indent=2, sort_keys=True, ensure_ascii=False) + "\n"
)