FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
Translate graphics and effect control accessibility labels
skylar taylor-barrick403b823ce43e
diff --git a/crates/ui-egui/src/panels/effect_controls.rs b/crates/ui-egui/src/panels/effect_controls.rsindex 6a9b98f0d..aa1ab03c9 100644--- a/crates/ui-egui/src/panels/effect_controls.rs+++ b/crates/ui-egui/src/panels/effect_controls.rs@@ -680,7 +680,7 @@ pub(crate) fn param_row((ParamKind::Text, ParamValue::Text(s)) if !pd.id.ends_with("_lut") => {// edited in a buffer; committed (one undo step) when the field loses focuslet mut buf = vui.data_mut(|d| d.get_temp::<String>(id)).unwrap_or_else(|| s.clone());- let r = crate::widgets::accessible_name(vui.add(egui::TextEdit::singleline(&mut buf).desired_width(160.0)), pd.label);+ let r = crate::widgets::accessible_name(vui.add(egui::TextEdit::singleline(&mut buf).desired_width(160.0)), crate::i18n::t(pd.label));app.auto.add(&format!("effectControls.text.{}.{}", idx, pd.id), r.rect, pd.label);if r.lost_focus() {if buf != *s {diff --git a/crates/ui-egui/src/panels/graphics.rs b/crates/ui-egui/src/panels/graphics.rsindex a41a7b7fd..9bce6b83a 100644--- a/crates/ui-egui/src/panels/graphics.rs+++ b/crates/ui-egui/src/panels/graphics.rs@@ -2363,7 +2363,7 @@ impl Ctx<'_> {self.set(id, json!(format!("#{r8:02x}{g8:02x}{b8:02x}")));}}- fn choice(&mut self, vui: &mut egui::Ui, id: &str, opts: &[&str], width: f32) {+ fn choice(&mut self, vui: &mut egui::Ui, id: &str, label: &str, opts: &[&str], width: f32) {let cur = match pv(self.e, id, self.mt) {ParamValue::Choice(c) => c as usize,_ => 0,@@ -2377,7 +2377,7 @@ impl Ctx<'_> {ui.selectable_value(&mut sel, i, crate::i18n::t(o));}});- let response = crate::widgets::accessible_name(r.response, id);+ let response = crate::widgets::accessible_name(r.response, label);self.auto(id, response.rect, id);if sel != cur {self.set(id, json!(sel));@@ -2799,7 +2799,7 @@ pub fn properties(app: &mut FilmcraftApp, ui: &mut egui::Ui, rect: Rect) {}if e.effect == graphic::SHAPE_LAYER && section(ui, app, "Shape", &t) {let (_, mut vui) = cx.row(ui, tl!("Shape"));- cx.choice(&mut vui, "shape", graphic::SHAPE_OPTS, 120.0);+ cx.choice(&mut vui, "shape", tl!("Shape"), graphic::SHAPE_OPTS, 120.0);cx.point(ui, tl!("Size"), "size");cx.number(ui, tl!("Corner Radius"), "corner_radius", 0.5, (0.0, 10_000.0), 0, "");cx.number(ui, tl!("Polygon Sides"), "sides", 0.05, (3.0, 64.0), 0, "");@@ -2811,7 +2811,7 @@ pub fn properties(app: &mut FilmcraftApp, ui: &mut egui::Ui, rect: Rect) {cx.color(&mut vui, "fill_color");if fill_on {vui.add_space(6.0);- cx.choice(&mut vui, "fill_kind", graphic::FILL_KIND_OPTS, 130.0);+ cx.choice(&mut vui, "fill_kind", tl!("Fill Type"), graphic::FILL_KIND_OPTS, 130.0);}let fill_kind = match pv(e, "fill_kind", mt) {ParamValue::Choice(c) => c,@@ -2823,17 +2823,17 @@ pub fn properties(app: &mut FilmcraftApp, ui: &mut egui::Ui, rect: Rect) {cx.color(&mut vui, "gradient_end");cx.number(ui, tl!(" Angle"), "gradient_angle", 0.5, (-3600.0, 3600.0), 0, " °");}- for (on, col, w, kind, label) in [- ("stroke", "stroke_color", "stroke_width", "stroke_type", tl!("Stroke")),- ("stroke2", "stroke2_color", "stroke2_width", "stroke2_type", tl!("Stroke 2")),+ for (on, col, w, kind, label, width_label, type_label) in [+ ("stroke", "stroke_color", "stroke_width", "stroke_type", tl!("Stroke"), tl!("Stroke Width"), tl!("Stroke Type")),+ ("stroke2", "stroke2_color", "stroke2_width", "stroke2_type", tl!("Stroke 2"), tl!("Stroke 2 Width"), tl!("Stroke 2 Type")),] {let (_, mut vui) = cx.row(ui, label);cx.check(&mut vui, on, "");cx.color(&mut vui, col);vui.add_space(6.0);- cx.number_in(&mut vui, &format!("{label} width"), NumberField { id: w, speed: 0.2, range: (0.0, 1000.0), decimals: 1, unit: "" });+ cx.number_in(&mut vui, width_label, NumberField { id: w, speed: 0.2, range: (0.0, 1000.0), decimals: 1, unit: "" });vui.add_space(6.0);- cx.choice(&mut vui, kind, graphic::STROKE_OPTS, 70.0);+ cx.choice(&mut vui, kind, type_label, graphic::STROKE_OPTS, 70.0);}let (_, mut vui) = cx.row(ui, tl!("Background"));let bg = cx.check(&mut vui, "background", "");diff --git a/crates/ui-egui/tests/it/graphics_ui.rs b/crates/ui-egui/tests/it/graphics_ui.rsindex fffa7a1d9..fe3c3e2d0 100644--- a/crates/ui-egui/tests/it/graphics_ui.rs+++ b/crates/ui-egui/tests/it/graphics_ui.rs@@ -7,7 +7,9 @@use std::sync::mpsc::{Sender, channel};+use egui::accesskit::Role;use egui_kittest::Harness;+use egui_kittest::kittest::Queryable;use filmcraft_engine::Session;use filmcraft_ui_egui::FilmcraftApp;use filmcraft_ui_egui::control::ControlRequest;@@ -153,6 +155,93 @@ fn type_tool_edit_style_and_move() {d.shot("shape-layer");}+/// Properties-panel choice and stroke-width accessible names follow the interface language, while+/// the automation ids and the values shown stay those of the property.+#[test]+fn choice_and_stroke_width_accessible_names_follow_language() {+ let mut d = Driver::demo();+ d.ok("ui.set", json!({"workspace": "Captions and Graphics"}));+ let clip = d.exec("graphics.newShape", json!({"shape": "rectangle", "position": [800, 500], "size": [500, 300]}))["clip"].as_u64().unwrap();+ d.exec("graphics.selectLayer", json!({"clip": clip, "layers": [0]}));+ d.frames(4);++ assert_eq!(d.harness.get_by_role_and_label(Role::ComboBox, "Shape").value().as_deref(), Some("Rectangle"));++ d.exec("prefs.set", json!({"key": "general.interfaceLanguage", "value": "es"}));+ d.frames(4);+ let es = filmcraft_ui_egui::i18n::Language::Es;+ for (label, value) in [("Shape", "Rectangle"), ("Fill Type", "Solid"), ("Stroke Type", "Outer"), ("Stroke 2 Type", "Outer")] {+ assert_eq!(+ d.harness.get_by_role_and_label(Role::ComboBox, es.tr(label)).value().as_deref(),+ Some(es.tr(value)),+ "{label} keeps its translated name and selected value"+ );+ }++ // The widget still writes the property it names, and its automation id does not change.+ d.exec("graphics.set", json!({"clip": clip, "layer": 0, "props": {"shape": "ellipse", "stroke2_type": "center"}}));+ d.frames(4);+ assert_eq!(d.harness.get_by_role_and_label(Role::ComboBox, es.tr("Shape")).value().as_deref(), Some(es.tr("Ellipse")));+ assert_eq!(d.harness.get_by_role_and_label(Role::ComboBox, es.tr("Stroke 2 Type")).value().as_deref(), Some(es.tr("Center")));+ let ids: Vec<String> =+ d.ok("ui.elements", json!({"prefix": "graphics.prop."})).as_array().unwrap().iter().filter_map(|e| e["id"].as_str().map(str::to_string)).collect();+ for id in ["graphics.prop.shape", "graphics.prop.fill_kind", "graphics.prop.stroke_type", "graphics.prop.stroke2_type"] {+ assert!(ids.iter().any(|i| i == id), "{id} is still registered: {ids:?}");+ }++ // Each stroke width opens its editor under the complete translated catalog entry, not an+ // English " width" suffix appended to a translated label.+ for _ in 0..20 {+ if d.rect("graphics.prop.stroke_width")[1] < 900.0 {+ break;+ }+ d.ok("ui.scroll", json!({"id": "graphics.prop.shape", "dy": -200.0}));+ d.frames(2);+ }+ d.ok("ui.click", json!({"id": "graphics.prop.stroke_width"}));+ d.frames(3);+ assert_eq!(+ d.harness.get_by_role_and_label(Role::TextInput, es.tr("Stroke Width")).value().as_deref(),+ Some("4.0"),+ "the first stroke width editor has the translated label"+ );+ d.ok("ui.click", json!({"id": "graphics.prop.stroke2_width"}));+ d.frames(3);+ assert_eq!(+ d.harness.get_by_role_and_label(Role::TextInput, es.tr("Stroke 2 Width")).value().as_deref(),+ Some("10.0"),+ "the second stroke width editor has its own translated label"+ );+ filmcraft_ui_egui::i18n::set_current(filmcraft_ui_egui::i18n::Language::En);+}++/// Effect Controls' Text parameter (graphic layers' Source Text / name / font fields) names its+/// text editor with the translated parameter label, like the boolean and choice arms.+#[test]+fn effect_controls_text_accessible_name_follows_language() {+ let mut d = Driver::demo();+ d.ok("ui.set", json!({"workspace": "Captions and Graphics"}));+ let clip = d.exec("graphics.newText", json!({"text": "Night Drive"}))["clip"].as_u64().unwrap();+ d.exec("timeline.select", json!({"clips": [clip]}));+ d.ok("ui.panel.show", json!({"panel": "Effect Controls"}));+ d.frames(4);++ d.exec("prefs.set", json!({"key": "general.interfaceLanguage", "value": "es"}));+ d.frames(4);+ let es = filmcraft_ui_egui::i18n::Language::Es;+ assert_eq!(+ d.harness.get_by_role_and_label(Role::TextInput, es.tr("Source Text")).value().as_deref(),+ Some("Night Drive"),+ "the translated accessible name and the same value"+ );+ let elements = d.ok("ui.elements", json!({"prefix": "effectControls.text."}));+ assert!(+ elements.as_array().unwrap().iter().any(|e| e["id"].as_str().is_some_and(|id| id.ends_with(".text"))),+ "the Source Text automation id is unchanged: {elements}"+ );+ filmcraft_ui_egui::i18n::set_current(filmcraft_ui_egui::i18n::Language::En);+}+/// The value of `param` on the text layer of graphic clip `clip`, at its first frame.fn text_param(d: &mut Driver, clip: u64, param: &str) -> Option<filmcraft_project::ParamValue> {let s = &d.harness.state().session;