EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust
Merge #1842: i18n: tab titles, workspaces and Project/Timeline column headers reach the catalogs; web language follows ?lang= and the browser (@devius)
aiongg819756855953
diff --cc crates/ui-egui/src/i18n.rsindex c722b8c93,dde67e225..c4905ff7e--- a/crates/ui-egui/src/i18n.rs+++ b/crates/ui-egui/src/i18n.rs@@@ -6651,6 -6685,174 +6687,41 @@@ mod testsuse serde_json::json;use std::collections::BTreeSet;+ /// Labels drawn outside the menu bar take the menu bar's row for their command (with `…` for+ /// `...`), else the panel catalog's row, else stay as they are.+ #[test]+ fn command_label_reads_the_menu_row_then_the_panel_row() {+ set_current("zh-hans");- assert_eq!(command_label("window.panel", "Project"), "项目");++ assert_eq!(command_label("window.panel", "Project"), lookup(SIMPLIFIED_CHINESE, "window.panel", "Project"));+ let (command, en, translated) = SIMPLIFIED_CHINESE.iter().find(|(c, en, _)| !c.is_empty() && en.ends_with("...")).expect("a menu row ending in ...");+ assert_eq!(command_label(command, &format!("{}…", en.trim_end_matches("..."))), *translated);- assert_eq!(command_label("no.such.command", "Cancel"), "取消");++ assert_eq!(command_label("no.such.command", "Cancel"), tr("Cancel"));+ assert_eq!(command_label("window.panel", "Comp 1"), "Comp 1");+ set_current("en");+ assert_eq!(command_label("window.panel", "Project"), "Project");+ }++ #[test]+ fn settings_page_titles_read_the_menu_row() {+ set_current("zh-hans");- assert_eq!(settings_page_title("Type"), "文字");- assert_eq!(tr("Type"), "类型");++ let menu_row = lookup(SIMPLIFIED_CHINESE, "app.settings", "Type...");++ assert_eq!(settings_page_title("Type"), menu_row.trim_end_matches("..."));++ assert_ne!(settings_page_title("Type"), tr("Type"), "the page is about text, the panel row is the kind");+ assert_eq!(settings_page_title("Roto Brush"), tr("Roto Brush"));+ set_current("en");+ assert_eq!(settings_page_title("Type"), "Type");+ }++ #[test]+ fn match_system_takes_the_first_browser_language_with_a_catalog() {+ let tags = |t: &[&str]| t.iter().map(|s| s.to_string()).collect::<Vec<_>>();+ assert_eq!(super::first_supported(&tags(&["cs-CZ", "cs", "en"])), "cs");+ assert_eq!(super::first_supported(&tags(&["nl-NL", "cs"])), "cs");+ assert_eq!(super::first_supported(&tags(&["en-US", "cs"])), "en");+ assert_eq!(super::first_supported(&tags(&["nl-NL"])), "en");+ assert_eq!(super::first_supported(&tags(&[])), "en");+ }+- #[test]- fn czech_translates_menus_without_changing_bindings_or_user_names() {- let mut app = EffectcraftApp::new(effectcraft_engine::Session::default());- app.session.execute("prefs.set", json!({"key": "general.language", "value": "en"})).unwrap();- app.session.prefs.push_recent("File.ecproj");- let en = crate::native_menu::build(&app);- let state = crate::native_menu::state_key(&app);- app.session.execute("prefs.set", json!({"key": "general.language", "value": "cs"})).unwrap();- let cs = crate::native_menu::build(&app);- assert_eq!(language(&app), "cs");- assert!(czech(&app));- assert_eq!(code("cs"), "cs");- assert_ne!(state, crate::native_menu::state_key(&app));- let bindings = |menu: &crate::native_menu::NativeMenu| {- menu.items().into_iter().map(|i| (i.id.clone(), i.command.clone(), i.params.clone(), i.shortcut.clone(), i.enabled, i.checked)).collect::<Vec<_>>()- };- assert_eq!(bindings(&en), bindings(&cs));- assert!(cs.items().iter().any(|i| i.command == "comp.new" && i.label == "Nová kompozice..."));- assert!(cs.items().iter().any(|i| i.command == "layer.newText" && i.label == "Text"));- assert!(cs.items().iter().any(|i| i.command == "keys.easyEase" && i.label == "Snadné zpomalení"));- assert!(cs.items().iter().any(|i| i.command == "file.openRecent" && i.label == "File.ecproj"));- for (source, translated) in [- ("File", "Soubor"),- ("Edit", "Úpravy"),- ("Composition", "Kompozice"),- ("Layer", "Vrstva"),- ("Effect", "Efekt"),- ("Animation", "Animace"),- ("View", "Zobrazení"),- ("Window", "Okno"),- ("Help", "Nápověda"),- ] {- assert_eq!(label(&app, "", source), translated);- }- assert_eq!(label(&app, "unknown.command", "Text"), "Text");- let panel =- MenuEntry { label: "Layer".into(), command: "window.panel".into(), params: json!({"panel": "layer"}), shortcut: None, alt_shortcuts: vec![] };- assert_eq!(entry(&app, &panel, "Layer: File Čeština".into()), "Vrstva: File Čeština");- assert_eq!(- submenu(&app, "Assign Shortcut to Workspace", "Assign Shortcut to “File Čeština” Workspace".into()),- "Přiřadit zkratku pracovnímu prostoru „File Čeština“"- );- assert_eq!(submenu(&app, "Assign Shortcut to 3D View", "Assign Shortcut to “Top”".into()), "Přiřadit zkratku 3D zobrazení „Top“");- assert_eq!(submenu(&app, "Assign Shortcut to Workspace", "Assign Shortcut to Workspace".into()), "Přiřadit zkratku pracovnímu prostoru");- app.session.execute("prefs.set", json!({"key": "general.language", "value": "en"})).unwrap();- assert_eq!(crate::native_menu::build(&app), en);- }-- #[test]- fn czech_undo_redo_keeps_history_labels_verbatim() {- let mut app = EffectcraftApp::new(effectcraft_engine::Session::default());- app.session.execute("prefs.set", json!({"key": "general.language", "value": "cs"})).unwrap();- let undo = MenuEntry { label: "Undo".into(), command: "edit.undo".into(), params: json!({}), shortcut: None, alt_shortcuts: vec![] };- let redo = MenuEntry { label: "Redo".into(), command: "edit.redo".into(), params: json!({}), shortcut: None, alt_shortcuts: vec![] };- assert_eq!(entry(&app, &undo, "Can't Undo".into()), "Není co vrátit");- assert_eq!(entry(&app, &redo, "Can't Redo".into()), "Není co zopakovat");- app.session.history.undo.push(("File Čeština".into(), app.session.project.clone()));- app.session.history.redo.push(("Text Čeština".into(), app.session.project.clone()));- assert_eq!(entry(&app, &undo, "Undo File Čeština".into()), "Zpět File Čeština");- assert_eq!(entry(&app, &redo, "Redo Text Čeština".into()), "Znovu Text Čeština");- }-- #[test]- fn german_reveal_labels_follow_the_platform_file_manager() {- // As `czech_…` and `ukrainian_…` do. Asserted through `label`, not `entry`: `entry`- // returns the English for German, Russian and French, which have catalogues but are- // not wired into the menus (see the undo/redo match in `entry` and `supported`).- let mut app = EffectcraftApp::new(effectcraft_engine::Session::default());- app.session.execute("prefs.set", json!({"key": "general.language", "value": "de"})).unwrap();- for command in ["file.revealInFinder", "layer.revealInFinder"] {- for (source, translated) in [- ("Reveal in Finder", "Im Finder anzeigen"),- ("Reveal in Explorer", "Im Explorer anzeigen"),- ("Reveal in File Manager", "Im Dateimanager anzeigen"),- ] {- assert_eq!(label(&app, command, source), translated, "{command} / {source}");- // Another command keeps a label that merely looks like one of these.- assert_eq!(label(&app, "file.openRecent", source), source);- }- assert_eq!(label(&app, command, "My file.mp4"), "My file.mp4", "a user's filename is never looked up");- }- }-- #[test]- fn german_menu_labels_name_what_their_command_does() {- let mut app = EffectcraftApp::new(effectcraft_engine::Session::default());- app.session.execute("prefs.set", json!({"key": "general.language", "value": "de"})).unwrap();- // "Ebenenreihenfolge umkehren" reads as reversing the stacking order, not time, and- // "Formate" are formats, not layer styles (#1443).- assert_eq!(label(&app, "layer.timeReverse", "Time-Reverse Layer"), "Ebene zeitlich umkehren");- assert_eq!(label(&app, "keys.timeReverse", "Time-Reverse Keyframes"), "Keyframes zeitlich umkehren");- assert_eq!(label(&app, "layer.style.convertToEditable", "Convert to Editable Styles"), "In bearbeitbare Stile umwandeln");- }-- #[test]- fn german_uses_one_word_per_term() {- let german: Vec<&str> = GERMAN.iter().map(|(_, _, de)| *de).collect();- let with = |needle: &str| german.iter().filter(|de| de.contains(needle)).copied().collect::<Vec<_>>();- // "Expression" is "Ausdruck", not the English word.- assert!(with("Expression").is_empty(), "{:?}", with("Expression"));- // "Track" as a verb is "verfolgen", not "tracken".- assert!(with("tracken").is_empty(), "{:?}", with("tracken"));- // "Reveal <somewhere>" is "anzeigen". ("einblenden" stays right for "Show All",- // "Fade from Blur" and the like, so only the Reveal entries are checked.)- let reveal: Vec<&str> =- GERMAN.iter().filter(|(_, en, _)| en.starts_with("Reveal")).map(|(_, _, de)| *de).filter(|de| !de.to_lowercase().contains("anzeigen")).collect();- assert!(reveal.is_empty(), "{reveal:?}");- // One spelling of "to the front".- let vorn: Vec<&str> = german.iter().filter(|de| de.ends_with("nach vorn")).copied().collect();- assert!(vorn.is_empty(), "{vorn:?}");- // The terms those entries joined are still the majority ones.- assert!(with("verfolgen").len() >= 4, "{:?}", with("verfolgen"));- assert!(with("anzeigen").len() >= 12, "{}", with("anzeigen").len());- }-- #[test]- fn czech_reveal_labels_follow_the_platform_file_manager() {- let mut app = EffectcraftApp::new(effectcraft_engine::Session::default());- app.session.execute("prefs.set", json!({"key": "general.language", "value": "cs"})).unwrap();- for command in ["file.revealInFinder", "layer.revealInFinder"] {- for (source, translated) in [- ("Reveal in Finder", "Zobrazit ve Finderu"),- ("Reveal in Explorer", "Zobrazit v Průzkumníku"),- ("Reveal in File Manager", "Zobrazit ve správci souborů"),- ] {- let e = MenuEntry { label: source.into(), command: command.into(), params: json!({}), shortcut: None, alt_shortcuts: vec![] };- assert_eq!(label(&app, command, source), translated);- assert_eq!(entry(&app, &e, source.into()), translated);- assert_eq!(label(&app, "file.openRecent", source), source);- }- assert_eq!(label(&app, command, "My file.mp4"), "My file.mp4");- }- }-fn keys(nodes: &[MenuNode], out: &mut BTreeSet<(String, String)>) {for node in nodes {match node {diff --cc docs/preferences.mdindex 3fc0c555a,59b0fc8a9..581410d7d--- a/docs/preferences.md+++ b/docs/preferences.md@@@ -30,7 -30,7 +30,7 @@@ Commands (CLI, MCP, control channel)### Settings that change behaviour- - `general.language`: interface language (`system` / `en` / `ja` / `zh-hans` / `zh-hant` / `uk` / `es` / `pt-br`), Settings ▸ General ▸ Language; menu labels change immediately. `system` (Match System, the default) follows the operating system's interface language where EffectCraft has a translation and is English otherwise: a Simplified Chinese locale (`zh`, `zh-CN`, `zh_CN.UTF-8`, `zh-Hans-CN`, `zh-SG`) selects `zh-hans`, a Traditional one (`zh-TW`, `zh-HK`, `zh-Hant`, `zh_MO`) selects `zh-hant`, a Ukrainian one (`uk`, `uk-UA`, `uk_UA.UTF-8`) selects `uk`, a Spanish one (`es`, `es-ES`, `es_MX.UTF-8`) selects `es`, a Portuguese one (`pt`, `pt-BR`, `pt_PT.UTF-8`) selects `pt-br`; the browser build stays in English with it. Choose **Español** or **Português (Brasil)** for Spanish or Brazilian Portuguese menus (panels stay in English for now); choose **Українська** for Ukrainian menus and cataloged panel, dialog, button and tooltip text; Ukrainian uses the bundled UI fonts. Native Japanese, Simplified and Traditional Chinese UI uses installed system fonts; the web host must supply a Japanese font. The same setting picks the CJK fallback for the interface *and* the Han preference of the text engine, so the composition's own text is drawn with the same language's glyph forms (the text engine's preference is process-global); swapping the language reinstalls the fonts, so it applies without a restart. Two catalogs back the text: the menus are keyed by `(command, English label)` (`crates/ui-egui/src/i18n.rs`), and the rest of the interface - panels, dialogs, buttons, tooltips - is keyed by its English source string (`crates/ui-egui/src/i18n/ui.rs`, with rows for Japanese, Simplified and Traditional Chinese and Ukrainian), where a panel writes `tr("Rename")`, or `tr_args("Proxy Use: {}", &[&quality])` when the row carries a value. A row that is missing falls back to English, so a new string shows up untranslated rather than empty; the `missing_translations_report` test lists what each language lacks, and the tests in `ui.rs` fail on an unused row.-- `general.language`: interface language (`system` / `en` / `ja` / `zh-hans` / `zh-hant` / `uk` / `es` / `pt-br`), Settings ▸ General ▸ Language; menu labels change immediately. `system` (Match System, the default) follows the operating system's interface language where EffectCraft has a translation and is English otherwise: a Simplified Chinese locale (`zh`, `zh-CN`, `zh_CN.UTF-8`, `zh-Hans-CN`, `zh-SG`) selects `zh-hans`, a Traditional one (`zh-TW`, `zh-HK`, `zh-Hant`, `zh_MO`) selects `zh-hant`, a Ukrainian one (`uk`, `uk-UA`, `uk_UA.UTF-8`) selects `uk`, a Spanish one (`es`, `es-ES`, `es_MX.UTF-8`) selects `es`, a Portuguese one (`pt`, `pt-BR`, `pt_PT.UTF-8`) selects `pt-br`; the browser build follows `?lang=` in the address, then the browser's languages (`navigator.languages`). Choose **Español** or **Português (Brasil)** for Spanish or Brazilian Portuguese menus (panels stay in English for now); choose **Українська** for Ukrainian menus and cataloged panel, dialog, button and tooltip text; Ukrainian uses the bundled UI fonts. Native Japanese, Simplified and Traditional Chinese UI uses installed system fonts; the web host must supply a Japanese font. The same setting picks the CJK fallback for the interface *and* the Han preference of the text engine, so the composition's own text is drawn with the same language's glyph forms (the text engine's preference is process-global); swapping the language reinstalls the fonts, so it applies without a restart. Two catalogs back the text: the menus are keyed by `(command, English label)` (`crates/ui-egui/src/i18n.rs`), and the rest of the interface - panels, dialogs, buttons, tooltips - is keyed by its English source string (`crates/ui-egui/src/i18n/ui.rs`, with rows for Japanese, Simplified and Traditional Chinese and Ukrainian), where a panel writes `tr("Rename")`, or `tr_args("Proxy Use: {}", &[&quality])` when the row carries a value. A row that is missing falls back to English, so a new string shows up untranslated rather than empty; the tests in that module fail on an unused row and on a hard-coded string in a converted panel.++- `general.language`: interface language (`system` / `en` / `ja` / `zh-hans` / `zh-hant` / `uk` / `es` / `pt-br`), Settings ▸ General ▸ Language; menu labels change immediately. `system` (Match System, the default) follows the operating system's interface language where EffectCraft has a translation and is English otherwise: a Simplified Chinese locale (`zh`, `zh-CN`, `zh_CN.UTF-8`, `zh-Hans-CN`, `zh-SG`) selects `zh-hans`, a Traditional one (`zh-TW`, `zh-HK`, `zh-Hant`, `zh_MO`) selects `zh-hant`, a Ukrainian one (`uk`, `uk-UA`, `uk_UA.UTF-8`) selects `uk`, a Spanish one (`es`, `es-ES`, `es_MX.UTF-8`) selects `es`, a Portuguese one (`pt`, `pt-BR`, `pt_PT.UTF-8`) selects `pt-br`; the browser build follows `?lang=` in the address, then the browser's languages (`navigator.languages`). Choose **Español** or **Português (Brasil)** for Spanish or Brazilian Portuguese menus (panels stay in English for now); choose **Українська** for Ukrainian menus and cataloged panel, dialog, button and tooltip text; Ukrainian uses the bundled UI fonts. Native Japanese, Simplified and Traditional Chinese UI uses installed system fonts; the web host must supply a Japanese font. The same setting picks the CJK fallback for the interface *and* the Han preference of the text engine, so the composition's own text is drawn with the same language's glyph forms (the text engine's preference is process-global); swapping the language reinstalls the fonts, so it applies without a restart. Two catalogs back the text: the menus are keyed by `(command, English label)` (`crates/ui-egui/src/i18n.rs`), and the rest of the interface - panels, dialogs, buttons, tooltips - is keyed by its English source string (`crates/ui-egui/src/i18n/ui.rs`, with rows for Japanese, Simplified and Traditional Chinese and Ukrainian), where a panel writes `tr("Rename")`, or `tr_args("Proxy Use: {}", &[&quality])` when the row carries a value. A row that is missing falls back to English, so a new string shows up untranslated rather than empty; the `missing_translations_report` test lists what each language lacks, and the tests in `ui.rs` fail on an unused row.- `general.undoLevels`: Levels of Undo- `general.pathPointSize`: Path Point and Handle Size- `general.recentItems`: Recent Projects Shown