From 45effdce12b4545bf6f46fd598cd170912faf521 Mon Sep 17 00:00:00 2001 From: Martin Ball Date: Sun, 8 Nov 2026 22:29:10 +0000 Subject: [PATCH] test(i18n): check Layer Via and rasterize-prompt keys in the craft-i18n catalogs Both tests walked src/i18n/*.tsv, which this branch deletes: the Layer Via count would fail and the rasterize check passed on no files. They now read the embedded catalogs, skip commented rows, and skip without craft-i18n. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/layer_via_label_tests.rs | 30 +++++++++---------- .../src/rasterize_prompt_text_tests.rs | 11 +++---- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/crates/ui-egui/src/layer_via_label_tests.rs b/crates/ui-egui/src/layer_via_label_tests.rs index b8a20c3b27..c5832136fb 100644 --- a/crates/ui-egui/src/layer_via_label_tests.rs +++ b/crates/ui-egui/src/layer_via_label_tests.rs @@ -1,5 +1,5 @@ //! "Layer Via Copy" and "Layer Via Cut" carry a capital V in every menu, as in the reference -//! application (#12357), and every translation moved with the key. +//! application (#12357), and every translation moved with the key in the craft-i18n catalogs. use crate::canvas::canvas_tool_menu::SELECTION_MENU; use crate::menu_catalog::CATALOG; @@ -34,29 +34,29 @@ fn selection_tools_canvas_menu_uses_the_capital_v() { } #[test] -fn every_locale_file_keeps_its_translation_under_the_new_keys() { - let dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("src/i18n"); +fn every_locale_catalog_keeps_its_translation_under_the_new_keys() { + if !crate::i18n::needs_catalogs() { + return; + } let mut checked = 0; - for entry in std::fs::read_dir(dir).expect("i18n dir") { - let path = entry.expect("entry").path(); - if path.extension().and_then(|e| e.to_str()) != Some("tsv") { - continue; - } - let text = std::fs::read_to_string(&path).expect("tsv"); - let keys: Vec<&str> = text.lines().filter_map(|l| l.split('\t').nth(1)).collect(); - let name = path.display(); - assert!(OLD.iter().all(|o| !keys.contains(o)), "{name} still has an old key"); - // Hindi has no entries for these menus yet; every other file has both. + for (code, _, catalog) in crate::i18n::CRAFT_I18N { + // Rows are `context English translation`; `#` starts a comment. + let keys: Vec<&str> = catalog.lines().filter(|l| !l.starts_with('#')).filter_map(|l| l.split('\t').nth(1)).collect(); + assert!(OLD.iter().all(|o| !keys.contains(o)), "{code} still has an old key"); + // Hindi has no entries for these menus yet; every other catalog has both. if keys.contains(&"Layer Via Copy") || keys.contains(&"Layer Via Cut") { - assert!(NEW.iter().all(|(n, _)| keys.contains(n)), "{name} lacks a new key"); + assert!(NEW.iter().all(|(n, _)| keys.contains(n)), "{code} lacks a new key"); checked += 1; } } - assert!(checked >= 30, "only {checked} locale files carry the keys"); + assert!(checked >= 30, "only {checked} locale catalogs carry the keys"); } #[test] fn a_translation_is_found_under_the_new_key() { + if !crate::i18n::needs_catalogs() { + return; + } let de = crate::i18n::Lang::from_code("de").expect("German"); assert_eq!(crate::i18n::tr(de, "Layer Via Copy"), "Ebene durch Kopieren"); assert_eq!(crate::i18n::tr(de, "Layer Via Cut"), "Ebene durch Ausschneiden"); diff --git a/crates/ui-egui/src/rasterize_prompt_text_tests.rs b/crates/ui-egui/src/rasterize_prompt_text_tests.rs index 651a4ceb97..25ef1fa43d 100644 --- a/crates/ui-egui/src/rasterize_prompt_text_tests.rs +++ b/crates/ui-egui/src/rasterize_prompt_text_tests.rs @@ -31,12 +31,9 @@ fn catalogs_that_had_a_translation_keep_one() { let de = Lang::from_code("de").expect("German"); assert_eq!(tr(de, new), new); // No catalog keeps the old key. - let dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("src/i18n"); - for entry in std::fs::read_dir(&dir).unwrap() { - let path = entry.unwrap().path(); - if path.extension().is_some_and(|e| e == "tsv") { - let text = std::fs::read_to_string(&path).unwrap(); - assert!(!text.contains(OLD), "{} still has the old key", path.display()); - } + for (code, _, catalog) in crate::i18n::CRAFT_I18N { + // Rows are `context English translation`; `#` starts a comment. + let mut keys = catalog.lines().filter(|l| !l.starts_with('#')).filter_map(|l| l.split('\t').nth(1)); + assert!(keys.all(|k| k != OLD), "{code} still has the old key"); } }