1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-15 18:00:59 +00:00

feat(python): support per-layout translations

Tested by modifying a single translation entry.
This commit is contained in:
Roman Zeyde 2025-01-13 12:18:27 +02:00
parent 6927b8e4a8
commit 193cdb76eb
4 changed files with 17 additions and 5 deletions

View File

@ -421,7 +421,7 @@
"homescreen__title_no_usb_connection": "Žádné připojení usb", "homescreen__title_no_usb_connection": "Žádné připojení usb",
"homescreen__title_pin_not_set": "Není nastaven PIN", "homescreen__title_pin_not_set": "Není nastaven PIN",
"homescreen__title_seedless": "Bez seedu", "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__back": "ZPĚT",
"inputs__cancel": "ZRUŠIT", "inputs__cancel": "ZRUŠIT",
"inputs__delete": "ODSTRANIT", "inputs__delete": "ODSTRANIT",

View File

@ -1,8 +1,8 @@
{ {
"current": { "current": {
"merkle_root": "53515eead12df806f139761eddc91f2aa2d3de3b9e0eb831552167ee25897f4a", "merkle_root": "2a0a00d59b3beb98d0c54b7673c6bc807f15717bbb314cff0a39b5f6698dce7d",
"datetime": "2024-12-16T11:26:54.578708", "datetime": "2025-01-13T10:06:18.733358",
"commit": "76301b1e97ea5ce0a2e17967f44a9db2a2e905e4" "commit": "a1c9d8806dce8b12aebcbd59647e77d0cae629e0"
}, },
"history": [ "history": [
{ {

View File

@ -10,6 +10,7 @@ import construct as c
from construct_classes import Struct, subcon from construct_classes import Struct, subcon
from typing_extensions import Self, TypedDict from typing_extensions import Self, TypedDict
from ..debuglink import LayoutType
from ..firmware.models import Model from ..firmware.models import Model
from ..models import TrezorModel from ..models import TrezorModel
from ..tools import EnumAdapter, TupleAdapter 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()} 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( def blob_from_defs(
lang_data: JsonDef, lang_data: JsonDef,
order: Order, order: Order,
@ -305,10 +314,11 @@ def blob_from_defs(
fonts_dir: Path, fonts_dir: Path,
) -> TranslationsBlob: ) -> TranslationsBlob:
json_header: JsonHeader = lang_data["header"] json_header: JsonHeader = lang_data["header"]
layout_type = LayoutType.from_model(model)
# order translations -- python dicts keep insertion order # order translations -- python dicts keep insertion order
translations_ordered: list[str] = [ 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) translations = TranslatedStrings.from_items(translations_ordered)

View File

@ -88,6 +88,8 @@ class LayoutType(Enum):
return cls.Samson return cls.Samson
if model in (models.T3T1,): if model in (models.T3T1,):
return cls.Quicksilver return cls.Quicksilver
if model in (models.T3W1,):
return cls.Quicksilver # TODO: use correct layout for T3W1
if model in (models.T1B1,): if model in (models.T1B1,):
return cls.T1 return cls.T1
raise ValueError(f"Unknown model: {model}") raise ValueError(f"Unknown model: {model}")