mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-19 12:58:13 +00:00
feat(core/translations): cli.py merge command
This commit is contained in:
parent
c857fcdc2f
commit
ca1c5c4e33
@ -133,6 +133,7 @@ class TranslationsDir:
|
||||
data,
|
||||
indent=2,
|
||||
ensure_ascii=False,
|
||||
sort_keys=True,
|
||||
)
|
||||
+ "\n"
|
||||
)
|
||||
@ -365,5 +366,27 @@ def sign(signature_hex: str, force: bool | None, version_str: str | None) -> Non
|
||||
build_all_blobs(all_blobs, tree, sigmask, signature, production=True)
|
||||
|
||||
|
||||
def _dict_merge(a: dict, b: dict) -> None:
|
||||
for k, v in b.items():
|
||||
if k in a and isinstance(a[k], dict) and isinstance(v, dict):
|
||||
_dict_merge(a[k], v)
|
||||
else:
|
||||
a[k] = v
|
||||
|
||||
|
||||
@cli.command()
|
||||
@click.argument("update_json", type=click.File("r"), nargs=-1)
|
||||
def merge(update_json: t.Tuple[t.TextIO, ...]) -> None:
|
||||
"""Update translations from JSON files."""
|
||||
tdir = TranslationsDir()
|
||||
for f in update_json:
|
||||
new_data = json.load(f)
|
||||
lang = new_data["header"]["language"][:2]
|
||||
orig_data = tdir.load_lang(lang)
|
||||
_dict_merge(orig_data, new_data)
|
||||
tdir.save_lang(lang, orig_data)
|
||||
click.echo(f"Updated {lang}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
cli()
|
||||
|
Loading…
Reference in New Issue
Block a user