DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
i18n tests: the same checks for every language, none fail on a missing translation (#1576)
aiongge44662305f23
diff --git a/crates/ui-egui/src/chrome.rs b/crates/ui-egui/src/chrome.rsindex 0df5361f9..e853e6793 100644--- a/crates/ui-egui/src/chrome.rs+++ b/crates/ui-egui/src/chrome.rs@@ -1155,7 +1155,7 @@ mod tests {/// The application bar's search field (German interface).fn search_node<'h>(h: &'h egui_kittest::Harness<'static, test_window::Window>) -> egui_kittest::Node<'h> {- h.get_by(|n| n.role() == egui::accesskit::Role::TextInput && n.placeholder() == Some("Suchen"))+ h.get_by(|n| n.role() == egui::accesskit::Role::TextInput && n.placeholder() == Some(crate::i18n::tr("de", "Search")))}/// A document with two frames, the Selection tool, German menus, and the search field clicked.@@ -1187,12 +1187,12 @@ mod tests {#[test]fn the_search_field_finds_and_runs_menu_commands() {let mut h = searching();- h.event(egui::Event::Text("gruppier".into()));+ let group = crate::i18n::tr("de", "Group");+ h.event(egui::Event::Text(group.to_lowercase()));h.run_steps(4);- assert!(row(&h, "Gruppieren").is_some(), "the German label is listed");- assert!(row(&h, "Gruppierung aufheben").is_some());+ assert!(row(&h, group).is_some(), "the German label is listed");// Nothing is selected, so Group is off and Return doesn't run it.- assert!(row(&h, "Gruppieren").is_some_and(|n| n.accesskit_node().is_disabled()));+ assert!(row(&h, group).is_some_and(|n| n.accesskit_node().is_disabled()));h.key_press(egui::Key::Enter);h.run_steps(4);assert_eq!(items(&h), (2, 0), "a disabled command doesn't run");@@ -1205,7 +1205,7 @@ mod tests {h.key_press(egui::Key::Enter);h.run_steps(4);assert_eq!(items(&h).0, 1, "the two frames are grouped");- assert!(row(&h, "Gruppieren").is_none(), "the matches closed");+ assert!(row(&h, group).is_none(), "the matches closed");assert!(!h.ctx.memory(|m| m.has_focus(super::search_id())), "the field gave the keyboard back");}@@ -1227,11 +1227,11 @@ mod tests {assert_eq!(items(&h), (2, 2), "nothing was deleted or deselected");h.event(egui::Event::Text("zz-no-such-command".into()));h.run_steps(4);- assert!(h.query_by_label("Keine passenden Befehle").is_some());+ assert!(h.query_by_label(crate::i18n::tr("de", "No matching commands")).is_some());// Escape closes the matches and clears the field without touching the document.h.key_press(egui::Key::Escape);h.run_steps(4);- assert!(h.query_by_label("Keine passenden Befehle").is_none());+ assert!(h.query_by_label(crate::i18n::tr("de", "No matching commands")).is_none());assert!(!h.ctx.text_edit_focused());assert_eq!(h.state().app.session.tool_id(), "rectangleFrame");assert_eq!(items(&h), (2, 2));diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rsindex 6b60b1296..40787954f 100644--- a/crates/ui-egui/src/dialogs.rs+++ b/crates/ui-egui/src/dialogs.rs@@ -8963,7 +8963,7 @@ mod tests {assert_eq!(app.ui.language, "de");assert_eq!(app.ui.dialog.as_ref().map(|d| d.id.as_str()), Some("preferences"));let labels = dialog_frame(&mut app, &ctx, screen, vec![]);- let heading = visible_label(&labels, screen, "Sprache der Oberfläche");+ let heading = visible_label(&labels, screen, crate::i18n::tr("de", "Interface Language"));let combo = visible_label(&labels, screen, "Deutsch");// The names stay endonyms in the German interface.diff --git a/crates/ui-egui/src/guide_selection_tests.rs b/crates/ui-egui/src/guide_selection_tests.rsindex 6c41d0122..d69026712 100644--- a/crates/ui-egui/src/guide_selection_tests.rs+++ b/crates/ui-egui/src/guide_selection_tests.rs@@ -190,11 +190,6 @@ fn select_all_guides_is_in_the_edit_menu_on_the_spread_in_view() {assert_eq!(crate::menus::default_shortcut("guide.selectAll"), Some("Cmd+Alt+G"));crate::menus::activate(h.state_mut(), "guide.selectAll", &serde_json::Value::Null);assert_eq!(selected(&h), [0, 1, 2]);- assert_eq!(crate::i18n::tr("de", "Select All Guides"), "Alle Hilfslinien auswählen");- for (code, _) in crate::i18n::LANGUAGES.iter().filter(|(c, _)| !c.is_empty()) {- assert_ne!(crate::i18n::tr(code, "Select All Guides"), "Select All Guides", "{code}");- assert_ne!(crate::i18n::tr(code, "Ruler Guide"), "Ruler Guide", "{code}");- }h.state_mut().ui.guides = false;assert!(!crate::menus::menu_enabled(h.state(), "guide.selectAll"));}diff --git a/crates/ui-egui/src/i18n.rs b/crates/ui-egui/src/i18n.rsindex fec123a33..6057abc97 100644--- a/crates/ui-egui/src/i18n.rs+++ b/crates/ui-egui/src/i18n.rs@@ -4598,332 +4598,198 @@ pub fn workspace_name<'a>(lang: &str, name: &'a str) -> &'a str {#[cfg(test)]mod tests {use super::*;+ use std::collections::HashSet;++ /// Every per-language table `tr` looks up, by interface language.+ const LANGUAGE_TABLES: &[(&str, &[(&str, &str)])] = &[+ ("ar", ar::TABLE),+ ("cs", cs::TABLE),+ ("de", de::TABLE),+ ("fr", fr::TABLE),+ ("it", it::TABLE),+ ("ja", ja::TABLE),+ ("ka", ka::TABLE),+ ("pl", pl::TABLE),+ ("pt-br", pt_br::TABLE),+ ("ru", ru::TABLE),+ ("uk", uk::TABLE),+ ];++ /// Every per-language table `tr_context` looks up.+ const CONTEXT_TABLES: &[(&str, &[(&str, &str, &str)])] =+ &[("ar", ar::CONTEXT), ("cs", cs::CONTEXT), ("ja", ja::CONTEXT), ("pl", pl::CONTEXT), ("ru", ru::CONTEXT), ("uk", uk::CONTEXT)];++ /// The languages of the shared tables' columns, in column order.+ const SHARED_COLUMNS: [&str; 5] = ["de", "fr", "es", "ja", "zh"];++ /// The German and Japanese tables translate the whole interface and win over the shared columns.+ const WHOLE_INTERFACE: [&str; 2] = ["de", "ja"];++ #[test]+ fn every_interface_language_has_a_catalog() {+ for (lang, i) in SHARED_COLUMNS.iter().zip(0..) {+ assert_eq!(column(lang), Some(i), "{lang}");+ }+ for (code, name) in LANGUAGES.iter().filter(|(code, _)| !code.is_empty()) {+ assert!(!name.is_empty(), "{code}");+ assert!(LANGUAGE_TABLES.iter().any(|(lang, _)| lang == code) || column(code).is_some(), "{code} has no catalog in LANGUAGE_TABLES");+ }+ }#[test]fn cached_lookup_preserves_every_translation_across_language_switches() {+ let own = |lang: &str, key: &str| {+ LANGUAGE_TABLES.iter().find(|(code, _)| *code == lang).and_then(|(_, table)| table.iter().find(|(k, _)| *k == key)).map(|(_, text)| *text)+ };for (key, translations) in TABLE {- for (lang, expected) in ["de", "fr", "es", "ja", "zh"].into_iter().zip(translations) {- // `de::TABLE` and `ja::TABLE` translate the whole interface and win over the shared columns.- if lang != "de" && lang != "ja" {- assert_eq!(tr(lang, key), *expected, "{lang}: {key}");- }+ for (lang, shared) in SHARED_COLUMNS.into_iter().zip(translations) {+ // A language's own table is looked up before the shared column.+ assert_eq!(tr(lang, key), own(lang, key).unwrap_or(*shared), "{lang}: {key}");}assert_eq!(tr("", key), *key);}- for (key, expected) in de::TABLE {- assert_eq!(tr("de", key), *expected, "de: {key}");- }- for (key, expected) in ar::TABLE {- assert_eq!(tr("ar", key), *expected, "ar: {key}");- }- for (key, expected) in pt_br::TABLE {- assert_eq!(tr("pt-br", key), *expected, "pt-br: {key}");- }- for (key, expected) in it::TABLE {- assert_eq!(tr("it", key), *expected, "it: {key}");- }- for (key, expected) in uk::TABLE {- assert_eq!(tr("uk", key), *expected, "uk: {key}");- }- for (key, expected) in ru::TABLE {- assert_eq!(tr("ru", key), *expected, "ru: {key}");- }- for (key, expected) in cs::TABLE {- assert_eq!(tr("cs", key), *expected, "cs: {key}");- }- for (key, expected) in fr::TABLE {- assert_eq!(tr("fr", key), *expected, "fr: {key}");- }- for (key, expected) in pl::TABLE {- assert_eq!(tr("pl", key), *expected, "pl: {key}");- }- for (key, expected) in ka::TABLE {- assert_eq!(tr("ka", key), *expected, "ka: {key}");+ for (lang, table) in LANGUAGE_TABLES {+ for (key, expected) in *table {+ assert_eq!(tr(lang, key), *expected, "{lang}: {key}");+ assert_eq!(tr("", key), *key);+ }}+ // Strings no catalog has stay as they are, in every language.let unknown = String::from("A user-defined untranslated label");- for lang in ["pl", "cs", "uk", "ru", "ar", "pt-br", "it", "ka", "zh", "ja", "de", "fr", "es", "", "unknown"] {- assert!(std::ptr::eq(tr(lang, &unknown), unknown.as_str()));+ for lang in LANGUAGES.iter().map(|(code, _)| *code).chain(["en", "unknown"]) {+ assert!(std::ptr::eq(tr(lang, &unknown), unknown.as_str()), "{lang}");+ // Fixed standard names stay identical.+ assert_eq!(tr(lang, "PDF/X-4"), "PDF/X-4", "{lang}");}}#[test]- fn translates_known_strings_and_keeps_the_rest() {- assert_eq!(tr("de", "File"), "Datei");- assert_eq!(tr("ja", "Swatches"), "スウォッチ");- assert_eq!(tr("fr", "Something new"), "Something new");- assert_eq!(tr("", "File"), "File");- assert_eq!(tr("ar", "File"), "ملف");- assert_eq!(tr("ar", "Unknown label"), "Unknown label");- assert_eq!(tr("pt-br", "File"), "Arquivo");- assert_eq!(tr("pt-br", "New Document…"), "Novo documento…");- assert_eq!(tr("pt-br", "Unknown label"), "Unknown label");- assert_eq!(tr("it", "Edit"), "Modifica");- assert_eq!(tr("it", "New Document…"), "Nuovo documento…");- assert_eq!(tr("it", "Unknown label"), "Unknown label");- assert!(is_rtl("ar"));- for (i, (en, translation)) in ar::TABLE.iter().enumerate() {- assert!(ar::TABLE[..i].iter().all(|(key, _)| key != en), "duplicate {en}");- assert!(!translation.is_empty(), "{en}");- }- for (i, (en, translation)) in pt_br::TABLE.iter().enumerate() {- assert!(pt_br::TABLE[..i].iter().all(|(key, _)| key != en), "duplicate {en}");- assert!(!translation.is_empty(), "{en}");- }- for (i, (en, translation)) in it::TABLE.iter().enumerate() {- assert!(it::TABLE[..i].iter().all(|(key, _)| key != en), "duplicate {en}");- assert!(!translation.is_empty(), "{en}");+ fn context_captions_come_from_their_context_or_the_plain_translation() {+ for (lang, table) in CONTEXT_TABLES {+ for (key, scope, text) in *table {+ assert_eq!(tr_context(lang, key, scope), *text, "{lang}: {key} ({scope})");+ }}- // Italian entries are for keys the shared or Arabic table knows. A new English string- // falls back to English until it is translated, so it doesn't fail here.- for (en, _) in it::TABLE {- assert!(TABLE.iter().any(|(key, _)| key == en) || ar::TABLE.iter().any(|(key, _)| key == en), "it: unknown key {en}");+ for (key, scope, row) in CONTEXT {+ for (lang, shared) in SHARED_COLUMNS.into_iter().zip(row) {+ // A language's own context table is looked up before the shared one.+ let own = CONTEXT_TABLES+ .iter()+ .filter(|(code, _)| *code == lang)+ .flat_map(|(_, table)| table.iter())+ .find(|(k, s, _)| k == key && s == scope)+ .map(|(_, _, text)| *text);+ assert_eq!(tr_context(lang, key, scope), own.unwrap_or(*shared), "{lang}: {key} ({scope})");+ }}- // Every row is unique and complete.- for (i, (en, t)) in TABLE.iter().enumerate() {- assert!(TABLE[..i].iter().all(|(e, _)| e != en), "duplicate {en}");- assert!(t.iter().all(|x| !x.is_empty()), "{en}");+ // An unknown context, or a language without one, keeps the plain translation.+ let keys = CONTEXT.iter().map(|(key, _, _)| *key).chain(CONTEXT_TABLES.iter().flat_map(|(_, table)| table.iter().map(|(key, _, _)| *key)));+ for key in keys {+ for lang in LANGUAGES.iter().map(|(code, _)| *code).chain(["en"]) {+ assert_eq!(tr_context(lang, key, "no such context"), tr(lang, key), "{lang}: {key}");+ }+ assert_eq!(tr_context("", key, "count"), key);}}+ /// Every catalog: no duplicate or stale keys, no empty translations, and placeholders, padding,+ /// ellipses and label colons as in English. A string a catalog doesn't translate yet falls back+ /// to English, so missing translations don't fail here.#[test]- fn a_column_count_and_a_list_number_read_differently() {- for (lang, count, numeral) in [- ("de", "Anzahl:", "Zahl:"),- ("ja", "数:", "番号:"),- ("uk", "Кількість:", "Номер:"),- ("ar", "العدد:", "الرقم:"),- ("fr", "Nombre :", "Numéro:"),- ("zh", "数量:", "编号:"),- ] {- assert_eq!((tr_context(lang, "Number:", "count"), tr(lang, "Number:")), (count, numeral), "{lang}");+ fn every_catalog_is_unique_current_and_keeps_placeholders_and_markers() {+ // (language, key, translation) of every catalog, and every catalog's keys by name.+ let mut entries: Vec<(&str, &str, &str)> = Vec::new();+ let mut catalogs: Vec<(&str, HashSet<&str>)> = Vec::new();+ for (lang, table) in LANGUAGE_TABLES {+ let keys: HashSet<_> = table.iter().map(|(key, _)| *key).collect();+ assert_eq!(keys.len(), table.len(), "{lang}: duplicate keys");+ catalogs.push((*lang, keys));+ entries.extend(table.iter().map(|(key, text)| (*lang, *key, *text)));}- assert_eq!(tr_context("en", "Number:", "count"), "Number:");- assert_eq!(tr("de", "Gutter:"), "Spaltenabstand:");- // The Pages panel menu.- for key in [- "Insert Pages…",- "Move Pages…",- "New Parent…",- "Override All Parent Page Items",- "Remove All Local Overrides",- "Detach All Objects from Parent",- "Create Alternate Layout…",- "Allow Selected Spread to Shuffle",- ] {- assert_ne!(tr("pt-br", key), key);+ let shared: HashSet<_> = TABLE.iter().map(|(key, _)| *key).collect();+ assert_eq!(shared.len(), TABLE.len(), "duplicate keys in the shared table");+ catalogs.push(("shared", shared.clone()));+ for (lang, i) in SHARED_COLUMNS.into_iter().zip(0..) {+ entries.extend(TABLE.iter().filter_map(|(key, row)| row.get(i).map(|text| (lang, *key, *text))));+ entries.extend(CONTEXT.iter().filter_map(|(key, _, row)| row.get(i).map(|text| (lang, *key, *text))));+ }+ let mut contexts = vec![("shared", CONTEXT.iter().map(|(key, scope, _)| (*key, *scope)).collect::<Vec<_>>())];+ for (lang, table) in CONTEXT_TABLES {+ contexts.push((*lang, table.iter().map(|(key, scope, _)| (*key, *scope)).collect()));+ entries.extend(table.iter().map(|(key, _, text)| (*lang, *key, *text)));}- assert_ne!(tr("ar", "Apply Parent to Pages"), "Apply Parent to Pages");- }- #[test]- fn french_catalog_has_no_duplicate_or_stale_keys_and_keeps_placeholders() {- let catalog: HashMap<_, _> = fr::TABLE.iter().copied().collect();- assert_eq!(catalog.len(), fr::TABLE.len(), "duplicate French keys");- let shared: std::collections::HashSet<_> = TABLE.iter().map(|(key, _)| *key).collect();- // `fr::TABLE` is looked up first: a key there would hide the shared table's French column.- let both: Vec<_> = catalog.keys().filter(|k| shared.contains(*k)).collect();- assert!(both.is_empty(), "French keys also in the shared table: {both:?}");- let mut keys = interface_strings();- for table in [ar::TABLE, de::TABLE, it::TABLE, ja::TABLE, pt_br::TABLE, uk::TABLE, ru::TABLE, cs::TABLE] {- keys.extend(table.iter().map(|(key, _)| *key));+ // A per-language table is looked up before the shared table, so a key in both hides the+ // shared column, except in the tables that translate the whole interface.+ for (lang, table) in LANGUAGE_TABLES.iter().filter(|(lang, _)| column(lang).is_some() && !WHOLE_INTERFACE.contains(lang)) {+ let both: Vec<_> = table.iter().map(|(key, _)| *key).filter(|key| shared.contains(key)).collect();+ assert!(both.is_empty(), "{lang} keys also in the shared table: {both:?}");+ }++ // A key is current while the interface or another catalog has it.+ let interface = interface_strings();+ let current = |key: &str, own: &str| interface.contains(key) || catalogs.iter().any(|(name, keys)| *name != own && keys.contains(key));+ for (name, keys) in &catalogs {+ let mut stale: Vec<_> = keys.iter().filter(|key| !current(key, name)).collect();+ stale.sort();+ assert!(stale.is_empty(), "{name}: entries for unknown keys: {stale:?}");}- let stale: Vec<_> = catalog.keys().filter(|k| !keys.contains(*k)).collect();- assert!(stale.is_empty(), "French entries for unknown keys: {stale:?}");- let placeholders = |s: &str| {- let mut names = s.split('{').skip(1).filter_map(|part| part.split_once('}').map(|(name, _)| name.to_owned())).collect::<Vec<_>>();- names.sort();+ for (name, keys) in &contexts {+ let unique: HashSet<_> = keys.iter().collect();+ assert_eq!(unique.len(), keys.len(), "{name}: duplicate context keys");+ let stale: Vec<_> = keys.iter().filter(|(key, _)| !current(key, "")).collect();+ assert!(stale.is_empty(), "{name}: contexts for unknown keys: {stale:?}");+ }++ let placeholders = |s: &'static str| {+ let mut names: Vec<_> = s.split('{').skip(1).filter_map(|part| part.split_once('}').map(|(name, _)| name)).collect();+ names.sort_unstable();names};- let shared_french = TABLE.iter().filter_map(|(key, row)| row.get(1).map(|text| (*key, *text)));- for (key, translation) in fr::TABLE.iter().copied().chain(shared_french) {- assert!(!translation.trim().is_empty(), "empty {key}");- assert_eq!(key.starts_with(' '), translation.starts_with(' '), "leading space: {key}");- assert_eq!(key.ends_with(' '), translation.ends_with(' '), "trailing space: {key}");- assert_eq!(placeholders(key), placeholders(translation), "placeholders: {key}");+ let ellipsis = |s: &str| s.ends_with('…') || s.ends_with("...");+ let colon = |s: &str| s.ends_with(':') || s.ends_with(':');+ // Full-width punctuation carries its own spacing.+ let full_width = |c: char| ('\u{3000}'..='\u{303F}').contains(&c) || ('\u{FF00}'..='\u{FFEF}').contains(&c);+ for (lang, key, text) in entries {+ assert!(!text.trim().is_empty(), "{lang}: empty translation of {key:?}");+ assert_eq!(placeholders(key), placeholders(text), "{lang}: placeholders of {key:?}");+ // Dialog ellipses, label colons and padded captions stay as in English.+ assert_eq!(ellipsis(key), ellipsis(text), "{lang}: ellipsis of {key:?}");+ assert_eq!(colon(key), colon(text), "{lang}: colon of {key:?}");+ if !text.starts_with(full_width) {+ assert_eq!(key.starts_with(' '), text.starts_with(' '), "{lang}: leading space of {key:?}");+ }+ if !text.ends_with(full_width) {+ assert_eq!(key.ends_with(' '), text.ends_with(' '), "{lang}: trailing space of {key:?}");+ }}- assert_eq!(tr("fr", "Group"), "Associer");}- /// Interface strings that read the same in French: names, abbreviations, numbering samples, key- /// symbols and words French shares with English.- const SAME_IN_FRENCH: &[&str] = &[- " OK ",- " (auto)",- "+Bin",- "+LOC",- "A, B, C, D...",- "Angle",- "Articles",- "Bunri-Kinshi",- "Commits",- "Composition",- "Compression",- "Conditions",- "Cyan",- "DesignCraft",- "Direction",- "Distance",- "Document",- "Document…",- "Ellipse",- "Extras",- "Fractions",- "GREP",- "Hindi",- "Horizontal",- "I, II, III, IV...",- "Image",- "Index",- "Interface",- "Justification",- "Justification…",- "Kanji",- "Kenten",- "Lab",- "Ligatures",- "Magenta",- "Maximum",- "Menus",- "Menus…",- "Minimum",- "Mobile",- "Normal",- "Normal (W)",- "Notes",- "OK",- "OpenType",- "Options",- "Orange",- "Orientation",- "PDF/A-2b",- "PDF/X-4",- "Page",- "Pages",- "Pathfinder",- "Picas",- "Portrait",- "Position",- "Radial",- "Rectangle",- "Rensuuji",- "Rotation",- "Ruby",- "Ruby…",- "Satin",- "Saturation",- "Script",- "Scripts",- "Section",- "Serif",- "Shatai",- "Signature",- "Simple",- "Structure",- "Style",- "Styles",- "Tate-Chu-Yoko",- "Triangle",- "Version",- "Vertical",- "Violet",- "Warichu",- "Web",- "a, b, c, d...",- "document",- "i, ii, iii, iv...",- "pages",- "ΔLOC",- "⇧",- "−Bin",- "−LOC",- "⌃",- "⌘",- "⌥",- ];-#[test]- fn french_translates_every_interface_string() {- let keys = interface_strings();- // A new English string needs a French entry (or a place on `SAME_IN_FRENCH`) before it ships.- let mut untranslated: Vec<_> = keys.iter().filter(|key| tr("fr", key) == **key && !SAME_IN_FRENCH.contains(key)).collect();- untranslated.sort();- assert!(untranslated.is_empty(), "French falls back to English for: {untranslated:?}");- for key in SAME_IN_FRENCH {- assert!(keys.contains(key), "SAME_IN_FRENCH lists a string the interface no longer has: {key}");- assert_eq!(tr("fr", key), *key, "SAME_IN_FRENCH lists a string French translates: {key}");- }- for tool in designcraft_tools::TOOL_GROUPS.iter().flat_map(|group| group.iter()) {- assert!(tr("fr", tool.label).starts_with("Outil "), "{}", tool.id);+ fn only_arabic_lays_out_right_to_left() {+ for (code, _) in LANGUAGES {+ assert_eq!(is_rtl(code), *code == "ar", "{code}");}- assert_eq!(tr("fr", "Selection Tool"), "Outil Sélection");- assert_eq!(tr("fr", "Don't Save"), "Ne pas enregistrer");}+ /// Built-in style and workspace names follow the interface language; names people give their+ /// own styles and workspaces are document data and stay as typed.#[test]- fn ukrainian_catalog_covers_existing_keys_and_preserves_placeholders() {- let catalog: std::collections::HashMap<_, _> = uk::TABLE.iter().copied().collect();- assert_eq!(catalog.len(), uk::TABLE.len(), "duplicate Ukrainian keys");- let mut keys = std::collections::HashSet::new();- keys.extend(TABLE.iter().map(|(key, _)| *key));- keys.extend(ar::TABLE.iter().map(|(key, _)| *key));- keys.extend(pt_br::TABLE.iter().map(|(key, _)| *key));- // A new English string falls back to English until it is translated, so only stale- // entries (keys no catalog knows any more) fail.- let stale: Vec<_> = catalog.keys().filter(|k| !keys.contains(*k)).collect();- assert!(stale.is_empty(), "Ukrainian entries for unknown keys: {stale:?}");- let placeholders =- |s: &str| s.split('{').skip(1).filter_map(|part| part.split_once('}').map(|(name, _)| name.to_owned())).collect::<Vec<_>>();- for (key, translation) in uk::TABLE {- assert!(!translation.trim().is_empty(), "empty {key}");- let mut source = placeholders(key);- let mut translated = placeholders(translation);- source.sort();- translated.sort();- assert_eq!(source, translated, "placeholders: {key}");+ fn only_built_in_style_and_workspace_names_are_translated() {+ for (code, _) in LANGUAGES {+ for name in [designcraft_doc::NO_PARA_STYLE, designcraft_doc::BASIC_PARAGRAPH, designcraft_doc::NO_CHAR_STYLE] {+ assert_eq!(style_name(code, name), tr(code, name), "{code}");+ }+ assert_eq!(workspace_name(code, "Essentials"), tr(code, "Essentials"), "{code}");+ for custom in ["Group", "Columns", "My layout style"] {+ assert_eq!(style_name(code, custom), custom, "{code}");+ assert_eq!(workspace_name(code, custom), custom, "{code}");+ }}- assert_eq!(tr_context("uk", "Columns", "table"), "Стовпці");- assert_eq!(tr("uk", "Columns"), "Колонки");- assert_eq!(tr_context("uk", "Group", "selection"), "Група");- // Step and Repeat's grid columns are not a text frame's.- assert_eq!(tr_context("uk", "Columns:", "grid"), "Стовпці:");- assert_eq!(tr_context("ja", "Columns:", "grid"), "列:");- assert_eq!(tr("ja", "Columns:"), "段:");- assert_eq!(tr("uk", "Group"), "Згрупувати");- assert_eq!(tr_context("", "Columns", "table"), "Columns");- assert_eq!(tr_context("ja", "Span Columns", "paragraphLayout"), "段抜き");- assert_eq!(tr("ja", "Span Columns"), "段抜きと段分割");- assert_eq!(tr_context("uk", "Custom caption", "custom"), "Custom caption");- assert_eq!(tr("uk", "through"), "включно");- assert_eq!(tr("uk", "up to"), "не включно");- assert!(!is_rtl("uk"));- assert_eq!(tr("uk", "Type"), "Текст");- assert_eq!(tr("uk", "Spread"), "Розворот");- assert_eq!(tr("uk", "Story"), "Текстовий матеріал");- assert_eq!(tr("uk", "Footer Rows"), "Рядки нижнього колонтитула");- assert_eq!(style_name("uk", "[Basic Paragraph]"), "[Основний абзац]");- assert_eq!(style_name("uk", "My layout style"), "My layout style");- assert_eq!(workspace_name("uk", "Essentials"), "Основне");- assert_eq!(workspace_name("uk", "My workspace"), "My workspace");}#[test]- fn georgian_catalog_preserves_placeholders_and_counts() {- let catalog: HashMap<_, _> = ka::TABLE.iter().copied().collect();- assert_eq!(catalog.len(), ka::TABLE.len(), "duplicate Georgian keys");- let placeholders = |s: &str| {- s.split('{').skip(1).filter_map(|part| part.split_once('}').map(|(name, _)| name.to_owned())).collect::<std::collections::BTreeSet<_>>()- };- for (key, translation) in ka::TABLE {- assert!(!translation.trim().is_empty(), "empty {key}");- assert_eq!(placeholders(key), placeholders(translation), "placeholders: {key}");- assert_eq!(key.ends_with('…'), translation.ends_with('…'), "ellipsis: {key}");- // Georgian has no capitals in running text: Mtavruli never appears in the interface.- assert!(!translation.chars().any(|c| ('\u{1C90}'..='\u{1CBF}').contains(&c)), "Mtavruli: {key}");- }- assert_eq!(tr("ka", "File"), "ფაილი");- assert_eq!(tr("ka", "Save As…"), "შენახვა როგორც…");- assert_eq!(tr("ka", "Unknown label"), "Unknown label");- assert!(!is_rtl("ka"));+ fn georgian_counts_use_category_captions_for_every_number() {for n in [1, 2, 5, 21] {assert_eq!(count_label("ka", "pages", n), format!("გვერდი: {n}"));}@@ -4941,62 +4807,6 @@ mod tests {assert_eq!(count_label("", "objects", 2), "2 objects");}- #[test]- fn russian_catalog_covers_existing_keys_and_preserves_placeholders() {- let catalog: std::collections::HashMap<_, _> = ru::TABLE.iter().copied().collect();- assert_eq!(catalog.len(), ru::TABLE.len(), "duplicate Russian keys");- let mut keys = std::collections::HashSet::new();- keys.extend(TABLE.iter().map(|(key, _)| *key));- keys.extend(ar::TABLE.iter().map(|(key, _)| *key));- keys.extend(pt_br::TABLE.iter().map(|(key, _)| *key));- keys.extend(it::TABLE.iter().map(|(key, _)| *key));- keys.extend(ja::TABLE.iter().map(|(key, _)| *key));- keys.extend(uk::TABLE.iter().map(|(key, _)| *key));- // A new English string falls back to English until it is translated, so only stale- // entries (keys no catalog knows any more) fail.- let stale: Vec<_> = catalog.keys().filter(|k| !keys.contains(*k)).collect();- assert!(stale.is_empty(), "Russian entries for unknown keys: {stale:?}");- let placeholders =- |s: &str| s.split('{').skip(1).filter_map(|part| part.split_once('}').map(|(name, _)| name.to_owned())).collect::<Vec<_>>();- for (key, translation) in ru::TABLE {- assert!(!translation.trim().is_empty(), "empty {key}");- assert_eq!(key.starts_with(' '), translation.starts_with(' '), "leading space: {key}");- assert_eq!(key.ends_with(' '), translation.ends_with(' '), "trailing space: {key}");- assert!(!translation.contains(['ґ', 'є', 'і', 'ї', 'Ґ', 'Є', 'І', 'Ї']), "Ukrainian letter in {key}");- let mut source = placeholders(key);- let mut translated = placeholders(translation);- source.sort();- translated.sort();- assert_eq!(source, translated, "placeholders: {key}");- }- }-- #[test]- fn russian_is_selectable_ltr_and_resolves_contexts_styles_and_menu_paths() {- assert!(LANGUAGES.contains(&("ru", "Русский")));- assert!(!is_rtl("ru"));- assert_eq!(tr("ru", "File"), "Файл");- assert_eq!(tr("ru", "Type"), "Текст");- assert_eq!(tr("ru", "Spread"), "Разворот");- assert_eq!(tr("ru", "Story"), "Материал");- assert_eq!(tr("ru", "Unknown label"), "Unknown label");- assert_eq!(tr_context("ru", "Columns", "table"), "Столбцы");- assert_eq!(tr("ru", "Columns"), "Колонки");- assert_eq!(tr_context("ru", "Group", "selection"), "Группа");- assert_eq!(tr("ru", "Group"), "Сгруппировать");- assert_eq!(tr_context("ru", "Custom caption", "custom"), "Custom caption");- assert_eq!(tr("ru", "through"), "включительно");- assert_eq!(tr("ru", "up to"), "не включая");- assert_eq!(tr("ru", "Edit/Spelling"), "Редактирование/Орфография");- assert_eq!(tr("ru", "Type/Insert Special Character/Quotation Marks"), "Текст/Вставить специальный символ/Кавычки");- assert_eq!(style_name("ru", "[Basic Paragraph]"), "[Основной абзац]");- assert_eq!(style_name("ru", "My layout style"), "My layout style");- assert_eq!(workspace_name("ru", "Essentials"), "Основное");- assert_eq!(workspace_name("ru", "My workspace"), "My workspace");- // Fixed standard names stay identical.- assert_eq!(tr("ru", "PDF/X-4"), "PDF/X-4");- }-#[test]fn russian_counts_use_category_captions_for_every_number() {assert!(category_first("ru") && category_first("uk") && !category_first("de") && !category_first(""));@@ -5009,45 +4819,6 @@ mod tests {}}- #[test]- fn polish_catalog_covers_existing_keys_and_preserves_placeholders() {- let catalog: HashMap<_, _> = pl::TABLE.iter().copied().collect();- assert_eq!(catalog.len(), pl::TABLE.len(), "duplicate Polish keys");- let mut keys = std::collections::HashSet::new();- keys.extend(TABLE.iter().map(|(key, _)| *key));- for table in [ar::TABLE, pt_br::TABLE, ja::TABLE, it::TABLE, uk::TABLE, de::TABLE, fr::TABLE, ru::TABLE, cs::TABLE] {- keys.extend(table.iter().map(|(key, _)| *key));- }- // A new English string falls back to English until it is translated; only stale entries fail.- let stale: Vec<_> = catalog.keys().filter(|k| !keys.contains(*k)).collect();- assert!(stale.is_empty(), "Polish entries for unknown keys: {stale:?}");- let placeholders =- |s: &str| s.split('{').skip(1).filter_map(|part| part.split_once('}').map(|(name, _)| name.to_owned())).collect::<Vec<_>>();- for (key, translation) in pl::TABLE {- assert!(!translation.trim().is_empty(), "empty {key}");- let mut source = placeholders(key);- let mut translated = placeholders(translation);- source.sort();- translated.sort();- assert_eq!(source, translated, "placeholders: {key}");- assert_eq!(key.ends_with('…'), translation.ends_with('…'), "ellipsis: {key}");- }- assert!(LANGUAGES.contains(&("pl", "Polski")));- assert!(!is_rtl("pl"));- assert_eq!(tr("pl", "File"), "Plik");- assert_eq!(tr("pl", "New Document…"), "Nowy dokument…");- assert_eq!(tr("pl", "Spread"), "Rozkładówka");- assert_eq!(tr("pl", "Unknown label"), "Unknown label");- assert_eq!(style_name("pl", "[Basic Paragraph]"), "[Podstawowy akapit]");- assert_eq!(workspace_name("pl", "Essentials"), "Podstawowe");- // A table's columns and grid columns aren't a text frame's; a selection's group isn't the action.- assert_eq!(tr("pl", "Columns"), "Łamy");- assert_eq!(tr_context("pl", "Columns", "table"), "Kolumny");- assert_eq!(tr_context("pl", "Columns:", "grid"), "Łamy:");- assert_eq!(tr("pl", "Group"), "Grupuj");- assert_eq!(tr_context("pl", "Group", "selection"), "Grupa");- }-#[test]fn polish_counts_use_category_captions_for_every_number() {for n in [0, 1, 2, 5, 12, 22, 25] {@@ -5058,14 +4829,10 @@ mod tests {assert_eq!(tr("pl", "{pages} Pages in {spreads} Spreads"), "Strony: {pages}, rozkładówki: {spreads}");}- /// Every English string the interface passes to `tr`, as far as the catalogs, command and tool- /// tables and the list of UI-only labels know them.- fn interface_strings() -> std::collections::HashSet<&'static str> {- let mut keys = std::collections::HashSet::new();- keys.extend(TABLE.iter().map(|(key, _)| *key));- for table in [ar::TABLE, it::TABLE, ja::TABLE, pt_br::TABLE, uk::TABLE] {- keys.extend(table.iter().map(|(key, _)| *key));- }+ /// Every English string the interface passes to `tr`, as far as the command and tool tables and+ /// the list of UI-only labels know them.+ fn interface_strings() -> HashSet<&'static str> {+ let mut keys = HashSet::new();// Command labels and menu names reach `tr` from the engine and the UI command table.for spec in designcraft_engine::command_specs() {keys.insert(spec.label);@@ -5085,6 +4852,8 @@ mod tests {"(unchanged)","[No Language]","Cell Number:",+ "Differs from this document",+ "Digits:","Change fill to:","Chinese: Simplified","Chinese: Traditional",@@ -5120,6 +4889,7 @@ mod tests {"Found","Grab bag","Key Object",+ "Load Styles","layer","layers","Lines +/−",@@ -5135,6 +4905,7 @@ mod tests {"Redefine Document Style","Report an issue","Reverse the order",+ "Sort Entries in Alphabetical Order","Story {story} ← story {parent}","Story Editor — {count} words","Text Anchor",@@ -5156,48 +4927,6 @@ mod tests {keys}- #[test]- fn czech_catalog_has_no_stale_keys_and_keeps_placeholders_and_markers() {- let catalog: HashMap<_, _> = cs::TABLE.iter().copied().collect();- assert_eq!(catalog.len(), cs::TABLE.len(), "duplicate Czech keys");- let keys = interface_strings();- // A new English string falls back to English until it is translated, so only stale- // entries (keys nothing passes to `tr` any more) fail.- let stale: Vec<_> = catalog.keys().filter(|k| !keys.contains(*k)).collect();- assert!(stale.is_empty(), "Czech entries for unknown keys: {stale:?}");- let placeholders =- |s: &str| s.split('{').skip(1).filter_map(|part| part.split_once('}').map(|(name, _)| name.to_owned())).collect::<Vec<_>>();- for (key, translation) in cs::TABLE {- assert!(!translation.trim().is_empty(), "empty {key}");- let mut source = placeholders(key);- let mut translated = placeholders(translation);- source.sort();- translated.sort();- assert_eq!(source, translated, "placeholders: {key}");- // Dialog ellipses, label colons and padded button captions stay as in English.- assert_eq!(key.ends_with('…'), translation.ends_with('…'), "ellipsis: {key}");- assert_eq!(key.ends_with(':'), translation.ends_with(':'), "colon: {key}");- assert_eq!(key.starts_with(' '), translation.starts_with(' '), "leading space: {key}");- assert_eq!(key.ends_with(' '), translation.ends_with(' '), "trailing space: {key}");- }- assert!(!is_rtl("cs"));- assert_eq!(tr("cs", "File"), "Soubor");- assert_eq!(tr("cs", "New Document…"), "Nový dokument…");- assert_eq!(tr("cs", "Spread"), "Dvoustrana");- assert_eq!(tr("cs", "Bleed"), "Spadávka");- assert_eq!(tr("cs", "Leading"), "Proklad");- assert_eq!(tr("cs", "Unknown label"), "Unknown label");- assert_eq!(tr_context("cs", "Group", "selection"), "Skupina");- assert_eq!(tr_context("cs", "Name", "contributors"), "Jméno");- assert_eq!(tr_context("cs", "Name", "unknown"), "Název");- assert_eq!(tr("cs", "Group"), "Seskupit");- assert_eq!(tr_context("cs", "Columns", "table"), tr("cs", "Columns"));- assert_eq!(style_name("cs", "[Basic Paragraph]"), "[Základní odstavec]");- assert_eq!(style_name("cs", "My layout style"), "My layout style");- assert_eq!(workspace_name("cs", "Essentials"), "Základní");- assert_eq!(workspace_name("cs", "My workspace"), "My workspace");- }-#[test]fn czech_counts_use_the_plural_form_for_the_number() {for (n, form) in [(0, "chyb"), (1, "chyba"), (2, "chyby"), (4, "chyby"), (5, "chyb"), (11, "chyb"), (22, "chyb")] {@@ -5222,51 +4951,4 @@ mod tests {assert!(forms.contains(&tr("cs", noun)), "{noun}: the catalog row is one of the plural forms");}}-- #[test]- fn czech_translates_every_tool_name() {- for tool in designcraft_tools::TOOL_GROUPS.iter().flat_map(|group| group.iter()) {- assert_ne!(tr("cs", tool.label), tool.label, "{}", tool.id);- assert_eq!(tr("", tool.label), tool.label);- }- }-- #[test]- fn japanese_vertical_type_commands_are_translated() {- for (en, ja) in [- ("Story Direction", "組み方向"),- ("Horizontal", "横書き"),- ("Vertical", "縦書き"),- ("Tate-Chu-Yoko", "縦中横"),- ("Ruby…", "ルビ…"),- ("Kenten", "圏点"),- ("Warichu", "割り注"),- ] {- assert_eq!(tr("ja", en), ja);- }- }-- #[test]- fn pdf_export_dialog_strings_are_translated() {- // Translated labels in every supported language.- assert_ne!(tr("zh", "Crop Marks"), "Crop Marks");- assert_ne!(tr("de", "Tagged PDF"), "Tagged PDF");- assert_ne!(tr("ar", "Include document bleed"), "Include document bleed");- assert_ne!(tr("pt-br", "Compress images"), "Compress images");- // English returns the key unchanged.- assert_eq!(tr("", "Export PDF"), "Export PDF");- // An unknown string still falls through unchanged.- assert_eq!(tr("de", "Low Quality Print"), "Low Quality Print");- // Fixed standard names stay identical in every language.- assert_eq!(tr("ja", "PDF/X-4"), "PDF/X-4");- }-- #[test]- fn style_row_menu_strings_are_translated_in_every_language() {- for (code, _) in LANGUAGES.iter().filter(|(c, _)| !c.is_empty()) {- for key in ["Redefine Style", "Alt-click clears overrides", "Apply \"{name}\", Clear Overrides"] {- assert_ne!(tr(code, key), key, "{code}: {key}");- }- }- }}diff --git a/crates/ui-egui/src/i18n/de.rs b/crates/ui-egui/src/i18n/de.rsindex d47657b09..4f4177cbd 100644--- a/crates/ui-egui/src/i18n/de.rs+++ b/crates/ui-egui/src/i18n/de.rs@@ -2037,7 +2037,6 @@ pub(super) const TABLE: &[(&str, &str)] = &[("Print Layer", "Ebene drucken"),("Suppress Text Wrap When Layer is Hidden", "Textumfluss bei ausgeblendeter Ebene unterdrücken"),// Remaining interface strings.- ("A custom name", "Ein eigener Name"),("Close Panel", "Bedienfeld schließen"),("Default Fill and Stroke", "Standardfläche und -kontur"),("Distribute Rows Evenly", "Zeilen gleichmäßig verteilen"),diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rsindex 18fa402a5..535c87629 100644--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@ -2460,7 +2460,7 @@ mod tests {assert_eq!(app.ui.status, "Table: No table selected");app.ui.language = "cs".into();app.status_error("Table", "No table selected");- assert_eq!(app.ui.status, "Tabulka: No table selected");+ assert_eq!(app.ui.status, format!("{}: No table selected", crate::i18n::tr("cs", "Table")));}#[test]diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rsindex 2a271324a..87537abd7 100644--- a/crates/ui-egui/src/menus.rs+++ b/crates/ui-egui/src/menus.rs@@ -3367,16 +3367,12 @@ mod tests {}#[test]- fn screen_mode_shows_the_current_mode_and_view_submenus_are_translated() {+ fn screen_mode_shows_the_current_mode() {let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());let mode = |app: &DesignApp, m: &str| checked(app, "view.screenMode", &json!({ "mode": m }));assert_eq!((mode(&app, "normal"), mode(&app, "preview")), (Some(true), Some(false)));app.ui.screen_mode = crate::ScreenMode::Preview;assert_eq!((mode(&app, "normal"), mode(&app, "preview")), (Some(false), Some(true)));- // Every View submenu has its Japanese path (Edit › Menus shows them).- for path in submenu_paths("View") {- assert_ne!(crate::i18n::tr("ja", &path), path, "{path} has no Japanese row");- }}fn walk(items: &[Item], out: &mut Vec<(String, String, Value)>) {@@ -3793,8 +3789,8 @@ mod tests {run_ui(&mut app, "app.language", &json!({"lang": "de"})).unwrap().unwrap();assert_eq!(app.ui.language, "de");assert_eq!(checked(&app, "app.language", &json!({"lang": "de"})), Some(true));- assert_eq!(crate::i18n::tr(&app.ui.language, "Window"), "Fenster");assert!(run_ui(&mut app, "app.language", &json!({"lang": "xx"})).unwrap().is_err());+ assert_eq!(app.ui.language, "de");// The language is set in Preferences, not from a menu; without `lang` the command opens it.let mut items = Vec::new();for (_, entries) in menu_tree() {@@ -3804,153 +3800,23 @@ mod tests {run_ui(&mut app, "app.language", &json!({})).unwrap().unwrap();assert_eq!(app.ui.dialog.as_ref().map(|d| d.id.as_str()), Some("preferences"));assert_eq!(app.ui.language, "de");- app.ui.dialog = None;-- run_ui(&mut app, "app.language", &json!({"lang": "zh"})).unwrap().unwrap();- assert_eq!(app.ui.language, "zh");- assert_eq!(crate::i18n::tr(&app.ui.language, "File"), "文件");-- app.run("file.new", json!({"pages": 4, "facingPages": true})).unwrap();- let before = serde_json::to_value(&app.session.doc().unwrap().doc).unwrap();- run_ui(&mut app, "app.language", &json!({"lang": "ar"})).unwrap().unwrap();- assert_eq!(app.ui.language, "ar");- assert_eq!(checked(&app, "app.language", &json!({"lang": "ar"})), Some(true));- assert_eq!(before, serde_json::to_value(&app.session.doc().unwrap().doc).unwrap());- for (title, _) in menu_tree() {- assert_ne!(crate::i18n::tr("ar", title), title, "{title}");- }- // Every menu title has a translation (Japanese never matches the English).- for (title, _) in menu_tree() {- assert_ne!(crate::i18n::tr("ja", title), title, "{title}");- }-- run_ui(&mut app, "app.language", &json!({"lang": "pt-br"})).unwrap().unwrap();- assert_eq!(app.ui.language, "pt-br");- assert_eq!(checked(&app, "app.language", &json!({"lang": "pt-br"})), Some(true));- for (title, _) in menu_tree() {- // "Layout" is the natural Brazilian Portuguese word, so it stays identical- // to English; every other title must be translated.- if title != "Layout" {- assert_ne!(crate::i18n::tr("pt-br", title), title, "{title}");- }- }-- run_ui(&mut app, "app.language", &json!({"lang": "it"})).unwrap().unwrap();- assert_eq!(app.ui.language, "it");- assert_eq!(checked(&app, "app.language", &json!({"lang": "it"})), Some(true));- for (title, _) in menu_tree() {- // "File" and "Layout" are the usual Italian menu names, so they stay identical- // to English; every other title must be translated.- if title != "File" && title != "Layout" {- assert_ne!(crate::i18n::tr("it", title), title, "{title}");- }- }-- run_ui(&mut app, "app.language", &json!({"lang": "ka"})).unwrap().unwrap();- assert_eq!(app.ui.language, "ka");- assert_eq!(checked(&app, "app.language", &json!({"lang": "ka"})), Some(true));- // Every menu title, item and submenu is translated into Georgian.- let mut untranslated = Vec::new();- for (title, entries) in menu_tree() {- let mut labels = vec![title.to_string()];- let mut stack: Vec<&Item> = entries.iter().collect();- while let Some(entry) = stack.pop() {- match entry {- Item::Sub(label, children) => {- labels.push(label.clone());- stack.extend(children.iter());- }- Item::Cmd { label, id, .. } if id != "app.language" => labels.push(label.clone()),- _ => {}- }- }- // Labels without letters ("180°") or point sizes ("72 pt") read the same in every language.- let size = |l: &str| l.strip_suffix(" pt").is_some_and(|n| !n.is_empty() && n.chars().all(|c| c.is_ascii_digit()));- untranslated- .extend(labels.into_iter().filter(|l| l.chars().any(char::is_alphabetic) && !size(l) && crate::i18n::tr("ka", l) == l.as_str()));- }- assert!(untranslated.is_empty(), "untranslated Georgian menu labels: {untranslated:?}");}#[test]- fn ukrainian_language_is_selectable_persisted_and_keeps_document_data() {+ fn every_interface_language_is_selectable_persisted_and_keeps_document_data() {let mut app = crate::DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());app.run("file.new", json!({"pages": 4, "facingPages": true})).unwrap();- app.run("frame.create", json!({"rect": [36, 36, 200, 200], "content": "text", "text": "My words · Мої слова"})).unwrap();+ app.run("frame.create", json!({"rect": [36, 36, 200, 200], "content": "text", "text": "My words · Мої слова · Zażółć gęślą jaźń"})).unwrap();let before = serde_json::to_value(&app.session.doc().unwrap().doc).unwrap();- run_ui(&mut app, "app.language", &json!({"lang": "uk"})).unwrap().unwrap();- assert_eq!(checked(&app, "app.language", &json!({"lang": "uk"})), Some(true));- assert_eq!(before, serde_json::to_value(&app.session.doc().unwrap().doc).unwrap());- for (title, _) in menu_tree() {- assert_ne!(crate::i18n::tr("uk", title), title, "{title}");+ for (code, _) in crate::i18n::LANGUAGES {+ run_ui(&mut app, "app.language", &json!({"lang": code})).unwrap().unwrap();+ assert_eq!(app.ui.language, *code);+ assert_eq!(checked(&app, "app.language", &json!({"lang": code})), Some(true), "{code}");+ assert_eq!(before, serde_json::to_value(&app.session.doc().unwrap().doc).unwrap(), "{code}");+ let bytes = serde_json::to_vec(&app.ui).unwrap();+ let restored: crate::UiState = serde_json::from_slice(&bytes).unwrap();+ assert_eq!(restored.language, *code);}- let bytes = serde_json::to_vec(&app.ui).unwrap();- let restored: crate::UiState = serde_json::from_slice(&bytes).unwrap();- assert_eq!(restored.language, "uk");- assert_eq!(crate::i18n::tr(&restored.language, "File"), "Файл");- assert_eq!(crate::i18n::tr(&restored.language, "A custom name"), "A custom name");- assert!(crate::i18n::LANGUAGES.contains(&("uk", "Українська")), "Preferences lists Ukrainian by its own name");- }-- #[test]- fn russian_language_is_selectable_persisted_and_keeps_document_data() {- let mut app = crate::DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());- app.run("file.new", json!({"pages": 4, "facingPages": true})).unwrap();- app.run("frame.create", json!({"rect": [36, 36, 200, 200], "content": "text", "text": "My words · Мои слова"})).unwrap();- let before = serde_json::to_value(&app.session.doc().unwrap().doc).unwrap();- run_ui(&mut app, "app.language", &json!({"lang": "ru"})).unwrap().unwrap();- assert_eq!(checked(&app, "app.language", &json!({"lang": "ru"})), Some(true));- assert_eq!(before, serde_json::to_value(&app.session.doc().unwrap().doc).unwrap());- for (title, _) in menu_tree() {- assert_ne!(crate::i18n::tr("ru", title), title, "{title}");- }- let bytes = serde_json::to_vec(&app.ui).unwrap();- let restored: crate::UiState = serde_json::from_slice(&bytes).unwrap();- assert_eq!(restored.language, "ru");- assert_eq!(crate::i18n::tr(&restored.language, "File"), "Файл");- assert_eq!(crate::i18n::tr(&restored.language, "A custom name"), "A custom name");- assert!(crate::i18n::LANGUAGES.contains(&("ru", "Русский")), "Preferences lists Russian by its own name");- }-- #[test]- fn czech_language_is_selectable_persisted_and_keeps_document_data() {- let mut app = crate::DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());- app.run("file.new", json!({"pages": 4, "facingPages": true})).unwrap();- app.run("frame.create", json!({"rect": [36, 36, 200, 200], "content": "text", "text": "My words · Příliš žluťoučký kůň"})).unwrap();- let before = serde_json::to_value(&app.session.doc().unwrap().doc).unwrap();- run_ui(&mut app, "app.language", &json!({"lang": "cs"})).unwrap().unwrap();- assert_eq!(app.ui.language, "cs");- assert_eq!(checked(&app, "app.language", &json!({"lang": "cs"})), Some(true));- assert_eq!(before, serde_json::to_value(&app.session.doc().unwrap().doc).unwrap());- for (title, _) in menu_tree() {- assert_ne!(crate::i18n::tr("cs", title), title, "{title}");- }- let bytes = serde_json::to_vec(&app.ui).unwrap();- let restored: crate::UiState = serde_json::from_slice(&bytes).unwrap();- assert_eq!(restored.language, "cs");- assert_eq!(crate::i18n::tr(&restored.language, "File"), "Soubor");- assert_eq!(crate::i18n::tr(&restored.language, "A custom name"), "A custom name");- assert!(crate::i18n::LANGUAGES.contains(&("cs", "Čeština")), "Preferences lists Czech by its own name");- }-- #[test]- fn polish_language_is_selectable_persisted_and_keeps_document_data() {- let mut app = crate::DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());- app.run("file.new", json!({"pages": 2, "facingPages": true})).unwrap();- app.run("frame.create", json!({"rect": [36, 36, 200, 200], "content": "text", "text": "Zażółć gęślą jaźń"})).unwrap();- let before = serde_json::to_value(&app.session.doc().unwrap().doc).unwrap();- run_ui(&mut app, "app.language", &json!({"lang": "pl"})).unwrap().unwrap();- assert_eq!(app.ui.language, "pl");- assert_eq!(checked(&app, "app.language", &json!({"lang": "pl"})), Some(true));- assert_eq!(before, serde_json::to_value(&app.session.doc().unwrap().doc).unwrap());- for (title, _) in menu_tree() {- assert_ne!(crate::i18n::tr("pl", title), title, "{title}");- }- let bytes = serde_json::to_vec(&app.ui).unwrap();- let restored: crate::UiState = serde_json::from_slice(&bytes).unwrap();- assert_eq!(restored.language, "pl");- assert_eq!(crate::i18n::tr(&restored.language, "File"), "Plik");- assert!(crate::i18n::LANGUAGES.contains(&("pl", "Polski")), "Preferences lists Polish by its own name");}#[test]@@ -4993,9 +4859,10 @@ mod tests {fn command_search_matches_labels_in_the_interface_language() {let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());app.ui.language = "de".into();- let items = command_search(&app, "gruppieren");+ let label = crate::i18n::tr("de", "Group");+ let items = command_search(&app, &label.to_lowercase());let group = items.iter().find(|i| i.id == "object.group").unwrap();- assert_eq!(group.label, "Gruppieren");+ assert_eq!(group.label, label);assert_eq!(group.shortcut.as_deref(), Some("Cmd+G"));assert!(command_search(&app, "group").iter().any(|i| i.id == "object.group"), "English labels match too");assert!(command_search(&app, " ").is_empty());@@ -5652,9 +5519,6 @@ mod tests {// Language follows Settings, as in the suite's other apps, titled in the interface language.assert_eq!(MAC_APP_MENU.get(settings + 1), Some(&AppMenuItem::Language));assert_eq!(MAC_APP_MENU.get(settings + 2), Some(&AppMenuItem::Sep));- for (code, _) in crate::i18n::LANGUAGES.iter().filter(|(c, _)| !c.is_empty()) {- assert_ne!(crate::i18n::tr(code, "Language"), "Language", "{code}");- }let label = |command: &str| {MAC_APP_MENU.iter().find_map(|m| match m {AppMenuItem::Cmd { label, command: c, .. } if *c == command => Some(*label),@@ -5662,7 +5526,6 @@ mod tests {})};assert_eq!(label("app.preferences"), Some("Settings…"));- assert_ne!(crate::i18n::tr("de", "Settings…"), "Settings…");let ids = MAC_APP_MENU.iter().filter_map(|m| if let AppMenuItem::Cmd { id, .. } = m { Some(*id) } else { None }).collect::<Vec<_>>();assert!(ids.iter().enumerate().all(|(i, id)| !ids[..i].contains(id)), "native ids are unique: {ids:?}");diff --git a/crates/ui-egui/src/panels/properties.rs b/crates/ui-egui/src/panels/properties.rsindex 1cbd623a6..fd0094f9b 100644--- a/crates/ui-egui/src/panels/properties.rs+++ b/crates/ui-egui/src/panels/properties.rs@@ -3148,8 +3148,19 @@ mod tests {/// are translated, with a sample of each script's figures.#[test]fn digits_choices_use_the_reference_names() {- let shown: Vec<String> = DIGIT_OPTIONS.iter().map(|o| digit_label("fr", *o)).collect();- assert_eq!(shown, ["Par défaut", "Arabe 0123", "Hindi ٠١٢٣", "Persan ۰۱۲۳", "Natif"].map(String::from));+ assert_eq!(DIGIT_OPTIONS.map(|o| o.1), ["Default", "Arabic", "Hindi", "Farsi", "Native"]);+ for (lang, _) in crate::i18n::LANGUAGES {+ let tr = |s| crate::i18n::tr(lang, s);+ let shown: Vec<String> = DIGIT_OPTIONS.iter().map(|o| digit_label(lang, *o)).collect();+ let expected = [+ tr("Default").to_string(),+ format!("{} 0123", tr("Arabic")),+ format!("{} ٠١٢٣", tr("Hindi")),+ format!("{} ۰۱۲۳", tr("Farsi")),+ tr("Native").to_string(),+ ];+ assert_eq!(shown, expected, "{lang}");+ }}#[test]