Global Light: drop the engine's "not available" wrapper before the reason in every status (#14807)

A failed action step on a greyed command showed the English "command `id`
is not available right now: " wrapper (and the id twice) before the
translated reason. translated_refusal now leaves out the wrapper that
directly precedes the reason; outer text such as "action `X` step N
failed: " stays, and the run status uses the same function.
Test: a failed Brightness/Contrast or Global Light step shows
"Step 1 (id) failed: <translation>" with no "command `", and a nested
action failure keeps its outer text. The test the_gui_key_is_the_engines_reason
was removed earlier (it only compared a constant to a literal).
This commit is contained in:
SBaksa committed 2026-11-28 07:06:05 -05:00
1 parent 87570f64d6
commit 21da2fda73
2 files changed
+37 -8

No files matched your search

+13 -8
View File
@@ -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<String> {
@@ -459,7 +464,7 @@ pub(crate) fn translated_refusal(error: &str) -> Option<String> {
[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)))
})
}
@@ -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);
}
}