diff --git a/crates/ui-egui/src/app/commands.rs b/crates/ui-egui/src/app/commands.rs index be0f03cac9..9222714853 100644 --- a/crates/ui-egui/src/app/commands.rs +++ b/crates/ui-egui/src/app/commands.rs @@ -438,19 +438,24 @@ const ADDS_LAYER_MASK: [&str; 5] = [ "layer.layerMask.fromTransparency", ]; -/// The status line of a failed command run: the refusal in the interface language, without the engine's -/// "command `id` is not available right now: " wrapper (the status names the reason, not the command id), and any -/// other error as the engine gave it. +/// The status line of a failed command run: the refusal in the interface language (see [`translated_refusal`], which +/// leaves out the engine's wrapper), and any other error as the engine gave it. pub(crate) fn refusal_status(error: &str) -> String { - let reason = error.strip_prefix("command `").and_then(|rest| rest.split_once("` is not available right now: ")).map_or(error, |(_, reason)| reason); - translated_refusal(reason).unwrap_or_else(|| error.to_string()) + translated_refusal(error).unwrap_or_else(|| error.to_string()) +} + +/// `before` (the text ahead of a refusal) without the engine's "command `id` is not available right now: " wrapper +/// that directly precedes the refusal: the status names the reason, not the command id, and the wrapper is English. +/// Outer text such as "action `X` step N failed: " stays. +fn without_wrapper(before: &str) -> &str { + before.strip_suffix("` is not available right now: ").and_then(|head| head.rfind("command `")).and_then(|at| before.get(..at)).unwrap_or(before) } /// The engine refusal in `error` that the status bar shows in the interface language: Brightness/ /// Contrast's hidden and empty layer alerts (#14359) and Global Light's Background-only reason (#14681), /// alone or at the end of a longer message after a `: ` (a greyed command's reason, a failed action -/// step, a batch's first failure). What comes before the refusal is kept as it was; only the refusal -/// is translated. The command's own error keeps the English text for automation. Global Light's reason +/// step, a batch's first failure). What comes before the refusal is kept as it was, except the engine's +/// "command `id` is not available right now: " wrapper; only the refusal is translated. The command's own error keeps the English text for automation. Global Light's reason /// is spelled out so `cargo xtask i18n-coverage` lists it; the Brightness/Contrast alerts are the engine's /// constants and are looked up as they are. pub(crate) fn translated_refusal(error: &str) -> Option { @@ -459,7 +464,7 @@ pub(crate) fn translated_refusal(error: &str) -> Option { [BRIGHTNESS_CONTRAST_UNAVAILABLE, BRIGHTNESS_CONTRAST_EMPTY, GLOBAL_LIGHT_BACKGROUND_ONLY].into_iter().find_map(|reason| { let before = error.strip_suffix(reason).filter(|before| before.is_empty() || before.ends_with(": "))?; let text = if reason == GLOBAL_LIGHT_BACKGROUND_ONLY { tl!("the document has only the Background layer") } else { tl!(reason) }; - Some(format!("{before}{text}")) + Some(format!("{}{text}", without_wrapper(before))) }) } diff --git a/crates/ui-egui/src/global_light_refusal_translation_tests.rs b/crates/ui-egui/src/global_light_refusal_translation_tests.rs index 60b23bfdab..5d79322c15 100644 --- a/crates/ui-egui/src/global_light_refusal_translation_tests.rs +++ b/crates/ui-egui/src/global_light_refusal_translation_tests.rs @@ -80,3 +80,27 @@ fn a_greyed_brightness_contrast_run_shows_only_the_translated_alert() { assert!(result.unwrap_err().ends_with(alert), "the engine keeps the English alert"); assert_eq!(app.ui.status, "Commande indisponible"); } + +/// A failed action step on a greyed command shows the translated reason without the engine's "command `id` is not +/// available right now: " wrapper (the step line already names the command), while the outer text of a nested +/// action failure stays. +#[test] +fn a_failed_step_on_a_greyed_command_drops_the_engine_wrapper() { + let mut app = background_app(); + let alert = photocraft_engine::adjust_cmds::BRIGHTNESS_CONTRAST_UNAVAILABLE; + let catalog: &'static str = format!("\t{alert}\tCommande indisponible\n{CATALOG}").leak(); + let french = crate::i18n::fixture_lang("fr", catalog); + let cases = + [("image.adjustments.brightnessContrast", alert, "Commande indisponible"), (GLOBAL_LIGHT, ENGLISH, "le document n'a que le calque d'arrière-plan")]; + for (id, reason, shown) in cases { + let error = format!("command `{id}` is not available right now: {reason}"); + let failed = json!({"failed": {"step": 0, "id": id, "error": error}}); + crate::i18n::with_language(french, || crate::actions::report_play(&mut app, &failed)); + assert_eq!(app.ui.status, format!("Step 1 ({id}) failed: {shown}")); + assert!(!app.ui.status.contains("command `"), "{}", app.ui.status); + let nested = json!({"failed": {"step": 0, "id": "actions.play", "error": format!("action `Inner` step 2 failed: {error}")}}); + crate::i18n::with_language(french, || crate::actions::report_play(&mut app, &nested)); + assert!(app.ui.status.ends_with(&format!("action `Inner` step 2 failed: {shown}")), "{}", app.ui.status); + assert!(!app.ui.status.contains("is not available right now"), "{}", app.ui.status); + } +}