From 23ad007760b5933fab2c19ad6a9fa5bc4ce0d7dd Mon Sep 17 00:00:00 2001 From: Tanish Manku Date: Tue, 10 Nov 2026 13:34:27 -0700 Subject: [PATCH] feat(ui): translate the sound envelope editor, layer volume and mute, and show the real Undo key in messages (M8) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The strings from sound effects (#100) and the ActionScript Script view (#99) go through tr!/trn!; the envelope editor joins the pseudo-locale accessibility audit. Messages that said "Ctrl+Z" now fill {undo} from App::undo_key (the rebindable Undo key, through platform::shortcut_label, so macOS reads ⌘Z). ADR 0040 leaves the reservations table. --- CHANGELOG.md | 2 ++ docs/adr/README.md | 1 - src/actions_panel.rs | 24 ++++++------- src/app.rs | 30 +++++++++------- src/camera_tool.rs | 2 +- src/envelope.rs | 82 ++++++++++++++++++++++---------------------- src/erasertool.rs | 6 ++-- src/i18n/mod.rs | 3 -- src/i18n/tests.rs | 6 +++- src/motion_editor.rs | 2 +- src/motion_path.rs | 4 +-- src/panels.rs | 20 +++++------ src/pathtools.rs | 2 +- src/plugins_ui.rs | 6 ++-- src/shape_hints.rs | 2 +- src/stage.rs | 2 +- src/timeline.rs | 14 ++++---- src/widthtool.rs | 4 +-- 18 files changed, 110 insertions(+), 102 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eaf6a81c..67ef9c26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ translators (and, with a craft-i18n checkout, how much each language already covers). * A **pseudo-locale** (`--lang pseudo`) draws everything accented, longer and bracketed, to find text that skipped translation or gets cut off. + * Messages that say how to undo show your Undo key as this computer writes it (⌘Z on a + Mac, and a rebound key wherever it is), instead of a fixed "Ctrl+Z". * Menus, the command palette and the shortcut sheet translate the command registry's labels as they are drawn; command ids, `.anicraft` files, `anicraft-cli` and MCP stay English. * For developers: `tr!`, `trn!` (plurals by CLDR rules), `trc!` and `tr_noop!`; a test fails diff --git a/docs/adr/README.md b/docs/adr/README.md index 209745e9..3e64e592 100644 --- a/docs/adr/README.md +++ b/docs/adr/README.md @@ -23,7 +23,6 @@ has to renumber because another PR merged first. | Number | Pull request | Topic | |---|---|---| | 0037 | #38 (outside contribution) | Interface languages | -| 0040 | branch `m8/localisation` (PR to come) | Localisation of the interface | | 0041 | branch `m1/raw-selection` (PR to come) | Selection tool on raw drawings (issue #42) | | 0042 | branch `m1/raw-subselection` (PR to come) | Subselection on raw drawings, merging everywhere (issue #42) | | 0043 | branch `m7/bones` (PR to come) | Bone tool and inverse kinematics | diff --git a/src/actions_panel.rs b/src/actions_panel.rs index cf852d22..50e3c90d 100644 --- a/src/actions_panel.rs +++ b/src/actions_panel.rs @@ -266,7 +266,7 @@ fn switch_kind(app: &mut App, t: &FrameTarget, from: Holds, to: Holds) { Holds::Plugin => { if let Some((id, entry)) = frame_scripts(app).first().map(|(id, _, e)| (id.clone(), e.first().cloned().unwrap_or_else(|| "main".into()))) { set_frame(app, &t.base, json!({"plugin": id, "entry": entry})); - app.status_ok(tr!("Frame script set — Ctrl+Z to undo")); + app.status_ok(tr!("Frame script set — {undo} to undo", undo = app.undo_key())); } else { app.status_err(tr!("No frame-script plug-ins are installed (Commands › Install Plug-in…)")); } @@ -282,9 +282,9 @@ fn switch_kind(app: &mut App, t: &FrameTarget, from: Holds, to: Holds) { } if had { let removed = match from { - Holds::Actions => tr!("Removed the actions — Ctrl+Z to undo"), - Holds::Plugin => tr!("Removed the plug-in frame script — Ctrl+Z to undo"), - Holds::Script => tr!("Removed the script — Ctrl+Z to undo"), + Holds::Actions => tr!("Removed the actions — {undo} to undo", undo = app.undo_key()), + Holds::Plugin => tr!("Removed the plug-in frame script — {undo} to undo", undo = app.undo_key()), + Holds::Script => tr!("Removed the script — {undo} to undo", undo = app.undo_key()), }; app.status_ok(removed); } @@ -361,7 +361,7 @@ fn script_view(app: &mut App, ui: &mut egui::Ui, t: &FrameTarget, src: Option<&S ui.label(text(Type::Caption, tr!("Kept with the document as written. AniCraft doesn't run scripts yet: Test Movie and exports skip it. Use actions for what should happen while the movie plays."))); if src.is_some() && ui.small_button(tr!("Remove script")).on_hover_text(tr!("Delete this keyframe's script")).clicked() { app.run("script.clear", t.base.clone()); - app.status_ok(tr!("Removed the script — Ctrl+Z to undo")); + app.status_ok(tr!("Removed the script — {undo} to undo", undo = app.undo_key())); } } @@ -518,7 +518,7 @@ fn instance_tab(app: &mut App, ui: &mut egui::Ui, e: &Element) { ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { if ui.small_button(tr!("Remove event")).clicked() { app.run("actions.clear", json!({"element": e.id.0, "event": h.event.key()})); - app.status_ok(event_removed(h.event)); + app.status_ok(event_removed(h.event, &app.undo_key())); } }); }); @@ -554,13 +554,13 @@ fn event_heading(ev: ButtonEvent) -> &'static str { } /// The status message after an event is removed: one sentence per event. -fn event_removed(ev: ButtonEvent) -> &'static str { +fn event_removed(ev: ButtonEvent, undo: &str) -> String { match ev { - ButtonEvent::Click => tr!("Removed the click event — Ctrl+Z to undo"), - ButtonEvent::Press => tr!("Removed the press event — Ctrl+Z to undo"), - ButtonEvent::Release => tr!("Removed the release event — Ctrl+Z to undo"), - ButtonEvent::Over => tr!("Removed the pointer over event — Ctrl+Z to undo"), - ButtonEvent::Out => tr!("Removed the pointer out event — Ctrl+Z to undo"), + ButtonEvent::Click => tr!("Removed the click event — {undo} to undo", undo = undo), + ButtonEvent::Press => tr!("Removed the press event — {undo} to undo", undo = undo), + ButtonEvent::Release => tr!("Removed the release event — {undo} to undo", undo = undo), + ButtonEvent::Over => tr!("Removed the pointer over event — {undo} to undo", undo = undo), + ButtonEvent::Out => tr!("Removed the pointer out event — {undo} to undo", undo = undo), } } diff --git a/src/app.rs b/src/app.rs index c8135bdf..3c8793d2 100644 --- a/src/app.rs +++ b/src/app.rs @@ -529,6 +529,12 @@ impl App { } } + /// The Undo key as this computer shows it (rebindable; ⌘Z on macOS), for messages that + /// say how to undo. + pub fn undo_key(&self) -> String { + platform::shortcut_label(self.keymap.primary("edit.undo").unwrap_or("Ctrl+Z")) + } + pub fn status_ok(&mut self, text: impl Into) { self.status = Some(Status { text: text.into(), error: false, at: 0.0 }); } @@ -1056,7 +1062,7 @@ impl App { self.run("motion.add_point", json!({"segment": 2, "t": 0.45})); self.run("motion.convert_point", json!({"anchor": 1, "smooth": false})); self.motion_anchors = vec![1, 2]; - self.status_ok(tr!("Added a point to the motion path. {undo} to undo.", undo = platform::shortcut_label("Ctrl+Z"))); + self.status_ok(tr!("Added a point to the motion path. {undo} to undo.", undo = self.undo_key())); } } Some("pen") => { @@ -1148,7 +1154,7 @@ impl App { let name = v["name"].as_str().unwrap_or(""); let secs = format!("{:.2}", v["seconds"].as_f64().unwrap_or(0.0)); self.status_ok(if v.get("layer").is_some() { - tr!("{name} ({secs} s) is on a new layer from frame {frame}. Set its sync in Properties. Ctrl+Z to undo.", name = name, secs = secs, frame = self.s.frame + 1) + tr!("{name} ({secs} s) is on a new layer from frame {frame}. Set its sync in Properties. {undo} to undo.", name = name, secs = secs, frame = self.s.frame + 1, undo = self.undo_key()) } else { tr!("{name} ({secs} s) is in the Library. Select a keyframe and pick it under Sound in Properties.", name = name, secs = secs) }); @@ -1159,14 +1165,14 @@ impl App { let (path, secs) = (v["written"].as_str().unwrap_or(""), format!("{:.2}", v["seconds"].as_f64().unwrap_or(0.0))); self.status_ok(if n == 0 { tr!("Exported {path} ({secs} s). No sounds play in that range, so the file is silent.", path = path, secs = secs) } else { tr!("Exported {path} ({secs} s).", path = path, secs = secs) }); } - "sound.delete" => self.status_ok(tr!("Deleted sound — Ctrl+Z to undo")), + "sound.delete" => self.status_ok(tr!("Deleted sound — {undo} to undo", undo = self.undo_key())), "file.import" => { if let Some(b) = self.s.doc.bitmaps.last().filter(|b| v["bitmap"].as_u64() == Some(b.id.0)) { self.library_sel = Some(LibraryItem::Bitmap(b.id)); } let n = v["elements"].as_u64().unwrap_or(0); let report = v["report"].as_str().unwrap_or(""); - let undo = tr!("{undo} to undo.", undo = platform::shortcut_label("Ctrl+Z")); + let undo = tr!("{undo} to undo.", undo = self.undo_key()); // A drawing with clip paths or masks comes in as a folder of layers (ADR 0021). let placed = match (v["layers"].as_u64().unwrap_or(1), v["masks"].as_u64().unwrap_or(0)) { (0 | 1, _) => trn!("{n} element on a new layer.", "{n} elements on a new layer.", n), @@ -1201,15 +1207,15 @@ impl App { // Undo labels are the engine's English, translated when a catalog has them. "edit.undo" => self.status_ok(tr!("Undid {action}", action = crate::i18n::t_dyn(v["undone"].as_str().unwrap_or("")))), "edit.redo" => self.status_ok(tr!("Redid {action}", action = crate::i18n::t_dyn(v["redone"].as_str().unwrap_or("")))), - "edit.delete" => self.status_ok(trn!("Deleted {n} element — Ctrl+Z to undo", "Deleted {n} elements — Ctrl+Z to undo", selected)), - "layer.delete" => self.status_ok(tr!("Deleted layer — Ctrl+Z to undo")), + "edit.delete" => self.status_ok(trn!("Deleted {n} element — {undo} to undo", "Deleted {n} elements — {undo} to undo", selected, undo = self.undo_key())), + "layer.delete" => self.status_ok(tr!("Deleted layer — {undo} to undo", undo = self.undo_key())), "draw.erase_all" => { let n = v["erased"].as_u64().unwrap_or(0); - self.status_ok(trn!("Erased everything at frame {frame} ({n} element). {undo} to undo.", "Erased everything at frame {frame} ({n} elements). {undo} to undo.", n, frame = self.s.frame + 1, undo = platform::shortcut_label("Ctrl+Z"))); + self.status_ok(trn!("Erased everything at frame {frame} ({n} element). {undo} to undo.", "Erased everything at frame {frame} ({n} elements). {undo} to undo.", n, frame = self.s.frame + 1, undo = self.undo_key())); } "scene.delete" => { self.frame_sel = None; - self.status_ok(tr!("Deleted scene — Ctrl+Z to undo")); + self.status_ok(tr!("Deleted scene — {undo} to undo", undo = self.undo_key())); } "scene.new" | "scene.duplicate" | "scene.select" | "scene.next" | "scene.prev" => { // Another scene's timeline: frame selections and scroll belong to the old one. @@ -1222,20 +1228,20 @@ impl App { } "timeline.clear_keyframe" => { let n = v["cleared"].as_u64().unwrap_or(1); - self.status_ok(if n == 1 { tr!("Cleared keyframe — Ctrl+Z to undo").to_string() } else { trn!("Cleared {n} keyframe — Ctrl+Z to undo", "Cleared {n} keyframes — Ctrl+Z to undo", n) }); + self.status_ok(if n == 1 { tr!("Cleared keyframe — {undo} to undo", undo = self.undo_key()).to_string() } else { trn!("Cleared {n} keyframe — {undo} to undo", "Cleared {n} keyframes — {undo} to undo", n, undo = self.undo_key()) }); } "timeline.copy_frames" | "timeline.cut_frames" | "timeline.paste_frames" => { let n = v["copied"].as_u64().or_else(|| v["cut"].as_u64()).or_else(|| v["pasted"].as_u64()).unwrap_or(0); self.status_ok(match id { "timeline.copy_frames" => trn!("Copied {n} frame", "Copied {n} frames", n), - "timeline.cut_frames" => trn!("Cut {n} frame — Ctrl+Z to undo", "Cut {n} frames — Ctrl+Z to undo", n), - _ => trn!("Pasted {n} frame — Ctrl+Z to undo", "Pasted {n} frames — Ctrl+Z to undo", n), + "timeline.cut_frames" => trn!("Cut {n} frame — {undo} to undo", "Cut {n} frames — {undo} to undo", n, undo = self.undo_key()), + _ => trn!("Pasted {n} frame — {undo} to undo", "Pasted {n} frames — {undo} to undo", n, undo = self.undo_key()), }); } "plugin.run" | "plugin.install" | "plugin.remove" | "plugin.reload" => crate::plugins_ui::status(self, id, &v), "timeline.remove_frame" => { let n = v["removed"].as_u64().unwrap_or(1); - self.status_ok(if n == 1 { tr!("Removed frame — Ctrl+Z to undo").to_string() } else { trn!("Removed {n} frame — Ctrl+Z to undo", "Removed {n} frames — Ctrl+Z to undo", n) }); + self.status_ok(if n == 1 { tr!("Removed frame — {undo} to undo", undo = self.undo_key()).to_string() } else { trn!("Removed {n} frame — {undo} to undo", "Removed {n} frames — {undo} to undo", n, undo = self.undo_key()) }); } _ => {} } diff --git a/src/camera_tool.rs b/src/camera_tool.rs index ff2200db..fb322a87 100644 --- a/src/camera_tool.rs +++ b/src/camera_tool.rs @@ -49,7 +49,7 @@ pub fn previewing(app: &App) -> bool { /// pick: undoing the add leaves the tool in hand without adding it again. pub fn on_tool_change(app: &mut App) { if app.tool == Tool::Camera && app.last_tool != Tool::Camera && app.s.doc.timeline(app.s.scene).camera_layer().is_none() && app.run("camera.add", json!({})).is_some() { - app.status_ok(tr!("Added a camera. Drag on the stage to pan it, turn it with the round handle, zoom with the wheel. Ctrl+Z to undo.")); + app.status_ok(tr!("Added a camera. Drag on the stage to pan it, turn it with the round handle, zoom with the wheel. {undo} to undo.", undo = app.undo_key())); } app.last_tool = app.tool; } diff --git a/src/envelope.rs b/src/envelope.rs index 713204b4..ab2125f4 100644 --- a/src/envelope.rs +++ b/src/envelope.rs @@ -45,7 +45,7 @@ pub struct EnvelopeEditor { pub fn open(app: &mut App) { let Some(layer) = app.s.active_layer() else { return }; let Some(k) = layer.keyframe_at(app.s.frame).filter(|k| k.sound.is_some()) else { - app.status_err("Select a keyframe with a sound to edit its envelope"); + app.status_err(tr!("Select a keyframe with a sound to edit its envelope")); return; }; let (layer, frame) = (layer.id, k.start); @@ -87,7 +87,7 @@ pub fn show(app: &mut App, ctx: &egui::Context) { // Closed when its keyframe or sound goes away (undo, delete). let Some(t) = target(app, &ed) else { return }; let mut open = true; - let title = format!("Edit Envelope — {}", t.sound.name); + let title = tr!("Edit Envelope — {name}", name = t.sound.name); let shown = egui::Window::new(title.clone()) .id(egui::Id::new("envelope_editor")) .open(&mut open) @@ -138,46 +138,46 @@ fn body(app: &mut App, ed: &mut EnvelopeEditor, ui: &mut egui::Ui, t: &Target) { let mut pts = points_of(t); // ---- effect, preview, zoom, units ---- ui.horizontal(|ui| { - ui.label(text(Type::Label, "Effect")); - egui::ComboBox::from_id_salt("envelope_effect").width(160.0).selected_text(t.fs.effect.label()).show_ui(ui, |ui| { + ui.label(text(Type::Label, tr!("Effect"))); + egui::ComboBox::from_id_salt("envelope_effect").width(160.0).selected_text(crate::i18n::t(t.fs.effect.label())).show_ui(ui, |ui| { for e in SoundEffect::PRESETS { - if ui.selectable_label(t.fs.effect == e, e.label()).on_hover_text(e.hint()).clicked() && t.fs.effect != e { + if ui.selectable_label(t.fs.effect == e, crate::i18n::t(e.label())).on_hover_text(crate::i18n::t(e.hint())).clicked() && t.fs.effect != e { app.run("sound.set", json!({"layer": ed.layer.0, "frame": ed.frame, "effect": e.key()})); ed.selected = None; } } let custom = matches!(t.fs.effect, SoundEffect::Custom(_)); - if ui.selectable_label(custom, "Custom").on_hover_text(SoundEffect::Custom(Vec::new()).hint()).clicked() && !custom { + if ui.selectable_label(custom, tr!("Custom")).on_hover_text(crate::i18n::t(SoundEffect::Custom(Vec::new()).hint())).clicked() && !custom { app.run("sound.set", json!({"layer": ed.layer.0, "frame": ed.frame, "effect": "custom"})); } }) .response - .set_name("Sound effect"); + .set_name(tr!("Sound effect")); ui.add_space(8.0); - if crate::timeline::icon_button(ui, "Play the sound with this envelope", None, Icon::Play).clicked() { + if crate::timeline::icon_button(ui, tr!("Play the sound with this envelope"), None, Icon::Play).clicked() { preview(app, t); } - if ui.small_button("Stop").on_hover_text("Stop the preview").clicked() { + if ui.small_button(tr!("Stop")).on_hover_text(tr!("Stop the preview")).clicked() { app.sound.stop(); } ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { - if ui.selectable_label(ed.frames, "Frames").on_hover_text("Read times in frames").clicked() { + if ui.selectable_label(ed.frames, tr!("Frames")).on_hover_text(tr!("Read times in frames")).clicked() { ed.frames = true; } - if ui.selectable_label(!ed.frames, "Seconds").on_hover_text("Read times in seconds").clicked() { + if ui.selectable_label(!ed.frames, tr!("Seconds")).on_hover_text(tr!("Read times in seconds")).clicked() { ed.frames = false; } ui.add_space(8.0); let total = total_seconds(t, &pts); let shown = ed.window.unwrap_or(total); - if ui.small_button("Fit").on_hover_text("Show the whole sound").named("Zoom to fit").clicked() { + if ui.small_button(tr!("Fit")).on_hover_text(tr!("Show the whole sound")).named(tr!("Zoom to fit")).clicked() { ed.window = None; ed.from = 0.0; } - if ui.small_button("+").on_hover_text("Zoom in").named("Zoom in").clicked() { + if ui.small_button("+").on_hover_text(tr!("Zoom in")).named(tr!("Zoom in")).clicked() { ed.window = Some((shown * 0.5).max(1.0 / f64::from(fps) / 4.0)); } - if ui.small_button("−").on_hover_text("Zoom out").named("Zoom out").clicked() { + if ui.small_button("−").on_hover_text(tr!("Zoom out")).named(tr!("Zoom out")).clicked() { let w = shown * 2.0; ed.window = if w >= total { None } else { Some(w) }; } @@ -201,9 +201,9 @@ fn body(app: &mut App, ed: &mut EnvelopeEditor, ui: &mut egui::Ui, t: &Target) { let p = ui.painter_at(area); let mut changed: Option<(&str, bool)> = None; for (c, lane) in lanes.iter().enumerate() { - let name = if c == 0 { "Left channel" } else { "Right channel" }; + let name = if c == 0 { tr!("Left channel") } else { tr!("Right channel") }; let bg = ui.interact(*lane, ui.id().with(("env_lane", c)), Sense::click()); - crate::a11y::surface(ui, &bg, &format!("{name}: click to add a volume point")); + crate::a11y::surface(ui, &bg, &tr!("{channel}: click to add a volume point", channel = name)); p.rect_filled(*lane, crate::theme::SQUARE, T.field); p.line_segment([pos2(lane.left(), lane.center().y), pos2(lane.right(), lane.center().y)], Stroke::new(1.0, T.separator)); if let Some(pk) = &peaks @@ -211,7 +211,7 @@ fn body(app: &mut App, ed: &mut EnvelopeEditor, ui: &mut egui::Ui, t: &Target) { { draw_wave(&p, *lane, pk, &t.sound, t, from, window); } - p.text(lane.left_top() + vec2(6.0, 4.0), Align2::LEFT_TOP, if c == 0 { "L" } else { "R" }, font(Type::Label), T.text_dim); + p.text(lane.left_top() + vec2(6.0, 4.0), Align2::LEFT_TOP, if c == 0 { trc!("left channel", "L") } else { trc!("right channel", "R") }, font(Type::Label), T.text_dim); // The envelope: its level before the first point and after the last, lines between. let level = |q: &EnvelopePoint| if c == 0 { q.left } else { q.right }; let mut line: Vec = Vec::new(); @@ -235,7 +235,7 @@ fn body(app: &mut App, ed: &mut EnvelopeEditor, ui: &mut egui::Ui, t: &Target) { pts.push(EnvelopePoint::new(when, l, r)); pts = clean_points(&pts); ed.selected = pts.iter().position(|q| q.at == when); - changed = Some(("Add Envelope Point", false)); + changed = Some((tr_noop!("Add Envelope Point"), false)); } // The points' handles: drag to move, right-click to delete. let mut remove = None; @@ -248,12 +248,12 @@ fn body(app: &mut App, ed: &mut EnvelopeEditor, ui: &mut egui::Ui, t: &Target) { let hit = Rect::from_center_size(centre, vec2(2.0 * REACH, 2.0 * REACH)); let r = ui.interact(hit, ui.id().with(("env_point", c, i)), Sense::click_and_drag()); let secs = time_label(q.at, ed.frames, fps); - crate::a11y::control(ui, &r, WidgetType::Slider, &format!("Point {} of {}, {name}: {:.0} % at {secs}", i + 1, pts.len(), level(&q) * 100.0), None); + crate::a11y::control(ui, &r, WidgetType::Slider, &tr!("Point {index} of {count}, {channel}: {level} % at {time}", index = i + 1, count = pts.len(), channel = name, level = format!("{:.0}", level(&q) * 100.0), time = secs), None); let hot = r.hovered() || r.dragged() || ed.selected == Some(i); let h = Rect::from_center_size(centre, vec2(2.0 * HANDLE, 2.0 * HANDLE)); p.rect_filled(h, crate::theme::SQUARE, if hot { T.accent } else { T.panel }); p.rect_stroke(h, crate::theme::SQUARE, Stroke::new(1.5, T.accent), egui::StrokeKind::Inside); - let r = r.on_hover_text(format!("{:.0} % at {secs} · drag to move, right-click to delete", level(&q) * 100.0)); + let r = r.on_hover_text(tr!("{level} % at {time} · drag to move, right-click to delete", level = format!("{:.0}", level(&q) * 100.0), time = secs)); if r.clicked() { ed.selected = Some(i); } @@ -269,7 +269,7 @@ fn body(app: &mut App, ed: &mut EnvelopeEditor, ui: &mut egui::Ui, t: &Target) { if c == 0 { q.left = v } else { q.right = v } } ed.selected = Some(i); - changed = Some(("Move Envelope Point", true)); + changed = Some((tr_noop!("Move Envelope Point"), true)); } if r.secondary_clicked() && pts.len() > 1 { remove = Some(i); @@ -278,7 +278,7 @@ fn body(app: &mut App, ed: &mut EnvelopeEditor, ui: &mut egui::Ui, t: &Target) { if let Some(i) = remove { pts.remove(i); ed.selected = None; - changed = Some(("Delete Envelope Point", false)); + changed = Some((tr_noop!("Delete Envelope Point"), false)); } } // The ruler: times under the lanes' x positions. @@ -295,22 +295,22 @@ fn body(app: &mut App, ed: &mut EnvelopeEditor, ui: &mut egui::Ui, t: &Target) { let sel = ed.selected.filter(|&i| i < pts.len()); match sel.and_then(|i| pts.get(i).copied().map(|q| (i, q))) { Some((i, mut q)) => { - ui.label(text(Type::Label, format!("Point {} of {}", i + 1, pts.len()))); + ui.label(text(Type::Label, tr!("Point {index} of {count}", index = i + 1, count = pts.len()))); let lo = i.checked_sub(1).and_then(|j| pts.get(j)).map_or(0.0, |n| n.at); let hi = pts.get(i + 1).map_or(MAX_ENVELOPE_SECONDS, |n| n.at); let mut edit = false; with_type(ui, Type::Data, |ui| { if ed.frames { let mut f = q.at * f64::from(fps); - edit |= ui.add(egui::DragValue::new(&mut f).range(lo * f64::from(fps)..=hi * f64::from(fps)).speed(0.1).max_decimals(1).suffix(" f")).named("Point time").changed(); + edit |= ui.add(egui::DragValue::new(&mut f).range(lo * f64::from(fps)..=hi * f64::from(fps)).speed(0.1).max_decimals(1).suffix(" f")).named(tr!("Point time")).changed(); q.at = f / f64::from(fps); } else { - edit |= ui.add(egui::DragValue::new(&mut q.at).range(lo..=hi).speed(0.005).max_decimals(3).suffix(" s")).named("Point time").changed(); + edit |= ui.add(egui::DragValue::new(&mut q.at).range(lo..=hi).speed(0.005).max_decimals(3).suffix(" s")).named(tr!("Point time")).changed(); } - for (name, v) in [("Left", &mut q.left), ("Right", &mut q.right)] { - ui.label(text(Type::Label, name)); + for (left, v) in [(true, &mut q.left), (false, &mut q.right)] { + ui.label(text(Type::Label, if left { tr!("Left") } else { tr!("Right") })); let mut pct = f64::from(*v) * 100.0; - if ui.add(egui::DragValue::new(&mut pct).range(0.0..=100.0).speed(0.5).max_decimals(0).suffix(" %")).named(&format!("{name} channel volume")).changed() { + if ui.add(egui::DragValue::new(&mut pct).range(0.0..=100.0).speed(0.5).max_decimals(0).suffix(" %")).named(if left { tr!("Left channel volume") } else { tr!("Right channel volume") }).changed() { *v = (pct / 100.0) as f32; edit = true; } @@ -318,21 +318,21 @@ fn body(app: &mut App, ed: &mut EnvelopeEditor, ui: &mut egui::Ui, t: &Target) { }); if edit && let Some(slot) = pts.get_mut(i) { *slot = q; - changed = Some(("Envelope Point", true)); + changed = Some((tr_noop!("Envelope Point"), true)); } - if ui.add_enabled(pts.len() > 1, egui::Button::new("Delete Point")).on_hover_text("A sound keeps at least one point").clicked() { + if ui.add_enabled(pts.len() > 1, egui::Button::new(tr!("Delete Point"))).on_hover_text(tr!("A sound keeps at least one point")).clicked() { pts.remove(i); ed.selected = None; - changed = Some(("Delete Envelope Point", false)); + changed = Some((tr_noop!("Delete Envelope Point"), false)); } } None => { - ui.label(text(Type::Caption, format!("Click a channel to add a point (up to {MAX_ENVELOPE_POINTS}), drag a point to shape the volume, right-click it to delete it. {} points.", pts.len()))); + ui.label(text(Type::Caption, trn!("Click a channel to add a point (up to {max}), drag a point to shape the volume, right-click it to delete it. {n} point.", "Click a channel to add a point (up to {max}), drag a point to shape the volume, right-click it to delete it. {n} points.", pts.len(), max = MAX_ENVELOPE_POINTS))); } } }); - let span = if ed.frames { format!("{} frames", (t.heard * f64::from(fps)).round()) } else { format!("{:.2} s", t.heard) }; - ui.label(text(Type::Caption, format!("Heard for {span} ({}). Presets are shaped over this time; editing one makes it Custom.", heard_reason(&t.fs, t.span, t.rest)))); + let span = if ed.frames { let n = (t.heard * f64::from(fps)).round().max(0.0) as u64; trn!("{n} frame", "{n} frames", n) } else { format!("{:.2} s", t.heard) }; + ui.label(text(Type::Caption, tr!("Heard for {time} ({why}). Presets are shaped over this time; editing one makes it Custom.", time = span, why = heard_reason(&t.fs, t.span, t.rest)))); if let Some((label, live)) = changed { set_points(app, ed, label, &pts, live); } @@ -342,11 +342,11 @@ fn body(app: &mut App, ed: &mut EnvelopeEditor, ui: &mut egui::Ui, t: &Target) { fn heard_reason(fs: &FrameSound, span: u32, rest: u32) -> String { use anicraft_engine::doc::SoundSync; match (fs.sync, fs.looping) { - (SoundSync::Stream, true) => format!("a stream looping over its {span}-frame span"), - (SoundSync::Stream, false) => format!("a stream, within its {span}-frame span"), - (_, true) => format!("looping to the end of the movie, {rest} frames on"), - (_, false) if fs.repeat > 1 => format!("played {} times", fs.repeat), - _ => "played once".to_string(), + (SoundSync::Stream, true) => trn!("a stream looping over its {n}-frame span", "a stream looping over its {n}-frame span", span), + (SoundSync::Stream, false) => trn!("a stream, within its {n}-frame span", "a stream, within its {n}-frame span", span), + (_, true) => trn!("looping to the end of the movie, {n} frame on", "looping to the end of the movie, {n} frames on", rest), + (_, false) if fs.repeat > 1 => trn!("played {n} time", "played {n} times", fs.repeat), + _ => tr!("played once").to_string(), } } @@ -357,7 +357,7 @@ fn total_seconds(t: &Target, pts: &[EnvelopePoint]) -> f64 { } fn time_label(at: f64, frames: bool, fps: f32) -> String { - if frames { format!("frame {:.1}", at * f64::from(fps) + 1.0) } else { format!("{at:.3} s") } + if frames { tr!("frame {number}", number = format!("{:.1}", at * f64::from(fps) + 1.0)) } else { format!("{at:.3} s") } } /// The sound's channels summarised apart (once per sound; a mono sound is one channel twice). @@ -441,7 +441,7 @@ fn preview(app: &mut App, t: &Target) { v.envelope = t.fs.effect.envelope(heard, rate); app.sound.preview_voice(v); if let Some(e) = app.sound.error.take() { - app.status_err(format!("No sound: {e}")); + app.status_err(tr!("No sound: {error}", error = crate::i18n::t_dyn(&e))); } } diff --git a/src/erasertool.rs b/src/erasertool.rs index d65c27a7..e8238de3 100644 --- a/src/erasertool.rs +++ b/src/erasertool.rs @@ -52,7 +52,7 @@ pub fn commit(app: &mut App, xf: Xf) { } let o = app.eraser; let params = json!({"points": points(&samples), "size": o.size, "shape": shape_key(o.shape), "mode": o.mode.key(), "unit": xf.unit()}); - let undo = crate::platform::shortcut_label("Ctrl+Z"); + let undo = app.undo_key(); match app.run("draw.erase", params) { Some(v) if v["erased"] == true => app.status_ok(tr!("Erased. {undo} to undo.", undo = undo)), Some(v) => { @@ -67,7 +67,7 @@ pub fn commit(app: &mut App, xf: Xf) { /// The Faucet: deletes the whole fill or line under the click. pub fn faucet(app: &mut App, p: Vec2, zoom: f32) { if let Some(v) = app.run("draw.faucet", json!({"x": p.x, "y": p.y, "slop": 4.0 / zoom.max(1e-3)})) { - let undo = crate::platform::shortcut_label("Ctrl+Z"); + let undo = app.undo_key(); app.status_ok(if v["kind"] == "line" { tr!("Deleted the line. {undo} to undo.", undo = undo) } else { tr!("Deleted the fill. {undo} to undo.", undo = undo) }); } } @@ -118,7 +118,7 @@ pub fn eyedropper(app: &mut App, p: Vec2, shift: bool, zoom: f32) { if shapes > 0 { if let Some(r) = app.run("paint.apply_style", json!({"fill": into_fill, "stroke": !into_fill})) { let n = r["changed"].as_u64().unwrap_or(0); - let undo = crate::platform::shortcut_label("Ctrl+Z"); + let undo = app.undo_key(); app.status_ok(match paint { Some("linear") => trn!("Applied the picked linear gradient to {n} shape. {undo} to undo.", "Applied the picked linear gradient to {n} shapes. {undo} to undo.", n, undo = undo), Some("radial") => trn!("Applied the picked radial gradient to {n} shape. {undo} to undo.", "Applied the picked radial gradient to {n} shapes. {undo} to undo.", n, undo = undo), diff --git a/src/i18n/mod.rs b/src/i18n/mod.rs index 8a4cd91c..681c2fa9 100644 --- a/src/i18n/mod.rs +++ b/src/i18n/mod.rs @@ -286,8 +286,6 @@ pub fn t(source: &'static str) -> &'static str { } /// `source` with a context word, falling back to its plain translation. -// craft-i18n's context column: no interface string needs one yet (tests use it). -#[allow(dead_code)] pub fn tc(context: &'static str, source: &'static str) -> &'static str { translate(context, source) } @@ -373,7 +371,6 @@ macro_rules! tr { } /// `trc!("menu", "Open")`: a literal with a context word (craft-i18n's first column). -#[allow(unused_macros)] macro_rules! trc { ($c:literal, $s:literal) => { $crate::i18n::tc($c, $s) diff --git a/src/i18n/tests.rs b/src/i18n/tests.rs index 944df495..6567464c 100644 --- a/src/i18n/tests.rs +++ b/src/i18n/tests.rs @@ -114,6 +114,10 @@ fn all_keys() -> BTreeSet { doc::Filter::KINDS.iter().for_each(|(_, l)| add(l)); doc::FilterSide::ALL.iter().for_each(|s| add(s.label())); doc::Easing::PRESETS.iter().for_each(|(n, _)| add(n)); + for e in doc::SoundEffect::PRESETS.iter().chain([&doc::SoundEffect::Custom(Vec::new())]) { + add(e.label()); + add(e.hint()); + } add(&doc::Easing::Linear.label()); doc::Property::ALL.iter().for_each(|p| add(p.label())); doc::ProfilePreset::ALL.iter().for_each(|p| add(p.label())); @@ -465,7 +469,7 @@ fn screen_reader_names_are_translated_too() { for tool in [Tool::Rect, Tool::Star, Tool::Text, Tool::Pencil, Tool::Brush, Tool::Eraser, Tool::PaintBucket, Tool::Eyedropper, Tool::Pen, Tool::Camera] { found.extend(untranslated_names(&format!("{tool:?} tool"), |a, _| a.tool = tool)); } - for panel in ["select", "motion", "motionspan", "motionpath", "motionedit", "camera", "sound", "prefs", "shortcuts", "palette", "about", "files", "licenses", "confirm", "recovery", "frames", "filters", "plugins", "actions", "script", "testmovie", "exporthtml"] { + for panel in ["select", "motion", "motionspan", "motionpath", "motionedit", "camera", "sound", "prefs", "shortcuts", "palette", "about", "files", "licenses", "confirm", "recovery", "frames", "filters", "plugins", "actions", "script", "testmovie", "exporthtml", "envelope"] { found.extend(untranslated_names(panel, |a, _| a.open_panel(Some(panel)))); } assert!(found.is_empty(), "{} screen-reader names not translated in the pseudo-locale:\n{}", found.len(), found.join("\n")); diff --git a/src/motion_editor.rs b/src/motion_editor.rs index 9562b139..f4b51ed4 100644 --- a/src/motion_editor.rs +++ b/src/motion_editor.rs @@ -427,7 +427,7 @@ fn footer(app: &mut App, ui: &mut egui::Ui, body: Rect, track: Option<&Track>, s } } ui.separator(); - if ui.button(tr!("Remove Tween")).on_hover_text(tr!("The object stays as it is on the span's first frame (Ctrl+Z to undo)")).clicked() { + if ui.button(tr!("Remove Tween")).on_hover_text(tr!("The object stays as it is on the span's first frame ({undo} to undo)", undo = app.undo_key())).clicked() { app.run("timeline.remove_tween", json!({})); } ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { diff --git a/src/motion_path.rs b/src/motion_path.rs index bbb7146a..8e202ad6 100644 --- a/src/motion_path.rs +++ b/src/motion_path.rs @@ -230,7 +230,7 @@ fn add_at(app: &mut App, p: Pos2, xf: Xf) -> bool { if let Some(v) = app.run("motion.add_point", json!({"x": sp.x, "y": sp.y, "slop": PICK * xf.unit()})) { app.motion_anchors = v["anchor"].as_u64().map(|a| vec![a as usize]).unwrap_or_default(); app.points.clear(); - app.status_ok(tr!("Added a point to the motion path. {undo} to undo.", undo = crate::platform::shortcut_label("Ctrl+Z"))); + app.status_ok(tr!("Added a point to the motion path. {undo} to undo.", undo = app.undo_key())); } true } @@ -279,7 +279,7 @@ pub fn delete_selected(app: &mut App) { } if let Some(v) = app.run("motion.delete_points", json!({"anchors": anchors})) { let n = v["deleted"].as_u64().unwrap_or(0); - let undo = crate::platform::shortcut_label("Ctrl+Z"); + let undo = app.undo_key(); app.status_ok(if v["kept_ends"].as_bool() == Some(true) { trn!("Deleted {n} point from the motion path; its ends stay, as they are where the motion starts and ends. {undo} to undo.", "Deleted {n} points from the motion path; its ends stay, as they are where the motion starts and ends. {undo} to undo.", n, undo = undo) } else { diff --git a/src/panels.rs b/src/panels.rs index 1f63dbd1..cdf081f2 100644 --- a/src/panels.rs +++ b/src/panels.rs @@ -1257,12 +1257,12 @@ fn frame_props(app: &mut App, ui: &mut egui::Ui, layer: &anicraft_engine::doc::L fn volume_row(app: &mut App, ui: &mut egui::Ui, layer: &anicraft_engine::doc::Layer) { let (mut pct, mut muted) = (f64::from(layer.volume) * 100.0, layer.muted); let id = layer.id.0; - row_prose(ui, "Volume", |ui| { + row_prose(ui, tr!("Volume"), |ui| { let r = with_type(ui, Type::Data, |ui| ui.add_enabled(!muted, egui::DragValue::new(&mut pct).range(0.0..=100.0).speed(0.5).max_decimals(0).suffix(" %"))); - if r.named("Layer volume").on_hover_text("The volume of this layer's sounds, and of the sounds in the symbols on it").changed() { - live(app, "Layer Volume", "layer.set_volume", json!({"layer": id, "volume": (pct / 100.0).clamp(0.0, 1.0)})); + if r.named(tr!("Layer volume")).on_hover_text(tr!("The volume of this layer's sounds, and of the sounds in the symbols on it")).changed() { + live(app, tr_noop!("Layer Volume"), "layer.set_volume", json!({"layer": id, "volume": (pct / 100.0).clamp(0.0, 1.0)})); } - if crate::theme::checkbox(ui, &mut muted, "Mute").on_hover_text("Silence this layer's sounds while you work and in every export").named("Mute layer").changed() { + if crate::theme::checkbox(ui, &mut muted, tr!("Mute")).on_hover_text(tr!("Silence this layer's sounds while you work and in every export")).named(tr!("Mute layer")).changed() { app.run("layer.set_volume", json!({"layer": id, "muted": muted})); } }); @@ -1326,15 +1326,15 @@ fn sound_rows(app: &mut App, ui: &mut egui::Ui, current: Option bool { if let Ok(v) = r { app.points = v["cmd"].as_u64().map(|c| vec![(id, c as usize, ANCHOR)]).unwrap_or_default(); app.motion_anchors.clear(); - app.status_ok(tr!("Added a point. {undo} to undo.", undo = crate::platform::shortcut_label("Ctrl+Z"))); + app.status_ok(tr!("Added a point. {undo} to undo.", undo = app.undo_key())); return true; } } diff --git a/src/plugins_ui.rs b/src/plugins_ui.rs index a911d0e0..79d9e43a 100644 --- a/src/plugins_ui.rs +++ b/src/plugins_ui.rs @@ -275,7 +275,7 @@ fn finish(app: &mut App) { let name = app.s.plugins.get(&d.id).map_or_else(String::new, |p| p.manifest().name.clone()); app.s.end_gesture(); app.plugin_dialog = None; - app.status_ok(tr!("{name} — {undo} to undo", name = name, undo = "Ctrl+Z")); + app.status_ok(tr!("{name} — {undo} to undo", name = name, undo = app.undo_key())); } /// Commands › Manage Plug-ins: what's installed, where it came from, and the folder. @@ -368,8 +368,8 @@ pub fn status(app: &mut App, id: &str, v: &Value) { // The plug-in's name and its last log line are its own text, shown as written. let name = v["name"].as_str().unwrap_or(tr!("Plug-in")); let msg = match v["log"].as_array().and_then(|l| l.last()).and_then(Value::as_str) { - Some(m) => tr!("{name}: {message} — {undo} to undo", name = name, message = m, undo = "Ctrl+Z"), - None => tr!("{name} — {undo} to undo", name = name, undo = "Ctrl+Z"), + Some(m) => tr!("{name}: {message} — {undo} to undo", name = name, message = m, undo = app.undo_key()), + None => tr!("{name} — {undo} to undo", name = name, undo = app.undo_key()), }; app.status_ok(msg); } diff --git a/src/shape_hints.rs b/src/shape_hints.rs index 825fb83e..ae3ef7eb 100644 --- a/src/shape_hints.rs +++ b/src/shape_hints.rs @@ -70,7 +70,7 @@ pub fn menu(app: &mut App, ui: &mut egui::Ui) -> bool { let Some(i) = app.hint_menu else { return false }; if ui.button(tr!("Remove Hint {letter}", letter = hint_letter(i))).clicked() { if app.run("tween.remove_hint", json!({"hint": i})).is_some() { - app.status_ok(tr!("Removed shape hint {letter}. {undo} to undo.", letter = hint_letter(i), undo = crate::platform::shortcut_label("Ctrl+Z"))); + app.status_ok(tr!("Removed shape hint {letter}. {undo} to undo.", letter = hint_letter(i), undo = app.undo_key())); } ui.close(); } diff --git a/src/stage.rs b/src/stage.rs index b591e911..14d4da78 100644 --- a/src/stage.rs +++ b/src/stage.rs @@ -526,7 +526,7 @@ pub fn show(app: &mut App, ui: &mut egui::Ui) { // The gap size is set in screen points, so it feels the same at any zoom. let gap = app.bucket_gap.screen_px() / zoom.max(1e-3); if let Some(v) = app.run("paint.bucket", json!({"x": sp.x, "y": sp.y, "gap": gap})) { - app.status_ok(if v.get("recolored").is_some() { tr!("Recoloured the fill. Ctrl+Z to undo.") } else { tr!("Filled the area. Ctrl+Z to undo.") }); + app.status_ok(if v.get("recolored").is_some() { tr!("Recoloured the fill. {undo} to undo.", undo = app.undo_key()) } else { tr!("Filled the area. {undo} to undo.", undo = app.undo_key()) }); } } Tool::Brush if !panning => { diff --git a/src/timeline.rs b/src/timeline.rs index 732e6f8c..9fa9cf54 100644 --- a/src/timeline.rs +++ b/src/timeline.rs @@ -162,7 +162,7 @@ fn transport(app: &mut App, ui: &mut egui::Ui) { } else if app.run("camera.add", json!({})).is_some() { app.tool = crate::app::Tool::Camera; app.last_tool = crate::app::Tool::Camera; - app.status_ok(tr!("Added a camera. Drag on the stage to pan it, turn it with the round handle, zoom with the wheel. Ctrl+Z to undo.")); + app.status_ok(tr!("Added a camera. Drag on the stage to pan it, turn it with the round handle, zoom with the wheel. {undo} to undo.", undo = app.undo_key())); } } } @@ -427,8 +427,8 @@ pub fn show(app: &mut App, ui: &mut egui::Ui) { } if let Some(sp) = speaker { let rr = ui.interact(sp, ui.id().with(("mute", layer.id.0)), Sense::click()); - a11y::control(ui, &rr, WidgetType::Checkbox, &format!("Mute {}", layer.name), Some(layer.muted)); - let tip = if layer.muted { "Unmute this layer's sounds" } else { "Mute this layer's sounds (in playback and every export)" }; + a11y::control(ui, &rr, WidgetType::Checkbox, &tr!("Mute {name}", name = layer.name), Some(layer.muted)); + let tip = if layer.muted { tr!("Unmute this layer's sounds") } else { tr!("Mute this layer's sounds (in playback and every export)") }; if rr.on_hover_text(tip).clicked() { app.run("layer.toggle_mute", json!({"layer": layer.id.0})); } @@ -475,7 +475,7 @@ pub fn show(app: &mut App, ui: &mut egui::Ui) { for id in ["layer.toggle_visible", "layer.toggle_lock", "layer.toggle_outline"] { menus::cmd_item(app, ui, id); } - if layer.has_sounds() && menus::check_item(ui, "Mute", layer.muted, true) { + if layer.has_sounds() && menus::check_item(ui, tr!("Mute"), layer.muted, true) { app.run("layer.toggle_mute", json!({"layer": layer.id.0})); } ui.separator(); @@ -754,9 +754,9 @@ pub fn show(app: &mut App, ui: &mut egui::Ui) { // One sentence per direction; the frame count is a phrase of its own. let frames = trn!("{n} frame", "{n} frames", n); app.status_ok(match rows_by { - 0 => trn!("Moved {n} frame by {by} — Ctrl+Z to undo", "Moved {n} frames by {by} — Ctrl+Z to undo", n, by = format!("{by:+}")), - r if r < 0 => trn!("Moved {frames} {n} layer up — Ctrl+Z to undo", "Moved {frames} {n} layers up — Ctrl+Z to undo", r.unsigned_abs(), frames = frames), - r => trn!("Moved {frames} {n} layer down — Ctrl+Z to undo", "Moved {frames} {n} layers down — Ctrl+Z to undo", r.unsigned_abs(), frames = frames), + 0 => trn!("Moved {n} frame by {by} — {undo} to undo", "Moved {n} frames by {by} — {undo} to undo", n, by = format!("{by:+}"), undo = app.undo_key()), + r if r < 0 => trn!("Moved {frames} {n} layer up — {undo} to undo", "Moved {frames} {n} layers up — {undo} to undo", r.unsigned_abs(), frames = frames, undo = app.undo_key()), + r => trn!("Moved {frames} {n} layer down — {undo} to undo", "Moved {frames} {n} layers down — {undo} to undo", r.unsigned_abs(), frames = frames, undo = app.undo_key()), }); app.run("timeline.goto", json!({"frame": shift_by(app.s.frame)})); if rows_by != 0 diff --git a/src/widthtool.rs b/src/widthtool.rs index f32787bb..8fe822de 100644 --- a/src/widthtool.rs +++ b/src/widthtool.rs @@ -202,7 +202,7 @@ pub fn drag_to(app: &mut App, d: Drag, at: Vec2, alt: bool, zoom: f32) { pub fn drag_end(app: &mut App) { app.s.end_gesture(); - app.status_ok(tr!("Changed the stroke's width. Ctrl+Z to undo.")); + app.status_ok(tr!("Changed the stroke's width. {undo} to undo.", undo = app.undo_key())); } /// Click: select the width point under the pointer, or the stroked shape. @@ -229,7 +229,7 @@ pub fn consume_keys(app: &mut App, ctx: &egui::Context) { if take(Key::Delete) || take(Key::Backspace) { app.width_sel = None; if app.run("stroke.delete_width_point", json!({"id": id.0, "index": index})).is_some() { - app.status_ok(tr!("Removed the width point. Ctrl+Z to undo.")); + app.status_ok(tr!("Removed the width point. {undo} to undo.", undo = app.undo_key())); } } else if take(Key::Escape) { app.width_sel = None;