mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-15 18:00:59 +00:00
feat(core): support per-layout untranslated text strings
[no changelog]
This commit is contained in:
parent
c9b50f3cde
commit
56f080615c
@ -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",
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user