mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-09 03:51:47 +00:00
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.
This commit is contained in:
1 parent
76e2bb0eb9
commit
939ded3e3d
1 file changed
+24
@@ -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]
|
||||
|
||||
Reference in new issue
Block a user