Merge remote-tracking branch 'agent/benma-agent/checked-rust-translations'
What changed, and why it matters
This commit hardens how translated user-facing messages are selected in the BitBox02 hardware wallet firmware. It introduces compile-time checks that reject messages missing from the English translation catalog and that verify the number of placeholders in formatted strings. The change prevents accidental silent fallback to English and mismatched format arguments, which could otherwise confuse users or make security prompts misleading. It is a defensive hardening patch rather than a fix for a known exploitable vulnerability.
No immediate action required. Treat as a hardening improvement. Continue migrating any remaining direct `translate`/`format` call sites to the checked macros, and ensure CI enforces the new `clippy::disallowed_methods` rule. Review the English locale file for completeness because the compile-time checks now depend on it.
Security signals we found
Compile-time validation of translatable strings against source locale catalog
Compile-time validation of format placeholder count against argument array length
Clippy lint disallows direct use of unchecked translation/format functions
Migration of user-facing security prompts (transaction confirmations, recovery workflows, typed-data signing) to checked macros
Prevents silent fallback to English for missing or drifted translation keys
Evidence from the diff
The merge adds checked i18n macros (tr!, format!, tr_format!) that perform const-evaluation against the English locale catalog and count {}/{:?} placeholders at compile time. It also enables the clippy::disallowed_methods lint and forbids direct calls to lower-level translation functions, forcing callers through the checked macros. Existing call sites across Bitcoin, Cardano, Ethereum, device-language, mnemonic, and UI code are migrated to the new macros. The patch reduces the risk of runtime translation fallback and format-string/argument-count mismatches.
Changed components
bitbox-i18n translation/format macros and build-time checksbitbox02-rust i18n wrappers (tr!, tr_format!)Bitcoin script config confirmation renderingCardano transaction slot verification promptsEthereum EIP-712 typed message signing promptsDevice language change confirmationMnemonic backup and restore workflow promptsBitBox02 UI transaction/fee/recipient review promptsInspect captured patch +221 / −69
### src/CMakeLists.txt
@@ -279,6 +279,7 @@ if(NOT CMAKE_CROSSCOMPILING)
--release
--tests --
# enabled linters:
+ -D clippy::disallowed_methods
-W clippy::use_debug
-W clippy::large_futures
# disabled linters:
### src/rust/.clippy.toml
@@ -1 +1,9 @@
future-size-threshold=4096
+
+disallowed-methods = [
+ { path = "bitbox_i18n::translate", reason = "Use tr!() to check the message at compile time" },
+ { path = "bitbox_i18n::format", reason = "Use bitbox_i18n::format!() to check the message at compile time" },
+ { path = "bitbox02_rust::i18n::I18n::tr", reason = "Use tr!() to check the message at compile time" },
+ { path = "bitbox02_rust::i18n::I18n::tr_format", reason = "Use tr_format!() to check the message at compile time" },
+ { path = "bitbox02::i18n::translate_current", reason = "Use bitbox_i18n::tr!() with the current language" },
+]
### src/rust/bitbox-i18n/build.rs
@@ -5,6 +5,10 @@ use std::env;
use std::fs;
use std::path::{Path, PathBuf};
+#[path = "src/placeholders.rs"]
+mod placeholders;
+use placeholders::placeholder_count;
+
const FNV1A64_OFFSET: u64 = 0xcbf29ce484222325;
const FNV1A64_PRIME: u64 = 0x100000001b3;
const SOURCE_LOCALE: &str = "en";
@@ -134,10 +138,6 @@ fn locale_entries(
by_english.into_iter().collect()
}
-fn placeholder_count(value: &str) -> usize {
- value.matches("{}").count() + value.matches("{:?}").count()
-}
-
fn generated_table(locale: &str, entries: &[(String, String)]) -> String {
let mut out = format!(
"pub(crate) const {}_TRANSLATIONS: &[(u64, &str)] = &[\n",
### src/rust/bitbox-i18n/src/lib.rs
@@ -8,11 +8,91 @@ use alloc::borrow::Cow;
use alloc::string::String;
use bitbox_hal::memory::Language;
+mod placeholders;
+#[doc(hidden)]
+pub use placeholders::placeholder_count;
+
include!(concat!(env!("OUT_DIR"), "/i18n.rs"));
const FNV1A64_OFFSET: u64 = 0xcbf29ce484222325;
const FNV1A64_PRIME: u64 = 0x100000001b3;
+/// Rejects messages missing from the English catalog, including constants.
+///
+/// ```compile_fail
+/// use bitbox_hal::memory::Language;
+/// fn unused<T>() {
+/// const MESSAGE: &str = "not a catalog entry";
+/// bitbox_i18n::tr!(Language::German, MESSAGE);
+/// }
+/// ```
+///
+/// Runtime messages cannot be checked at compile time.
+///
+/// ```compile_fail
+/// use bitbox_hal::memory::Language;
+/// let message = String::from("Warning");
+/// bitbox_i18n::tr!(Language::German, message.as_str());
+/// ```
+#[macro_export]
+macro_rules! tr {
+ ($language:expr, $msg:expr $(,)?) => {{
+ const _: &str = $crate::checked_message($msg);
+ #[allow(clippy::disallowed_methods)]
+ {
+ $crate::translate($language, const { $msg })
+ }
+ }};
+}
+
+/// Rejects missing catalog entries and argument counts that do not match the pattern.
+///
+/// ```compile_fail
+/// use bitbox_hal::memory::Language;
+/// fn unused<T>() {
+/// bitbox_i18n::format!(Language::German, "not a catalog entry: {}", &["value"]);
+/// }
+/// ```
+///
+/// ```compile_fail
+/// use bitbox_hal::memory::Language;
+/// bitbox_i18n::format!(Language::German, "{} words", &[]);
+/// ```
+///
+/// ```compile_fail
+/// use bitbox_hal::memory::Language;
+/// bitbox_i18n::format!(Language::German, "{} words", &["12", "24"]);
+/// ```
+///
+/// Arguments must be an array reference so its length can be checked at compile time.
+///
+/// ```compile_fail
+/// use bitbox_hal::memory::Language;
+/// let args: &[&str] = &["12"];
+/// bitbox_i18n::format!(Language::German, "{} words", args);
+/// ```
+#[macro_export]
+macro_rules! format {
+ ($language:expr, $msg:expr, $args:expr $(,)?) => {{
+ const _: &str = $crate::checked_message($msg);
+ let language = $language;
+ let args: &[&str; $crate::placeholder_count($msg)] = $args;
+ #[allow(clippy::disallowed_methods)]
+ {
+ $crate::format(language, const { $msg }, args)
+ }
+ }};
+}
+
+#[doc(hidden)]
+pub const fn checked_message(english: &str) -> &str {
+ assert!(
+ is_translatable(english),
+ "i18n: message is not a value in src/i18n/locales/en/firmware.json",
+ );
+ english
+}
+
pub fn language_from_code(code: &str) -> Option<Language> {
let code = code.as_bytes();
if code.len() < 2 {
@@ -45,6 +125,7 @@ pub fn translate<'a>(language: Language, english: &'a str) -> Cow<'a, str> {
}
}
+#[allow(clippy::disallowed_methods)]
pub fn format(language: Language, english: &'static str, args: &[&str]) -> String {
let translated = translate(language, english);
format_pattern(&translated, args)
@@ -137,6 +218,7 @@ mod tests {
}
#[test]
+ #[allow(clippy::disallowed_methods)]
fn test_translate() {
assert_eq!(
translate(Language::English, "Proceed to upgrade?").as_ref(),
@@ -152,6 +234,53 @@ mod tests {
);
}
+ #[test]
+ fn test_tr() {
+ const MESSAGE: &str = "Proceed to upgrade?";
+ for (language, expected) in [
+ (Language::English, MESSAGE),
+ (Language::German, "Firmware\naktualisieren?"),
+ ] {
+ assert_eq!(tr!(language, MESSAGE), expected);
+ }
+ }
+
+ #[test]
+ fn test_format_macro() {
+ assert_eq!(
+ format!(
+ Language::German,
+ "Fee is {}%\nof the send amount.\nProceed?",
+ &[&String::from("17.0")],
+ ),
+ "Gebühr: 17.0%\ndes Sendebetrags.\nFortfahren?",
+ );
+ assert_eq!(format!(Language::English, "Warning", &[]), "Warning");
+ const PATTERN: &str = "{} of {}";
+ let args = ["1", "12"];
+ assert_eq!(format!(Language::English, PATTERN, &args), "1 of 12");
+ }
+
+ #[test]
+ fn test_placeholder_count() {
+ for (pattern, expected) in [
+ ("", 0),
+ ("no placeholders", 0),
+ ("{}", 1),
+ ("{:?}", 1),
+ ("{} / {:?} / {}", 3),
+ ("ä {} {{}}", 2),
+ ("{", 0),
+ ("{:?", 0),
+ ] {
+ assert_eq!(placeholder_count(pattern), expected);
+ assert_eq!(
+ placeholder_count(pattern),
+ pattern.matches("{}").count() + pattern.matches("{:?}").count(),
+ );
+ }
+ }
+
#[test]
fn test_generated_table_sorted() {
assert!(DE_TRANSLATIONS.windows(2).all(|pair| pair[0].0 < pair[1].0));
@@ -165,6 +294,7 @@ mod tests {
}
#[test]
+ #[allow(clippy::disallowed_methods)]
fn test_format() {
assert_eq!(
format(
### src/rust/bitbox-i18n/src/placeholders.rs
@@ -0,0 +1,11 @@
+// SPDX-License-Identifier: Apache-2.0
+
+pub const fn placeholder_count(value: &str) -> usize {
+ let mut bytes = value.as_bytes();
+ let mut count = 0;
+ while let [_, rest @ ..] = bytes {
+ count += matches!(bytes, [b'{', b'}', ..] | [b'{', b':', b'?', b'}', ..]) as usize;
+ bytes = rest;
+ }
+ count
+}
### src/rust/bitbox02-rust/src/hww/api/bitcoin/script_configs.rs
@@ -40,7 +40,7 @@ impl ValidatedScriptConfigWithKeypath<'_> {
config: ValidatedScriptConfig::SimpleType(_),
} => {
let keypath_account_element = keypath.get(2).ok_or(Error::Generic)?;
- Ok(crate::i18n::format(
+ Ok(bitbox_i18n::format!(
language,
"This BitBox (account #{})",
&[&(keypath_account_element
@@ -57,7 +57,7 @@ impl ValidatedScriptConfigWithKeypath<'_> {
| ValidatedScriptConfigWithKeypath {
config: ValidatedScriptConfig::Policy { name, .. },
..
- } => Ok(crate::i18n::format(language, "This BitBox - {}", &[name])),
+ } => Ok(bitbox_i18n::format!(language, "This BitBox - {}", &[name])),
}
}
}
### src/rust/bitbox02-rust/src/hww/api/cardano/sign_transaction.rs
@@ -72,15 +72,10 @@ async fn verify_slot(
}
let epoch = SHELLEY_START_EPOCH + (slot - SHELLEY_START_SLOT) / SHELLEY_SLOTS_IN_EPOCH;
let slot_in_epoch = (slot - SHELLEY_START_SLOT) % SHELLEY_SLOTS_IN_EPOCH;
- let title = hal.tr(title);
let body = crate::tr_format!(
hal,
"{}\nslot {} in\nepoch {}",
- &[
- title.as_ref(),
- &slot_in_epoch.to_string(),
- &epoch.to_string(),
- ],
+ &[title, &slot_in_epoch.to_string(), &epoch.to_string()],
);
hal.ui()
.confirm(&ConfirmParams {
@@ -184,16 +179,12 @@ async fn _process(
.await?;
} else {
if validity_interval_start_present {
- verify_slot(
- hal,
- params,
- "Can be mined from",
- request.validity_interval_start,
- )
- .await?;
+ let title = crate::tr!(hal, "Can be mined from");
+ verify_slot(hal, params, &title, request.validity_interval_start).await?;
}
if ttl_present {
- verify_slot(hal, params, "Can be mined until", request.ttl).await?;
+ let title = crate::tr!(hal, "Can be mined until");
+ verify_slot(hal, params, &title, request.ttl).await?;
}
}
}
### src/rust/bitbox02-rust/src/hww/api/ethereum/sign_typed_msg.rs
@@ -21,6 +21,7 @@ use crate::workflow::confirm;
use pb::eth_request::Request;
use pb::eth_response::Response;
+use alloc::borrow::Cow;
use alloc::boxed::Box;
use alloc::string::{String, ToString};
use alloc::vec::Vec;
@@ -382,11 +383,11 @@ fn encode_value(
Ok(result)
}
-fn confirm_title(root_object: RootObject) -> &'static str {
+fn confirm_title(hal: &mut impl crate::hal::Hal, root_object: RootObject) -> Cow<'static, str> {
match root_object {
- RootObject::Unknown => "Unknown",
- RootObject::Domain => "Domain",
- RootObject::Message => "Message",
+ RootObject::Unknown => crate::tr!(hal, "Unknown"),
+ RootObject::Domain => crate::tr!(hal, "Domain"),
+ RootObject::Message => crate::tr!(hal, "Message"),
}
}
@@ -525,7 +526,7 @@ async fn encode_member<U: sha3::digest::Update>(
);
let title = format!(
"{}{}",
- hal.tr(confirm_title(context.root_object)),
+ confirm_title(hal, context.root_object),
context.title_suffix.as_deref().unwrap_or("")
);
confirm::confirm_value(
@@ -569,7 +570,7 @@ async fn hash_array(
{
let title = format!(
"{}{}",
- hal.tr(confirm_title(context.root_object)),
+ confirm_title(hal, context.root_object),
context.title_suffix.as_deref().unwrap_or("")
);
let list_description = if array_size == 0 {
### src/rust/bitbox02-rust/src/hww/api/set_device_language.rs
@@ -19,7 +19,7 @@ pub async fn process(
}
if hal.memory().is_initialized() {
let language_name = language_name(current_language, language);
- let body = crate::i18n::format(
+ let body = bitbox_i18n::format!(
current_language,
"Change language\nto {}?",
&[language_name.as_ref()],
@@ -40,8 +40,8 @@ fn language_name(
language: Language,
) -> alloc::borrow::Cow<'static, str> {
match language {
- Language::English => crate::i18n::translate(current_language, "English"),
- Language::German => crate::i18n::translate(current_language, "German"),
+ Language::English => bitbox_i18n::tr!(current_language, "English"),
+ Language::German => bitbox_i18n::tr!(current_language, "German"),
}
}
### src/rust/bitbox02-rust/src/i18n.rs
@@ -9,30 +9,32 @@ use bitbox_hal::memory::Language;
use crate::hal::{Hal, Memory};
pub use bitbox_i18n::{
- SUPPORTED_LANGUAGES, format, is_translatable, language_code, language_from_code, translate,
+ SUPPORTED_LANGUAGES, checked_message, format, language_code, language_from_code,
+ placeholder_count, translate,
};
-/// Verifying at compile time that the literal exists in the English source file.
-/// Prevents literals to drift from the locale file i.e. translations silently falling back to English.
+/// Verifying at compile time that the message exists in the English source file.
+/// Prevents messages from drifting from the locale file and silently falling back to English.
#[macro_export]
macro_rules! tr {
- ($hal:expr, $msg:literal $(,)?) => {{
- const _: () = ::core::assert!(
- $crate::i18n::is_translatable($msg),
- "i18n: string literal is not a value in src/i18n/locales/en/firmware.json",
- );
- $hal.tr($msg)
+ ($hal:expr, $msg:expr $(,)?) => {{
+ const _: &str = $crate::i18n::checked_message($msg);
+ #[allow(clippy::disallowed_methods)]
+ {
+ $hal.tr(const { $msg })
+ }
}};
}
#[macro_export]
macro_rules! tr_format {
- ($hal:expr, $msg:literal, $args:expr $(,)?) => {{
- const _: () = ::core::assert!(
- $crate::i18n::is_translatable($msg),
- "i18n: format pattern is not a value in src/i18n/locales/en/firmware.json",
- );
- $hal.tr_format($msg, $args)
+ ($hal:expr, $msg:expr, $args:expr $(,)?) => {{
+ const _: &str = $crate::i18n::checked_message($msg);
+ let args: &[&str; $crate::i18n::placeholder_count($msg)] = $args;
+ #[allow(clippy::disallowed_methods)]
+ {
+ $hal.tr_format(const { $msg }, args)
+ }
}};
}
@@ -48,11 +50,13 @@ pub trait I18n {
}
impl<T: Hal> I18n for T {
+ #[allow(clippy::disallowed_methods)]
fn tr<'a>(&mut self, english: &'a str) -> Cow<'a, str> {
let language = self.memory().get_device_language();
translate(language, english)
}
+ #[allow(clippy::disallowed_methods)]
fn tr_format(&mut self, english: &'static str, args: &[&str]) -> String {
let language = self.memory().get_device_language();
format(language, english, args)
### src/rust/bitbox02-rust/src/workflow/confirm.rs
@@ -17,7 +17,7 @@ pub(crate) async fn confirm_value(
) -> Result<(), UserAbort> {
if params.body.len() > MAX_CONFIRM_BODY_SIZE {
let title = crate::tr!(hal, "Warning");
- let body = hal.tr(TRUNCATION_WARNING_BODY);
+ let body = crate::tr!(hal, TRUNCATION_WARNING_BODY);
hal.ui()
.confirm(&ConfirmParams {
title: &title,
### src/rust/bitbox02-rust/src/workflow/mnemonic.rs
@@ -68,7 +68,7 @@ pub async fn show_and_confirm_mnemonic(
words: &[&str],
language: Language,
) -> Result<(), UserAbort> {
- let body = crate::i18n::format(language, "{} words follow", &[&words.len().to_string()]);
+ let body = bitbox_i18n::format!(language, "{} words follow", &[&words.len().to_string()]);
hal_ui
.confirm(&ConfirmParams {
title: "",
@@ -83,7 +83,7 @@ pub async fn show_and_confirm_mnemonic(
hal_ui.show_mnemonic(words).await?;
// Can only succeed due to `accept_only`.
- let body = crate::i18n::translate(language, "Please confirm\neach word");
+ let body = bitbox_i18n::tr!(language, "Please confirm\neach word");
let _ = hal_ui
.confirm(&ConfirmParams {
title: "",
@@ -99,15 +99,15 @@ pub async fn show_and_confirm_mnemonic(
let title = format!("{:02}", word_idx + 1);
let (correct_idx, choices) = create_random_unique_words(hal_random, word, NUM_RANDOM_WORDS);
let mut choices: Vec<&str> = choices.iter().map(|c| c.as_ref()).collect();
- let back_to_words = crate::i18n::translate(language, "Back to\nrecovery words");
+ let back_to_words = bitbox_i18n::tr!(language, "Back to\nrecovery words");
choices.push(&back_to_words);
let back_idx = (choices.len() - 1) as u8;
loop {
match hal_ui.quiz_mnemonic_word(&choices, &title).await? {
selected_idx if selected_idx == correct_idx => break,
selected_idx if selected_idx == back_idx => hal_ui.show_mnemonic(words).await?,
_ => {
- let status = crate::i18n::translate(language, "Incorrect word\nTry again");
+ let status = bitbox_i18n::tr!(language, "Incorrect word\nTry again");
hal_ui.status(&status, false).await
}
}
@@ -205,16 +205,15 @@ async fn get_24th_word(
// Add one more menu entry.
let none_of_them_idx = {
choices.push(zeroize::Zeroizing::new(
- crate::i18n::translate(language, "None of them").into_owned(),
+ bitbox_i18n::tr!(language, "None of them").into_owned(),
));
choices.len() - 1
};
loop {
match hal_ui.menu(&as_str_vec(&choices), Some(title)).await {
Err(UserAbort) => return Err(UserAbort),
Ok(choice_idx) if choice_idx as usize == none_of_them_idx => {
- let body =
- crate::i18n::translate(language, "Invalid. Check\nrecovery words.\nRestart?");
+ let body = bitbox_i18n::tr!(language, "Invalid. Check\nrecovery words.\nRestart?");
let params = ConfirmParams {
title: "",
body: &body,
@@ -286,7 +285,7 @@ pub async fn get_with_language(
hal_ui: &mut impl crate::hal::Ui,
language: Language,
) -> Result<zeroize::Zeroizing<String>, UserAbort> {
- let how_many_words = crate::i18n::translate(language, "How many words?");
+ let how_many_words = bitbox_i18n::tr!(language, "How many words?");
let num_words: usize = match hal_ui
.trinary_choice(&how_many_words, Some("12"), None, Some("24"))
.await
@@ -296,7 +295,7 @@ pub async fn get_with_language(
TrinaryChoice::Right => 24,
};
- let body = crate::i18n::format(language, "Enter {} words", &[&num_words.to_string()]);
+ let body = bitbox_i18n::format!(language, "Enter {} words", &[&num_words.to_string()]);
hal_ui.status(&body, true).await;
// Provide all bip39 words to restrict the keyboard entry.
@@ -305,7 +304,7 @@ pub async fn get_with_language(
let mut word_idx: usize = 0;
let mut entered_words = vec![zeroize::Zeroizing::new(String::new()); num_words];
while word_idx < num_words {
- let title = crate::i18n::format(
+ let title = bitbox_i18n::format!(
language,
"{} of {}",
&[&(word_idx + 1).to_string(), &num_words.to_string()],
@@ -365,9 +364,9 @@ pub async fn get_with_language(
// previous word and we go straight to the cancel action.
WordlistEntryAbort::Unspecified if word_idx == 0 => GetWordError::Cancel,
WordlistEntryAbort::Unspecified => {
- let edit_previous = crate::i18n::translate(language, "Edit previous word");
- let cancel_restore = crate::i18n::translate(language, "Cancel restore");
- let choose = crate::i18n::translate(language, "Choose");
+ let edit_previous = bitbox_i18n::tr!(language, "Edit previous word");
+ let cancel_restore = bitbox_i18n::tr!(language, "Cancel restore");
+ let choose = bitbox_i18n::tr!(language, "Choose");
let choices = [edit_previous.as_ref(), cancel_restore.as_ref()];
match hal_ui.menu(&choices, Some(choose.as_ref())).await {
Err(UserAbort) => {
@@ -384,8 +383,8 @@ pub async fn get_with_language(
match cancel_choice {
GetWordError::EditPrevious => word_idx -= 1,
GetWordError::Cancel => {
- let title = crate::i18n::translate(language, "Restore");
- let body = crate::i18n::translate(language, "Cancel restore?");
+ let title = bitbox_i18n::tr!(language, "Restore");
+ let body = bitbox_i18n::tr!(language, "Cancel restore?");
let params = ConfirmParams {
title: &title,
body: &body,
### src/rust/bitbox02/src/hal/ui.rs
@@ -152,9 +152,9 @@ impl<Timer: bitbox_hal::timer::Timer> Ui for BitBox02Ui<Timer> {
async fn confirm_swap(&mut self, title: &str, from: &str, to: &str) -> Result<(), UserAbort> {
if !crate::ui::transaction_amount_fits(from) || !crate::ui::transaction_amount_fits(to) {
let language = crate::memory::get_device_language();
- let from_title = crate::i18n::format(language, "{} from", &[title]);
+ let from_title = bitbox_i18n::format!(language, "{} from", &[title]);
self.review_value(&from_title, from, false).await?;
- let to_title = crate::i18n::format(language, "{} to", &[title]);
+ let to_title = bitbox_i18n::format!(language, "{} to", &[title]);
return self.review_value(&to_title, to, false).await;
}
match crate::ui::confirm_swap(title, from, to).await {
@@ -166,9 +166,9 @@ impl<Timer: bitbox_hal::timer::Timer> Ui for BitBox02Ui<Timer> {
#[inline(always)]
async fn verify_recipient(&mut self, recipient: &str, amount: &str) -> Result<(), UserAbort> {
if !crate::ui::transaction_amount_fits(amount) {
- let title = crate::i18n::translate_current("Amount");
+ let title = bitbox_i18n::tr!(crate::memory::get_device_language(), "Amount");
self.review_value(&title, amount, false).await?;
- let title = crate::i18n::translate_current("Recipient");
+ let title = bitbox_i18n::tr!(crate::memory::get_device_language(), "Recipient");
return self.review_value(&title, recipient, false).await;
}
match crate::ui::confirm_transaction_address(amount, recipient).await {
@@ -185,9 +185,9 @@ impl<Timer: bitbox_hal::timer::Timer> Ui for BitBox02Ui<Timer> {
longtouch: bool,
) -> Result<(), UserAbort> {
if !crate::ui::transaction_amount_fits(total) || !crate::ui::transaction_fee_fits(fee) {
- let title = crate::i18n::translate_current("Total");
+ let title = bitbox_i18n::tr!(crate::memory::get_device_language(), "Total");
self.review_value(&title, total, false).await?;
- let title = crate::i18n::translate_current("Fee");
+ let title = bitbox_i18n::tr!(crate::memory::get_device_language(), "Fee");
return self.review_value(&title, fee, longtouch).await;
}
match crate::ui::confirm_transaction_fee(total, fee, longtouch).await {
@@ -284,7 +284,8 @@ impl<Timer: bitbox_hal::timer::Timer> Ui for BitBox02Ui<Timer> {
}
async fn show_mnemonic(&mut self, words: &[&str]) -> Result<(), UserAbort> {
- let cancel_confirm_title = crate::i18n::translate_current("Recovery\nwords");
+ let cancel_confirm_title =
+ bitbox_i18n::tr!(crate::memory::get_device_language(), "Recovery\nwords");
match crate::ui::menu(crate::ui::MenuParams {
words,
title: None,
@@ -301,7 +302,8 @@ impl<Timer: bitbox_hal::timer::Timer> Ui for BitBox02Ui<Timer> {
}
async fn quiz_mnemonic_word(&mut self, choices: &[&str], title: &str) -> Result<u8, UserAbort> {
- let cancel_confirm_title = crate::i18n::translate_current("Recovery\nwords");
+ let cancel_confirm_title =
+ bitbox_i18n::tr!(crate::memory::get_device_language(), "Recovery\nwords");
match crate::ui::menu(crate::ui::MenuParams {
words: choices,
title: Some(title),
### src/rust/bitbox02/src/i18n.rs
@@ -4,6 +4,7 @@ use core::ffi::{c_char, c_void};
pub use bitbox_i18n::{format, language_code, language_from_code, translate};
+#[allow(clippy::disallowed_methods)]
pub fn translate_current<'a>(english: &'a str) -> alloc::borrow::Cow<'a, str> {
translate(crate::memory::get_device_language(), english)
}
@@ -13,6 +14,7 @@ pub fn translate_current<'a>(english: &'a str) -> alloc::borrow::Cow<'a, str> {
/// `input` must be a valid, null-terminated string pointer. `output` must be a valid pointer to a
/// buffer of at least `output_len` bytes.
#[unsafe(no_mangle)]
+#[allow(clippy::disallowed_methods)]
pub unsafe extern "C" fn rust_i18n_translate_copy(
input: *const c_char,
output: *mut c_char,
### src/rust/bitbox02/src/ui/ui.rs
@@ -541,7 +541,10 @@ pub async fn menu(params: MenuParams<'_>) -> MenuResponse {
MenuResponse::Cancel => match cancel_confirm_title {
None => return MenuResponse::Cancel,
Some(title) => {
- let body = crate::i18n::translate_current("Do you really\nwant to cancel?");
+ let body = bitbox_i18n::tr!(
+ crate::memory::get_device_language(),
+ "Do you really\nwant to cancel?"
+ );
// `ConfirmResponse::Cancelled` means _do not cancel_,
// stay in the same menu component.
match confirm(&ConfirmParams {Why this scored 29/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.