From c9e8dad92b6479b096413f0a087a3352d91cd0c1 Mon Sep 17 00:00:00 2001 From: grdddj Date: Mon, 6 Nov 2023 10:46:36 +0100 Subject: [PATCH] WIP - specific fonts for specific models --- core/embed/rust/src/ui/translations/cs.json | 7 ++++- core/embed/rust/src/ui/translations/fr.json | 7 ++++- python/src/trezorlib/cli/settings.py | 4 ++- python/src/trezorlib/translations.py | 13 +++++---- tests/device_tests/test_language.py | 31 +++++++++++++++++---- 5 files changed, 48 insertions(+), 14 deletions(-) diff --git a/core/embed/rust/src/ui/translations/cs.json b/core/embed/rust/src/ui/translations/cs.json index 9f421e2e643..0d201f4f6d1 100644 --- a/core/embed/rust/src/ui/translations/cs.json +++ b/core/embed/rust/src/ui/translations/cs.json @@ -1,6 +1,11 @@ { "font": { - "file": "font_pixeloperator_regular_8_cs.json" + "T": { + "file": "font_roboto_regular_20_cs.json" + }, + "Safe 3": { + "file": "font_pixeloperator_regular_8_cs.json" + } }, "header": { "language": "cs", diff --git a/core/embed/rust/src/ui/translations/fr.json b/core/embed/rust/src/ui/translations/fr.json index a04740de69e..c168ca1b527 100644 --- a/core/embed/rust/src/ui/translations/fr.json +++ b/core/embed/rust/src/ui/translations/fr.json @@ -1,6 +1,11 @@ { "font": { - "file": "font_pixeloperator_regular_8_fr.json" + "T": { + "file": "font_roboto_regular_20_fr.json" + }, + "Safe 3": { + "file": "font_pixeloperator_regular_8_fr.json" + } }, "header": { "language": "fr", diff --git a/python/src/trezorlib/cli/settings.py b/python/src/trezorlib/cli/settings.py index 84edc03e57c..957d1660ee9 100644 --- a/python/src/trezorlib/cli/settings.py +++ b/python/src/trezorlib/cli/settings.py @@ -219,7 +219,9 @@ def language(client: "TrezorClient", file: TextIO, url: str, remove: bool) -> st language_data = b"" else: if file: - language_data = translations.blob_from_file(file) + model = client.features.model + assert model is not None + language_data = translations.blob_from_file(file, model) elif url: language_data = translations.blob_from_url(url) else: diff --git a/python/src/trezorlib/translations.py b/python/src/trezorlib/translations.py index 9c5401bd18d..77bb468181c 100644 --- a/python/src/trezorlib/translations.py +++ b/python/src/trezorlib/translations.py @@ -14,11 +14,11 @@ FontData = Dict[str, str] -def blob_from_file(file: TextIO) -> bytes: +def blob_from_file(file: TextIO, model: str) -> bytes: data = json.load(file) file_dir = file.name.rsplit("/", 1)[0] file_dir_absolute_path = Path(file_dir).absolute() - return blob_from_dict(data, file_dir_absolute_path) + return blob_from_dict(data, file_dir_absolute_path, model) def blob_from_url(url: str) -> bytes: @@ -27,11 +27,14 @@ def blob_from_url(url: str) -> bytes: return r.content -def blob_from_dict(data: Dict[str, Any], file_dir: Path) -> bytes: +def blob_from_dict(data: Dict[str, Any], file_dir: Path, model: str) -> bytes: header: HeaderData = data["header"] translations: TranslationData = data["translations"] - font: FontData = data["font"] - return _blob_from_data(header, translations, font, file_dir) + font = data["font"] + if model not in font: + raise ValueError(f"Font for model {model} not found") + model_font: FontData = font[model] + return _blob_from_data(header, translations, model_font, file_dir) def _blob_from_data( diff --git a/tests/device_tests/test_language.py b/tests/device_tests/test_language.py index 28df91217d9..ee5a47199c5 100644 --- a/tests/device_tests/test_language.py +++ b/tests/device_tests/test_language.py @@ -55,12 +55,18 @@ def _set_english_return_back(client: Client) -> Generator[Client, None, None]: def _set_full_czech(client: Client): with client, open(CS_JSON, "r") as f: - device.change_language(client, language_data=translations.blob_from_file(f)) + device.change_language( + client, + language_data=translations.blob_from_file(f, client.features.model or ""), + ) def _set_full_french(client: Client): with client, open(FR_JSON, "r") as f: - device.change_language(client, language_data=translations.blob_from_file(f)) + device.change_language( + client, + language_data=translations.blob_from_file(f, client.features.model or ""), + ) def _set_default_english(client: Client): @@ -96,7 +102,11 @@ def test_change_language_errors(client: Client): ), client: with open(CS_JSON, "r") as f: device.change_language( - client, language_data=translations.blob_from_file(f) + b"abc" + client, + language_data=translations.blob_from_file( + f, client.features.model or "" + ) + + b"abc", ) assert client.features.language == "en-US" @@ -104,7 +114,11 @@ def test_change_language_errors(client: Client): with pytest.raises(exceptions.TrezorFailure, match="Invalid data hash"), client: with open(CS_JSON, "r") as f: device.change_language( - client, language_data=translations.blob_from_file(f)[:-4] + b"abcd" + client, + language_data=translations.blob_from_file( + f, client.features.model or "" + )[:-4] + + b"abcd", ) assert client.features.language == "en-US" @@ -117,7 +131,9 @@ def test_change_language_errors(client: Client): data["header"]["version"] = "3.5.4" device.change_language( client, - language_data=translations.blob_from_dict(data, file_dir=TRANSLATIONS), + language_data=translations.blob_from_dict( + data, file_dir=TRANSLATIONS, model=client.features.model or "" + ), ) assert client.features.language == "en-US" @@ -129,7 +145,10 @@ def test_change_language_errors(client: Client): data = json.load(f) data["header"]["version"] = "ABC.XYZ.DEF" device.change_language( - client, language_data=translations.blob_from_dict(data, file_dir=TRANSLATIONS) + client, + language_data=translations.blob_from_dict( + data, file_dir=TRANSLATIONS, model=client.features.model or "" + ), ) assert client.features.language == "en-US"