Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

Merge pull request #1470 from nikolainyegaard/language-picker-order

Brandon Thomasae550aa67059
diff --cc crates/ui-egui/src/i18n.rs
index 49148723a,60b827dc3..be5f43c97
--- a/crates/ui-egui/src/i18n.rs
+++ b/crates/ui-egui/src/i18n.rs
@@@ -4935,13 -5073,112 +4945,52 @@@ mod tests
#[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")] {
- assert_eq!(count_label("cs", "errors", n), format!("{n} {form}"));
+ for (noun, [one, few, other]) in cs::PLURALS {
+ for (n, form) in [(0, other), (1, one), (2, few), (4, few), (5, other), (11, other), (22, other)] {
+ let expected = if form.trim().is_empty() { format!("{n} {}", tr("cs", noun)) } else { format!("{n} {form}") };
+ assert_eq!(count_label("cs", noun, n), expected, "{noun}");
+ }
}
- // The status bar passes the singular noun for one error.
- assert_eq!(count_label("cs", "error", 1), "1 chyba");
- assert_eq!(count_label("cs", "pages", 1), "1 stránka");
- assert_eq!(count_label("cs", "pages", 3), "3 stránky");
- assert_eq!(count_label("cs", "pages", 5), "5 stránek");
- assert_eq!(count_label("cs", "stories", 2), "2 články");
- assert_eq!(count_label("cs", "items", 1), "1 položka");
- assert_eq!(count_label("cs", "objects", 7), "7 objektů");
- assert_eq!(count_label("cs", "warnings", 3), "3 varování");
- assert_eq!(count_label("cs", "layer", 1), "1 vrstva");
- assert_eq!(count_label("cs", "layers", 3), "3 vrstvy");
- assert_eq!(count_label("cs", "layers", 8), "8 vrstev");
// A noun without plural forms keeps the plain translation.
assert_eq!(count_label("cs", "a new noun", 3), "3 a new noun");
- for (noun, forms) in cs::PLURALS {
- assert!(forms.iter().all(|form| !form.is_empty()), "{noun}");
- 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}");
- }
- }
}
}
+
+ /// `name` lowercased with the Latin accents that occur in language names folded away, so a
+ /// byte-wise sort reads alphabetically. Other scripts are left as they are.
+ fn name_sort_key(name: &str) -> String {
+ name.chars()
+ .flat_map(char::to_lowercase)
+ .map(|c| match c {
+ 'à'..='å' | 'ā' | 'ă' | 'ą' => 'a',
+ 'ç' | 'ć' | 'č' => 'c',
+ 'è'..='ë' | 'ē' | 'ě' | 'ę' | 'ế' | 'ệ' => 'e',
+ 'ì'..='ï' | 'ī' => 'i',
+ 'ñ' | 'ń' | 'ň' => 'n',
+ 'ò'..='ö' | 'ø' | 'ő' => 'o',
+ 'ś' | 'š' => 's',
+ 'ù'..='ü' | 'ū' | 'ů' | 'ű' => 'u',
+ 'ý' | 'ÿ' => 'y',
+ 'ź' | 'ż' | 'ž' => 'z',
+ c => c,
+ })
+ .collect()
+ }
+
+ #[cfg(test)]
+ mod picker_order_tests {
+ use super::*;
+
+ #[test]
+ fn picker_lists_english_first_then_names_alphabetically() {
+ let order = picker_languages();
+ assert_eq!(order.first(), Some(&("", "English")));
+ assert_eq!(order.len(), LANGUAGES.len());
+ let keys: Vec<String> = order[1..].iter().map(|(_, name)| name_sort_key(name)).collect();
+ assert!(keys.windows(2).all(|w| w[0] <= w[1]), "{keys:?}");
+ let pos = |code: &str| order.iter().position(|(c, _)| *c == code).unwrap_or(usize::MAX);
+ assert!(pos("cs") < pos("de"), "Čeština sorts under C");
+ assert!(pos("pl") < pos("ru"), "Latin names come before Cyrillic");
+ assert!(pos("ru") < pos("ja"), "Cyrillic names come before CJK");
+ }
+ }