diff --git a/crates/ui-egui/src/i18n/tests.rs b/crates/ui-egui/src/i18n/tests.rs index 1ef955c627..9e3cf16398 100644 --- a/crates/ui-egui/src/i18n/tests.rs +++ b/crates/ui-egui/src/i18n/tests.rs @@ -805,16 +805,15 @@ fn anti_aliasing_method_labels_are_in_complete_catalogs() { } /// Each row in the `search` context, which adds a language's words to a group of words with the same -/// meaning for the command palette, names a group and adds single words of no other group. No -/// catalog has to have these rows. +/// meaning for the command palette, names a group and adds single words of no other group, and no +/// two rows of a catalog add one word to different groups. No catalog has to have these rows. #[test] fn search_rows_name_a_group_and_add_single_words() { let mut bad = Vec::new(); for l in LANGUAGES.iter().filter(|l| !l.source.is_empty()) { let (entries, _) = parse_entries(l.source); - for (_, src, tr) in entries.iter().filter(|(ctx, _, _)| ctx == crate::palette::words::CONTEXT) { - bad.extend(crate::palette::words::row_problems(src, tr).into_iter().map(|p| format!("{}: {p}", l.code))); - } + let rows = entries.iter().filter(|(ctx, _, _)| ctx == crate::palette::words::CONTEXT).map(|(_, src, tr)| (src.as_str(), tr.as_str())); + bad.extend(crate::palette::words::catalog_problems(rows).into_iter().map(|p| format!("{}: {p}", l.code))); } assert!(bad.is_empty(), "{bad:#?}"); } diff --git a/crates/ui-egui/src/palette/words.rs b/crates/ui-egui/src/palette/words.rs index 44176dbd24..86c03bfb8c 100644 --- a/crates/ui-egui/src/palette/words.rs +++ b/crates/ui-egui/src/palette/words.rs @@ -91,6 +91,27 @@ pub(crate) fn row_problems(source: &str, text: &str) -> Vec { problems } +/// What is wrong with one catalog's `search` rows, each a group's `source` and its translation +/// `text`: each row's [`row_problems`], and a word that rows add to two different groups. +#[cfg(test)] +pub(crate) fn catalog_problems<'a>(rows: impl IntoIterator) -> Vec { + let mut problems = vec![]; + let mut groups: std::collections::HashMap = std::collections::HashMap::new(); + for (source, text) in rows { + problems.extend(row_problems(source, text)); + for (w, _) in row_words(text).filter(|(_, single)| *single) { + match groups.get(w.as_str()) { + Some(&first) if first != source => problems.push(format!("{w:?} is a word of {first:?} and {source:?}")), + Some(_) => {} + None => { + groups.insert(w, source); + } + } + } + } + problems +} + #[cfg(test)] mod tests { use super::*; @@ -122,4 +143,16 @@ mod tests { assert_eq!(row_problems("remove, delete, erase, clear", "ganz entfernen").len(), 1, "two words"); assert_eq!(row_problems("remove, delete, erase, clear", "Text").len(), 1, "a word of another group once lowercased"); } + + /// A catalog's rows fail when they add one word to two groups, and pass when a word is repeated + /// for one group or the catalog has no rows. + #[test] + fn a_word_in_two_groups_of_a_catalog_is_checked() { + let (remove, artboard) = ("remove, delete, erase, clear", "artboard, canvas"); + let problems = catalog_problems([(remove, "retrait"), (artboard, "plan, Retrait")]); + assert_eq!(problems.len(), 1, "{problems:?}"); + assert!(problems.iter().all(|p| p.contains("retrait") && p.contains(remove) && p.contains(artboard)), "{problems:?}"); + assert!(catalog_problems([(remove, "retrait, retrait"), (remove, "Retrait"), (artboard, "plan")]).is_empty()); + assert!(catalog_problems([]).is_empty()); + } }