Skip to content

Commit

Permalink
feat(core): use layout name for translation font keys
Browse files Browse the repository at this point in the history
[no changelog]
  • Loading branch information
romanz committed Jan 14, 2025
1 parent a616a10 commit 4bc8659
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 40 deletions.
12 changes: 3 additions & 9 deletions core/translations/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,8 @@ def fonts_dir(self) -> Path:
def _lang_path(self, lang: str) -> Path:
return self.path / f"{lang}.json"

def load_lang(self, lang: str, model_groups: bool = True) -> translations.JsonDef:
json_def = json.loads(self._lang_path(lang).read_text())
# special-case for T2B1 and T3B1, so that we keep the info in one place instead
# of duplicating it in two entries, risking a desync
if model_groups and (fonts_safe3 := json_def.get("fonts", {}).get("##Safe3")) is not None:
json_def["fonts"]["T2B1"] = fonts_safe3
json_def["fonts"]["T3B1"] = fonts_safe3
return json_def
def load_lang(self, lang: str) -> translations.JsonDef:
return json.loads(self._lang_path(lang).read_text())

def save_lang(self, lang: str, data: translations.JsonDef) -> None:
self._lang_path(lang).write_text(
Expand All @@ -150,7 +144,7 @@ def all_languages(self) -> t.Iterable[str]:
def update_version_from_h(self, check: bool = False) -> VersionTuple:
version = _version_from_version_h()
for lang in self.all_languages():
blob_json = self.load_lang(lang, model_groups=False)
blob_json = self.load_lang(lang)
blob_version = translations.version_from_json(
blob_json["header"]["version"]
)
Expand Down
8 changes: 4 additions & 4 deletions core/translations/cs.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"fonts": {
"##Safe3": {
"Samson": {
"1_FONT_NORMAL": "font_pixeloperator_regular_8_cs.json",
"2_FONT_BOLD": "font_pixeloperator_bold_8_cs.json",
"3_FONT_MONO": "font_pixeloperatormono_regular_8_cs.json",
Expand All @@ -10,7 +10,7 @@
"7_FONT_BOLD_UPPER": "font_pixeloperator_bold_8_upper_cs.json",
"8_FONT_SUB": null
},
"T2T1": {
"Bolt": {
"1_FONT_NORMAL": "font_tthoves_regular_21_cs.json",
"2_FONT_BOLD": null,
"3_FONT_MONO": "font_robotomono_medium_20_cs.json",
Expand All @@ -20,7 +20,7 @@
"7_FONT_BOLD_UPPER": "font_tthoves_bold_17_upper_cs.json",
"8_FONT_SUB": null
},
"T3T1": {
"Quicksilver": {
"1_FONT_NORMAL": "font_ttsatoshi_demibold_21_cs.json",
"2_FONT_BOLD": "font_ttsatoshi_demibold_21_cs.json",
"3_FONT_MONO": "font_robotomono_medium_21_cs.json",
Expand All @@ -30,7 +30,7 @@
"7_FONT_BOLD_UPPER": null,
"8_FONT_SUB": "font_ttsatoshi_demibold_18_cs.json"
},
"T3W1": {
"LayoutTBD": {
"1_FONT_NORMAL": "font_ttsatoshi_demibold_21_cs.json",
"2_FONT_BOLD": "font_ttsatoshi_demibold_21_cs.json",
"3_FONT_MONO": "font_robotomono_medium_21_cs.json",
Expand Down
8 changes: 4 additions & 4 deletions core/translations/de.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"fonts": {
"##Safe3": {
"Samson": {
"1_FONT_NORMAL": "font_pixeloperator_regular_8_de.json",
"2_FONT_BOLD": "font_pixeloperator_bold_8_de.json",
"3_FONT_MONO": "font_pixeloperatormono_regular_8_de.json",
Expand All @@ -10,7 +10,7 @@
"7_FONT_BOLD_UPPER": "font_pixeloperator_bold_8_upper_de.json",
"8_FONT_SUB": null
},
"T2T1": {
"Bolt": {
"1_FONT_NORMAL": "font_tthoves_regular_21_de.json",
"2_FONT_BOLD": null,
"3_FONT_MONO": "font_robotomono_medium_20_de.json",
Expand All @@ -20,7 +20,7 @@
"7_FONT_BOLD_UPPER": "font_tthoves_bold_17_upper_de.json",
"8_FONT_SUB": null
},
"T3T1": {
"Quicksilver": {
"1_FONT_NORMAL": "font_ttsatoshi_demibold_21_de.json",
"2_FONT_BOLD": "font_ttsatoshi_demibold_21_de.json",
"3_FONT_MONO": "font_robotomono_medium_21_de.json",
Expand All @@ -30,7 +30,7 @@
"7_FONT_BOLD_UPPER": null,
"8_FONT_SUB": "font_ttsatoshi_demibold_18_de.json"
},
"T3W1": {
"LayoutTBD": {
"1_FONT_NORMAL": "font_ttsatoshi_demibold_21_de.json",
"2_FONT_BOLD": "font_ttsatoshi_demibold_21_de.json",
"3_FONT_MONO": "font_robotomono_medium_21_de.json",
Expand Down
8 changes: 4 additions & 4 deletions core/translations/es.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"fonts": {
"##Safe3": {
"Samson": {
"1_FONT_NORMAL": "font_pixeloperator_regular_8_es.json",
"2_FONT_BOLD": "font_pixeloperator_bold_8_es.json",
"3_FONT_MONO": "font_pixeloperatormono_regular_8_es.json",
Expand All @@ -10,7 +10,7 @@
"7_FONT_BOLD_UPPER": "font_pixeloperator_bold_8_upper_es.json",
"8_FONT_SUB": null
},
"T2T1": {
"Bolt": {
"1_FONT_NORMAL": "font_tthoves_regular_21_es.json",
"2_FONT_BOLD": null,
"3_FONT_MONO": "font_robotomono_medium_20_es.json",
Expand All @@ -20,7 +20,7 @@
"7_FONT_BOLD_UPPER": "font_tthoves_bold_17_upper_es.json",
"8_FONT_SUB": null
},
"T3T1": {
"Quicksilver": {
"1_FONT_NORMAL": "font_ttsatoshi_demibold_21_es.json",
"2_FONT_BOLD": "font_ttsatoshi_demibold_21_es.json",
"3_FONT_MONO": "font_robotomono_medium_21_es.json",
Expand All @@ -30,7 +30,7 @@
"7_FONT_BOLD_UPPER": null,
"8_FONT_SUB": "font_ttsatoshi_demibold_18_es.json"
},
"T3W1": {
"LayoutTBD": {
"1_FONT_NORMAL": "font_ttsatoshi_demibold_21_es.json",
"2_FONT_BOLD": "font_ttsatoshi_demibold_21_es.json",
"3_FONT_MONO": "font_robotomono_medium_21_es.json",
Expand Down
8 changes: 4 additions & 4 deletions core/translations/fr.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"fonts": {
"##Safe3": {
"Samson": {
"1_FONT_NORMAL": "font_pixeloperator_regular_8_fr.json",
"2_FONT_BOLD": "font_pixeloperator_bold_8_fr.json",
"3_FONT_MONO": "font_pixeloperatormono_regular_8_fr.json",
Expand All @@ -10,7 +10,7 @@
"7_FONT_BOLD_UPPER": "font_pixeloperator_bold_8_upper_fr.json",
"8_FONT_SUB": null
},
"T2T1": {
"Bolt": {
"1_FONT_NORMAL": "font_tthoves_regular_21_fr.json",
"2_FONT_BOLD": null,
"3_FONT_MONO": "font_robotomono_medium_20_fr.json",
Expand All @@ -20,7 +20,7 @@
"7_FONT_BOLD_UPPER": "font_tthoves_bold_17_upper_fr.json",
"8_FONT_SUB": null
},
"T3T1": {
"Quicksilver": {
"1_FONT_NORMAL": "font_ttsatoshi_demibold_21_fr.json",
"2_FONT_BOLD": "font_ttsatoshi_demibold_21_fr.json",
"3_FONT_MONO": "font_robotomono_medium_21_fr.json",
Expand All @@ -30,7 +30,7 @@
"7_FONT_BOLD_UPPER": null,
"8_FONT_SUB": "font_ttsatoshi_demibold_18_fr.json"
},
"T3W1": {
"LayoutTBD": {
"1_FONT_NORMAL": "font_ttsatoshi_demibold_21_fr.json",
"2_FONT_BOLD": "font_ttsatoshi_demibold_21_fr.json",
"3_FONT_MONO": "font_robotomono_medium_21_fr.json",
Expand Down
8 changes: 4 additions & 4 deletions core/translations/it.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"fonts": {
"##Safe3": {
"Samson": {
"1_FONT_NORMAL": "font_pixeloperator_regular_8_it.json",
"2_FONT_BOLD": "font_pixeloperator_bold_8_it.json",
"3_FONT_MONO": "font_pixeloperatormono_regular_8_it.json",
Expand All @@ -10,7 +10,7 @@
"7_FONT_BOLD_UPPER": "font_pixeloperator_bold_8_upper_it.json",
"8_FONT_SUB": null
},
"T2T1": {
"Bolt": {
"1_FONT_NORMAL": "font_tthoves_regular_21_it.json",
"2_FONT_BOLD": null,
"3_FONT_MONO": "font_robotomono_medium_20_it.json",
Expand All @@ -20,7 +20,7 @@
"7_FONT_BOLD_UPPER": "font_tthoves_bold_17_upper_it.json",
"8_FONT_SUB": null
},
"T3T1": {
"Quicksilver": {
"1_FONT_NORMAL": "font_ttsatoshi_demibold_21_it.json",
"2_FONT_BOLD": "font_ttsatoshi_demibold_21_it.json",
"3_FONT_MONO": "font_robotomono_medium_21_it.json",
Expand All @@ -30,7 +30,7 @@
"7_FONT_BOLD_UPPER": null,
"8_FONT_SUB": "font_ttsatoshi_demibold_18_it.json"
},
"T3W1": {
"LayoutTBD": {
"1_FONT_NORMAL": "font_ttsatoshi_demibold_21_it.json",
"2_FONT_BOLD": "font_ttsatoshi_demibold_21_it.json",
"3_FONT_MONO": "font_robotomono_medium_21_it.json",
Expand Down
8 changes: 4 additions & 4 deletions core/translations/pt.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"fonts": {
"##Safe3": {
"Samson": {
"1_FONT_NORMAL": "font_pixeloperator_regular_8_pt.json",
"2_FONT_BOLD": "font_pixeloperator_bold_8_pt.json",
"3_FONT_MONO": "font_pixeloperatormono_regular_8_pt.json",
Expand All @@ -10,7 +10,7 @@
"7_FONT_BOLD_UPPER": "font_pixeloperator_bold_8_upper_pt.json",
"8_FONT_SUB": null
},
"T2T1": {
"Bolt": {
"1_FONT_NORMAL": "font_tthoves_regular_21_pt.json",
"2_FONT_BOLD": null,
"3_FONT_MONO": "font_robotomono_medium_20_pt.json",
Expand All @@ -20,7 +20,7 @@
"7_FONT_BOLD_UPPER": "font_tthoves_bold_17_upper_pt.json",
"8_FONT_SUB": null
},
"T3T1": {
"Quicksilver": {
"1_FONT_NORMAL": "font_ttsatoshi_demibold_21_pt.json",
"2_FONT_BOLD": "font_ttsatoshi_demibold_21_pt.json",
"3_FONT_MONO": "font_robotomono_medium_21_pt.json",
Expand All @@ -30,7 +30,7 @@
"7_FONT_BOLD_UPPER": null,
"8_FONT_SUB": "font_ttsatoshi_demibold_18_pt.json"
},
"T3W1": {
"LayoutTBD": {
"1_FONT_NORMAL": "font_ttsatoshi_demibold_21_pt.json",
"2_FONT_BOLD": "font_ttsatoshi_demibold_21_pt.json",
"3_FONT_MONO": "font_robotomono_medium_21_pt.json",
Expand Down
8 changes: 4 additions & 4 deletions core/translations/tr.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"fonts": {
"##Safe3": {
"Samson": {
"1_FONT_NORMAL": "font_pixeloperator_regular_8_tr.json",
"2_FONT_BOLD": "font_pixeloperator_bold_8_tr.json",
"3_FONT_MONO": "font_pixeloperatormono_regular_8_tr.json",
Expand All @@ -10,7 +10,7 @@
"7_FONT_BOLD_UPPER": "font_pixeloperator_bold_8_upper_tr.json",
"8_FONT_SUB": null
},
"T2T1": {
"Bolt": {
"1_FONT_NORMAL": "font_tthoves_regular_21_tr.json",
"2_FONT_BOLD": null,
"3_FONT_MONO": "font_robotomono_medium_20_tr.json",
Expand All @@ -20,7 +20,7 @@
"7_FONT_BOLD_UPPER": "font_tthoves_bold_17_upper_tr.json",
"8_FONT_SUB": null
},
"T3T1": {
"Quicksilver": {
"1_FONT_NORMAL": "font_ttsatoshi_demibold_21_tr.json",
"2_FONT_BOLD": "font_ttsatoshi_demibold_21_tr.json",
"3_FONT_MONO": "font_robotomono_medium_21_tr.json",
Expand All @@ -30,7 +30,7 @@
"7_FONT_BOLD_UPPER": null,
"8_FONT_SUB": "font_ttsatoshi_demibold_18_tr.json"
},
"T3W1": {
"LayoutTBD": {
"1_FONT_NORMAL": "font_ttsatoshi_demibold_21_tr.json",
"2_FONT_BOLD": "font_ttsatoshi_demibold_21_tr.json",
"3_FONT_MONO": "font_robotomono_medium_21_tr.json",
Expand Down
6 changes: 3 additions & 3 deletions python/src/trezorlib/_internal/translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,12 @@ def blob_from_defs(

translations = TranslatedStrings.from_items(translations_ordered)

if model.internal_name not in lang_data["fonts"]:
if layout_type.name not in lang_data["fonts"]:
raise ValueError(
f"Model {model.internal_name} not found in header for {json_header['language']} v{json_header['version']}"
f"Model {layout_type.name} not found in header for {json_header['language']} v{json_header['version']}"
)

model_fonts = lang_data["fonts"][model.internal_name]
model_fonts = lang_data["fonts"][layout_type.name]
fonts = FontsTable.from_dir(model_fonts, fonts_dir)

translations_bytes = translations.build()
Expand Down

0 comments on commit 4bc8659

Please sign in to comment.