From 939ded3e3d69737f4c9e83cb2e20c8a9a8652c35 Mon Sep 17 00:00:00 2001 From: cdhdt Date: Mon, 2 Nov 2026 13:13:12 +0100 Subject: [PATCH] craft-update: a translator given after the prompt opened reaches it (review) Updater::with_translator stored the function for later prompts only; a prompt already open kept the old one. It now also sets the open prompt's. --- crates/update/src/updater.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/crates/update/src/updater.rs b/crates/update/src/updater.rs index 8747b898..b2a58d78 100644 --- a/crates/update/src/updater.rs +++ b/crates/update/src/updater.rs @@ -129,6 +129,10 @@ impl Updater { #[must_use] pub fn with_translator(mut self, translate: Translate) -> Self { self.translate = translate; + // A prompt already open (an offer made before) speaks the new language from its next draw. + if let Some(prompt) = &mut self.prompt { + prompt.translate = translate; + } self } @@ -601,6 +605,26 @@ mod tests { assert!(u.prompt.as_ref().is_some_and(|p| p.message().is_some())); } + /// A translator given after the prompt opened reaches it too. + #[test] + fn a_translator_given_later_reaches_the_open_prompt() { + fn shout(text: &str, args: &[(&str, &str)]) -> String { + crate::translate::fill(&text.to_uppercase(), args) + } + let ctx = egui::Context::default(); + let mut u = updater(Ok(None)); + u.offer(newer()); + u.request_install(&ctx, false); + let mut u = u.with_translator(shout); + let message = |u: &Updater| u.prompt.as_ref().and_then(StartupPrompt::message).unwrap_or_default(); + assert!(message(&u).starts_with("SAVE OR CLOSE"), "{}", message(&u)); + // And the prompts it opens later. + u.prompt = None; + u.offer(newer()); + u.request_install(&ctx, false); + assert!(message(&u).starts_with("SAVE OR CLOSE"), "{}", message(&u)); + } + /// The updater's own failures (a dropped or panicking worker) are in the interface language; /// the installer's are shown as they came. #[test]