WIP - fix micropython cfg compilation

tychovrahe/fw_translations/mpu
grdddj 8 months ago
parent d2a9a8cad8
commit 953f94b27a

@ -2,6 +2,9 @@
//! (by running `make templates` in `core`)
//! do not edit manually!
// NOTE: not used as a code, only for
// documentation purposes
use super::general::TranslationsGeneral;
#[rustfmt::skip]

@ -2,6 +2,9 @@
//! (by running `make templates` in `core`)
//! do not edit manually!
// NOTE: not used as a code, only for
// documentation purposes
<%
import json

@ -1,10 +1,10 @@
//! generated from cs.rs.mako
//! generated from export.rs.mako
//! (by running `make templates` in `core`)
//! do not edit manually!
use crate::micropython::{map::Map, module::Module, qstr::Qstr};
use super::{language_name_obj, TR_OBJ};
use crate::micropython::{map::Map, module::Module, qstr::Qstr};
use super::micropython::{language_name_obj, TR_OBJ};
#[no_mangle]
#[rustfmt::skip]

@ -1,4 +1,4 @@
//! generated from cs.rs.mako
//! generated from export.rs.mako
//! (by running `make templates` in `core`)
//! do not edit manually!
@ -21,9 +21,9 @@ def get_all_json_keys(data: dict) -> set[str]:
en_keys = get_all_json_keys(en_data)
%>\
use crate::micropython::{map::Map, module::Module, qstr::Qstr};
use super::{language_name_obj, TR_OBJ};
use crate::micropython::{map::Map, module::Module, qstr::Qstr};
use super::micropython::{language_name_obj, TR_OBJ};
#[no_mangle]
#[rustfmt::skip]

@ -1,7 +1,10 @@
//! generated from cs.rs.mako
//! generated from fr.rs.mako
//! (by running `make templates` in `core`)
//! do not edit manually!
// NOTE: not used as a code, only for
// documentation purposes
use super::general::TranslationsGeneral;
#[rustfmt::skip]
@ -511,10 +514,10 @@ pub const TRANSLATIONS: TranslationsGeneral = TranslationsGeneral {
recovery__cancel_dry_run: "Annuler le chèque de sauvegarde",
recovery__check_dry_run: "Vérifiez votre sauvegarde?",
recovery__cursor_will_change: "La position du curseur changera entre les entrées pour une sécurité améliorée.",
recovery__dry_run_bip39_valid_match: "La graine de récupération entrée est valide et correspond à celle de l'appareil.",
recovery__dry_run_bip39_valid_mismatch: "La graine de récupération entrée est valide mais ne correspond pas à celle de l'appareil.",
recovery__dry_run_slip39_valid_match: "Les parts de récupération entrées sont valides et correspondent à ce qui est actuellement dans l'appareil.",
recovery__dry_run_slip39_valid_mismatch: "Les parts de récupération entrées sont valides mais ne correspondent pas à ce qui est actuellement dans l'appareil.",
recovery__dry_run_bip39_valid_match: "Récupération entrée est valide et correspond à celle de l'appareil.",
recovery__dry_run_bip39_valid_mismatch: "Récupération entrée est valide mais ne correspond pas à celle de l'appareil.",
recovery__dry_run_slip39_valid_match: "Récupération entrées sont valides et correspondent à ce qui est actuellement dans.",
recovery__dry_run_slip39_valid_mismatch: "Récupération entrées sont valides mais ne correspondent pas à ce qui est actuellement dans.",
recovery__enter_any_share: "Entrez n'importe quelle part",
recovery__enter_backup: "Entrez votre sauvegarde.",
recovery__enter_different_share: "Veuillez saisir une part différente.",

@ -1,7 +1,10 @@
//! generated from cs.rs.mako
//! generated from fr.rs.mako
//! (by running `make templates` in `core`)
//! do not edit manually!
// NOTE: not used as a code, only for
// documentation purposes
<%
import json

@ -0,0 +1,75 @@
use crate::{
error::Error,
micropython::{
ffi,
obj::{Obj, ObjBase},
qstr::Qstr,
typ::Type,
util,
},
};
use super::{get_language_name, tr};
extern "C" fn translate_attr_fn(_self_in: Obj, attr: ffi::qstr, dest: *mut Obj) {
let block = || {
let arg = unsafe { dest.read() };
if !arg.is_null() {
// Null destination would mean a `setattr`.
return Err(Error::TypeError);
}
let attr = Qstr::from_u16(attr as u16);
unsafe { dest.write(TR_OBJ.getattr(attr)?) };
Ok(())
};
unsafe { util::try_or_raise(block) }
}
#[repr(C)]
pub struct TrObj {
base: ObjBase,
}
static TR_TYPE: Type = obj_type! {
name: Qstr::MP_QSTR_TR,
attr_fn: translate_attr_fn,
};
// SAFETY: We are in a single-threaded environment.
unsafe impl Sync for TrObj {}
impl TrObj {
fn obj_type() -> &'static Type {
&TR_TYPE
}
fn getattr(&self, attr: Qstr) -> Result<Obj, Error> {
tr(attr.as_str()).try_into()
}
/// Convert TrObj to a MicroPython object
pub const fn as_obj(&'static self) -> Obj {
// SAFETY:
// - We are an object struct with a base and a type.
// - 'static lifetime holds us in place.
// - There's nothing to mutate.
unsafe { Obj::from_ptr(self as *const _ as *mut _) }
}
}
/// Translations object callable from micropython.
pub static TR_OBJ: TrObj = TrObj {
base: TR_TYPE.as_base(),
};
/// Language name getter callable from micropython.
pub extern "C" fn language_name_obj() -> Obj {
let block = || {
if let Some(lang) = get_language_name() {
lang.try_into()
} else {
Ok(Obj::const_none())
}
};
unsafe { util::try_or_raise(block) }
}

