From a476530b4ead94d4ecf171758aeefd4afec43206 Mon Sep 17 00:00:00 2001 From: matejcik Date: Thu, 25 Jan 2024 12:17:53 +0100 Subject: [PATCH] WIP: core part --- core/embed/rust/src/translations/obj.rs | 2 +- core/embed/rust/src/ui/model_tr/layout.rs | 14 ++------- .../rust/src/ui/model_tt/component/page.rs | 8 +++-- core/mocks/generated/trezortranslate.pyi | 3 +- core/src/boot.py | 3 +- core/src/trezor/__init__.py | 4 +++ core/src/trezor/translations.py | 29 ------------------- core/tools/translations/validate_same_keys.py | 2 +- 8 files changed, 18 insertions(+), 47 deletions(-) delete mode 100644 core/src/trezor/translations.py diff --git a/core/embed/rust/src/translations/obj.rs b/core/embed/rust/src/translations/obj.rs index 090d4c95b..3919664d0 100644 --- a/core/embed/rust/src/translations/obj.rs +++ b/core/embed/rust/src/translations/obj.rs @@ -292,7 +292,7 @@ extern "C" fn verify(data: Obj) -> Obj { #[no_mangle] #[rustfmt::skip] pub static mp_module_trezortranslate: Module = obj_module! { - /// from trezortranslate_keys import TR # noqa: F401 + /// from trezortranslate_keys import TR as TR # noqa: F401 /// """Translation object with attributes.""" Qstr::MP_QSTR_TR => TR_OBJ.as_obj(), diff --git a/core/embed/rust/src/ui/model_tr/layout.rs b/core/embed/rust/src/ui/model_tr/layout.rs index eca548efe..ec8ac6926 100644 --- a/core/embed/rust/src/ui/model_tr/layout.rs +++ b/core/embed/rust/src/ui/model_tr/layout.rs @@ -1640,18 +1640,8 @@ extern "C" fn new_confirm_firmware_update( .vertically_centered(); let obj = LayoutObj::new( - Confirm::new( - theme::BG, - title, - message, - None, - TR::buttons__install, - false, - ) - .with_info_screen( - TR::firmware_update__title_fingerprint, - fingerprint, - ), + Confirm::new(theme::BG, title, message, None, TR::buttons__install, false) + .with_info_screen(TR::firmware_update__title_fingerprint, fingerprint), )?; Ok(obj.into()) }; diff --git a/core/embed/rust/src/ui/model_tt/component/page.rs b/core/embed/rust/src/ui/model_tt/component/page.rs index 4472c3b59..5b874d6c9 100644 --- a/core/embed/rust/src/ui/model_tt/component/page.rs +++ b/core/embed/rust/src/ui/model_tt/component/page.rs @@ -1,11 +1,15 @@ use crate::{ - error::Error, micropython::buffer::StrBuffer, time::Instant, translations::TR, ui::{ + error::Error, + micropython::buffer::StrBuffer, + time::Instant, + translations::TR, + ui::{ component::{paginated::PageMsg, Component, ComponentExt, Event, EventCtx, Pad, Paginate}, constant, display::{self, Color}, geometry::{Insets, Rect}, util::animation_disabled, - } + }, }; use super::{ diff --git a/core/mocks/generated/trezortranslate.pyi b/core/mocks/generated/trezortranslate.pyi index db0db0f18..59411539c 100644 --- a/core/mocks/generated/trezortranslate.pyi +++ b/core/mocks/generated/trezortranslate.pyi @@ -1,5 +1,6 @@ from typing import * -from trezortranslate_keys import TR # noqa: F401 +from trezortranslate_keys import TR as TR # noqa: F401 + """Translation object with attributes.""" MAX_HEADER_LEN: int """Maximum length of the translations header.""" diff --git a/core/src/boot.py b/core/src/boot.py index 090c66336..81aa4034c 100644 --- a/core/src/boot.py +++ b/core/src/boot.py @@ -10,7 +10,7 @@ welcome_screen_start_ms = utime.ticks_ms() import storage import storage.device -from trezor import config, log, loop, ui, utils, wire +from trezor import config, log, loop, ui, utils, wire, translations from trezor.pin import ( allow_all_loader_messages, ignore_nonpin_loader_messages, @@ -69,6 +69,7 @@ async def bootscreen() -> None: ignore_nonpin_loader_messages() config.init(show_pin_timeout) +translations.init() if __debug__ and not utils.EMULATOR: config.wipe() diff --git a/core/src/trezor/__init__.py b/core/src/trezor/__init__.py index 80c7ec815..3fab1c843 100644 --- a/core/src/trezor/__init__.py +++ b/core/src/trezor/__init__.py @@ -1,2 +1,6 @@ import trezorconfig as config # noqa: F401 import trezorio as io # noqa: F401 + +import trezortranslate as translations # noqa: F401 + +TR = translations.TR diff --git a/core/src/trezor/translations.py b/core/src/trezor/translations.py deleted file mode 100644 index fec898197..000000000 --- a/core/src/trezor/translations.py +++ /dev/null @@ -1,29 +0,0 @@ -from trezor import config - -DEFAULT_LANGUAGE = "en-US" - - -def get_language() -> str: - from trezortranslate import language_name - - translation_lang = language_name() - if translation_lang: - return translation_lang - return DEFAULT_LANGUAGE - - -def write(data: bytes | bytearray, offset: int) -> None: - from trezor import wire - - if offset + len(data) > data_max_size(): - raise wire.DataError("Language data too long") - - config.translations_set(data, offset) - - -def wipe() -> None: - config.translations_wipe() - - -def data_max_size() -> int: - return config.translations_max_bytesize() diff --git a/core/tools/translations/validate_same_keys.py b/core/tools/translations/validate_same_keys.py index dd7f17737..7f8c09c5f 100644 --- a/core/tools/translations/validate_same_keys.py +++ b/core/tools/translations/validate_same_keys.py @@ -7,7 +7,7 @@ from typing import TYPE_CHECKING, Dict HERE = Path(__file__).parent CORE = HERE.parent.parent -DIR = CORE / "embed" / "rust" / "src" / "ui" / "translations" +DIR = CORE / "translations" MISSING_VALUE = "TODO:missing"