diff --git a/core/embed/rust/src/translations/generated/translated_string.rs b/core/embed/rust/src/translations/generated/translated_string.rs index e8da45f6eb..6c1bbae7e1 100644 --- a/core/embed/rust/src/translations/generated/translated_string.rs +++ b/core/embed/rust/src/translations/generated/translated_string.rs @@ -1385,6 +1385,8 @@ pub enum TranslatedString { } impl TranslatedString { + // Allow building with `--all-features` (enabling all layouts results in duplicate match keys) for clippy + #[allow(unreachable_patterns)] pub fn untranslated(self) -> &'static str { match self { Self::addr_mismatch__contact_support_at => "Please contact Trezor support at", diff --git a/core/embed/rust/src/translations/generated/translated_string.rs.mako b/core/embed/rust/src/translations/generated/translated_string.rs.mako index 9ecc94fbcf..c8c194cc62 100644 --- a/core/embed/rust/src/translations/generated/translated_string.rs.mako +++ b/core/embed/rust/src/translations/generated/translated_string.rs.mako @@ -32,6 +32,9 @@ order = {int(k): v for k, v in order_index_name.items()} en_file = TR_DIR / "en.json" en_data = json.loads(en_file.read_text())["translations"] +def encode_str(s): + return re.sub(r'\\u([0-9a-f]{4})', r'\\u{\g<1>}', json.dumps(s)) + %>\ #[cfg(feature = "micropython")] use crate::micropython::qstr::Qstr; @@ -50,13 +53,30 @@ pub enum TranslatedString { } impl TranslatedString { + // Allow building with `--all-features` (enabling all layouts results in duplicate match keys) for clippy + #[allow(unreachable_patterns)] pub fn untranslated(self) -> &'static str { match self { % for name in order.values(): - %if any(name.startswith(prefix + "__") for prefix in ALTCOIN_PREFIXES): +<% + value = en_data.get(name, '""') + layouts_dict = value if isinstance(value, dict) else None + universal_fw = any(name.startswith(prefix + "__") for prefix in ALTCOIN_PREFIXES) +%>\ +%if layouts_dict is not None: + % for layout_name, layout_value in layouts_dict.items(): + %if universal_fw: #[cfg(feature = "universal_fw")] - %endif - Self::${name} => ${re.sub(r'\\u([0-9a-f]{4})', r'\\u{\g<1>}', json.dumps(en_data.get(name, '""')))}, + %endif + #[cfg(feature = "${f"layout_{layout_name.lower()}"}")] + Self::${name} => ${encode_str(layout_value)}, + % endfor +%else: + %if universal_fw: + #[cfg(feature = "universal_fw")] + %endif + Self::${name} => ${encode_str(value)}, +%endif % endfor } } diff --git a/core/mocks/trezortranslate_keys.pyi.mako b/core/mocks/trezortranslate_keys.pyi.mako index 722eb3bc52..8f0085c76e 100644 --- a/core/mocks/trezortranslate_keys.pyi.mako +++ b/core/mocks/trezortranslate_keys.pyi.mako @@ -9,7 +9,12 @@ en_data = json.loads(en_file.read_text())["translations"] %>\ class TR: -% for name, text in sorted(en_data.items()): - ${name}: str = ${json.dumps(text)} +% for name, value in sorted(en_data.items()): +<% + if isinstance(value, dict): + # For simplicity, use the first model's text for the stubs. + value, *_ = value.values() +%>\ + ${name}: str = ${json.dumps(value)} % endfor