@ -2,13 +2,13 @@ mod en;
#[cfg(feature = "micropython")]
mod export;
mod general;
#[cfg(feature = "micropython")]
mod micropython;
use en::EN_TRANSLATIONS;
use general::LANGUAGE_INDEX;
#[cfg(feature = "micropython")]
use crate::micropython::{ffi, obj::Obj, obj::ObjBase, qstr::Qstr, typ::Type, util};
use crate::{error::Error, trezorhal::translations::translations_get};
use crate::trezorhal::translations::translations_get;
use core::str;
@ -16,70 +16,6 @@ use core::str;
const DELIMITER_BYTE: u8 = b'*';
const TERMINATE_BYTE: u8 = 0xFF;
extern "C" fn translate_attr_fn(_self_in: Obj, attr: ffi::qstr, dest: *mut Obj) {
let block = || {
let arg = unsafe { dest.read() };
if !arg.is_null() {
// Null destination would mean a `setattr`.
return Err(Error::TypeError);
}
let attr = Qstr::from_u16(attr as u16);
unsafe { dest.write(TR_OBJ.getattr(attr)?) };
Ok(())
};
unsafe { util::try_or_raise(block) }
}
#[repr(C)]
pub struct TrObj {
base: ObjBase,
}
static TR_TYPE: Type = obj_type! {
name: Qstr::MP_QSTR_TR,
attr_fn: translate_attr_fn,
};
// SAFETY: We are in a single-threaded environment.
unsafe impl Sync for TrObj {}
impl TrObj {
fn obj_type() -> &'static Type {
&TR_TYPE
}
fn getattr(&self, attr: Qstr) -> Result<Obj, Error> {
tr(attr.as_str()).try_into()
}
/// Convert TrObj to a MicroPython object
const fn as_obj(&'static self) -> Obj {
// SAFETY:
// - We are an object struct with a base and a type.
// - 'static lifetime holds us in place.
// - There's nothing to mutate.
unsafe { Obj::from_ptr(self as *const _ as *mut _) }
}
}
/// Translations object callable from micropython.
pub static TR_OBJ: TrObj = TrObj {
base: TR_TYPE.as_base(),
};
/// Language name getter callable from micropython.
#[cfg(feature = "micropython")]
pub extern "C" fn language_name_obj() -> Obj {
let block = || {
if let Some(lang) = get_language_name() {
lang.try_into()
} else {
Ok(Obj::const_none())
}
};
unsafe { util::try_or_raise(block) }
}
/// Translation function for Rust.
pub fn tr(key: &str) -> &'static str {
translate(key).unwrap_or_default()

Loading…
Cancel
Save