From 193cdb76eb8fc81bb672339932227c20086d35f5 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Mon, 13 Jan 2025 12:18:27 +0200 Subject: [PATCH] feat(python): support per-layout translations Tested by modifying a single translation entry. --- core/translations/cs.json | 2 +- core/translations/signatures.json | 6 +++--- python/src/trezorlib/_internal/translations.py | 12 +++++++++++- python/src/trezorlib/debuglink.py | 2 ++ 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/core/translations/cs.json b/core/translations/cs.json index 28df4065ce..1dba286cad 100644 --- a/core/translations/cs.json +++ b/core/translations/cs.json @@ -421,7 +421,7 @@ "homescreen__title_no_usb_connection": "Žádné připojení usb", "homescreen__title_pin_not_set": "Není nastaven PIN", "homescreen__title_seedless": "Bez seedu", - "homescreen__title_set": "Změnit domov. obr.?", + "homescreen__title_set": {"Bolt": "Změnit domov. obr.?", "Samson": "Změnit domov. obr.?", "Quicksilver": "Změnit domovskou obrazovku?"}, "inputs__back": "ZPĚT", "inputs__cancel": "ZRUŠIT", "inputs__delete": "ODSTRANIT", diff --git a/core/translations/signatures.json b/core/translations/signatures.json index cdb37577ec..ae62536c1e 100644 --- a/core/translations/signatures.json +++ b/core/translations/signatures.json @@ -1,8 +1,8 @@ { "current": { - "merkle_root": "53515eead12df806f139761eddc91f2aa2d3de3b9e0eb831552167ee25897f4a", - "datetime": "2024-12-16T11:26:54.578708", - "commit": "76301b1e97ea5ce0a2e17967f44a9db2a2e905e4" + "merkle_root": "2a0a00d59b3beb98d0c54b7673c6bc807f15717bbb314cff0a39b5f6698dce7d", + "datetime": "2025-01-13T10:06:18.733358", + "commit": "a1c9d8806dce8b12aebcbd59647e77d0cae629e0" }, "history": [ { diff --git a/python/src/trezorlib/_internal/translations.py b/python/src/trezorlib/_internal/translations.py index 809725119d..42fcfc3f75 100644 --- a/python/src/trezorlib/_internal/translations.py +++ b/python/src/trezorlib/_internal/translations.py @@ -10,6 +10,7 @@ import construct as c from construct_classes import Struct, subcon from typing_extensions import Self, TypedDict +from ..debuglink import LayoutType from ..firmware.models import Model from ..models import TrezorModel from ..tools import EnumAdapter, TupleAdapter @@ -297,6 +298,14 @@ def order_from_json(json_order: dict[str, str]) -> Order: return {int(k): v for k, v in json_order.items()} +def get_translation(lang_data: JsonDef, key: str, layout_type: LayoutType) -> str: + item = lang_data["translations"].get(key, "") + if isinstance(item, dict): + return item.get(layout_type.name, "") + + return item # Same translation for all layouts + + def blob_from_defs( lang_data: JsonDef, order: Order, @@ -305,10 +314,11 @@ def blob_from_defs( fonts_dir: Path, ) -> TranslationsBlob: json_header: JsonHeader = lang_data["header"] + layout_type = LayoutType.from_model(model) # order translations -- python dicts keep insertion order translations_ordered: list[str] = [ - lang_data["translations"].get(key, "") for _, key in sorted(order.items()) + get_translation(lang_data, key, layout_type) for _, key in sorted(order.items()) ] translations = TranslatedStrings.from_items(translations_ordered) diff --git a/python/src/trezorlib/debuglink.py b/python/src/trezorlib/debuglink.py index d1f89db35f..8715f61aff 100644 --- a/python/src/trezorlib/debuglink.py +++ b/python/src/trezorlib/debuglink.py @@ -88,6 +88,8 @@ class LayoutType(Enum): return cls.Samson if model in (models.T3T1,): return cls.Quicksilver + if model in (models.T3W1,): + return cls.Quicksilver # TODO: use correct layout for T3W1 if model in (models.T1B1,): return cls.T1 raise ValueError(f"Unknown model: {model}")