mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-15 09:50:57 +00:00
feat(core): support per-layout text strings
Tested by modifying a single untranslated text entry.
This commit is contained in:
parent
c9b50f3cde
commit
6927b8e4a8
@ -546,7 +546,7 @@ pub enum TranslatedString {
|
||||
homescreen__title_no_usb_connection = 327, // "No USB connection"
|
||||
homescreen__title_pin_not_set = 328, // "PIN not set"
|
||||
homescreen__title_seedless = 329, // "Seedless"
|
||||
homescreen__title_set = 330, // "Change wallpaper"
|
||||
homescreen__title_set = 330, // {"Bolt": "Change wallpaper?", "Samson": "Change wallpaper?", "Quicksilver": "Change wallpaper?"}
|
||||
inputs__back = 331, // "BACK"
|
||||
inputs__cancel = 332, // "CANCEL"
|
||||
inputs__delete = 333, // "DELETE"
|
||||
@ -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",
|
||||
@ -1922,7 +1924,12 @@ impl TranslatedString {
|
||||
Self::homescreen__title_no_usb_connection => "No USB connection",
|
||||
Self::homescreen__title_pin_not_set => "PIN not set",
|
||||
Self::homescreen__title_seedless => "Seedless",
|
||||
Self::homescreen__title_set => "Change wallpaper",
|
||||
#[cfg(feature = "layout_bolt")]
|
||||
Self::homescreen__title_set => "Change wallpaper?",
|
||||
#[cfg(feature = "layout_samson")]
|
||||
Self::homescreen__title_set => "Change wallpaper?",
|
||||
#[cfg(feature = "layout_quicksilver")]
|
||||
Self::homescreen__title_set => "Change wallpaper?",
|
||||
Self::inputs__back => "BACK",
|
||||
Self::inputs__cancel => "CANCEL",
|
||||
Self::inputs__delete => "DELETE",
|
||||
|
@ -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,26 @@ 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():
|
||||
<%
|
||||
value = en_data.get(name, '""')
|
||||
layouts_dict = value if isinstance(value, dict) else None
|
||||
%>\
|
||||
%if any(name.startswith(prefix + "__") for prefix in ALTCOIN_PREFIXES):
|
||||
#[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, '""')))},
|
||||
%if layouts_dict is not None:
|
||||
% for layout_name, layout_value in layouts_dict.items():
|
||||
#[cfg(feature = "${f"layout_{layout_name.lower()}"}")]
|
||||
Self::${name} => ${encode_str(layout_value)},
|
||||
% endfor
|
||||
%else:
|
||||
Self::${name} => ${encode_str(value)},
|
||||
%endif
|
||||
% endfor
|
||||
}
|
||||
}
|
||||
|
@ -377,7 +377,7 @@ class TR:
|
||||
homescreen__title_no_usb_connection: str = "No USB connection"
|
||||
homescreen__title_pin_not_set: str = "PIN not set"
|
||||
homescreen__title_seedless: str = "Seedless"
|
||||
homescreen__title_set: str = "Change wallpaper"
|
||||
homescreen__title_set: str = "Change wallpaper?"
|
||||
inputs__back: str = "BACK"
|
||||
inputs__cancel: str = "CANCEL"
|
||||
inputs__delete: str = "DELETE"
|
||||
|
@ -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
|
||||
|
||||
|
@ -379,7 +379,7 @@
|
||||
"homescreen__title_no_usb_connection": "No USB connection",
|
||||
"homescreen__title_pin_not_set": "PIN not set",
|
||||
"homescreen__title_seedless": "Seedless",
|
||||
"homescreen__title_set": "Change wallpaper",
|
||||
"homescreen__title_set": {"Bolt": "Change wallpaper?", "Samson": "Change wallpaper?", "Quicksilver": "Change wallpaper?"},
|
||||
"inputs__back": "BACK",
|
||||
"inputs__cancel": "CANCEL",
|
||||
"inputs__delete": "DELETE",
|
||||
|
Loading…
Reference in New Issue
Block a user