From 9d7544929e44edd2d4c1413b2bcddc8bf514ab18 Mon Sep 17 00:00:00 2001 From: CamWight <91156642+CamWight@users.noreply.github.com> Date: Mon, 2 Nov 2026 00:11:16 +0000 Subject: [PATCH] Tests: the same language on every PC (#10297) (#10298) Since #10183 the app follows the system's language, and the tests followed it too, so a test naming an English word failed on a PC set to another language. CI's runners read as English and never saw it. In tests the system's language is now English: `cfg!(test)` for this crate's own tests, as the engine's folders do, and the harness for the tests outside it. The preference stays `system`, and the app is unchanged. Co-authored-by: Claude Opus 5.5 --- crates/ui-egui/src/i18n.rs | 20 ++++++++++++++++++-- crates/ui-egui/src/prefs.rs | 3 +-- crates/ui-egui/src/scenario.rs | 1 + crates/ui-egui/tests/ui_layout.rs | 8 ++++++++ docs/localization.md | 3 ++- 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/crates/ui-egui/src/i18n.rs b/crates/ui-egui/src/i18n.rs index db623ddeb..67ca10b91 100644 --- a/crates/ui-egui/src/i18n.rs +++ b/crates/ui-egui/src/i18n.rs @@ -154,8 +154,18 @@ pub fn match_system_tags(tags: &[String]) -> &'static str { /// The catalog id the system asks for, read once per process: the OS locale on desktop /// (Windows, macOS, Linux/BSD) and `navigator.languages` in the browser. pub fn system_language() -> &'static str { - static CACHED: OnceLock<&'static str> = OnceLock::new(); - CACHED.get_or_init(|| match_system_tags(&sys_locale::get_locales().collect::>())) + SYSTEM_LANGUAGE.get_or_init(|| { + // Tests read the same words on every PC, whatever its language. + if cfg!(test) { ENGLISH.id } else { match_system_tags(&sys_locale::get_locales().collect::>()) } + }) +} + +static SYSTEM_LANGUAGE: OnceLock<&'static str> = OnceLock::new(); + +/// `cfg!(test)` for the tests outside this crate, which link it without that: they all start from +/// the test harness, which calls this first. +pub(crate) fn pin_system_language() { + let _ = SYSTEM_LANGUAGE.set(ENGLISH.id); } /// The catalog id a `language` preference resolves to: the saved choice, or the system's for @@ -409,6 +419,12 @@ mod tests { assert_eq!(super::match_system_tags(&tags(&["xx-YY", "de-DE"])), "de", "the first tag that matches wins"); } + /// Tests name English words, so the PC's own language never reaches them (#10297). + #[test] + fn tests_take_english_as_the_system_language() { + assert_eq!(super::system_language(), "en"); + } + /// A saved language is never overridden: only `system` resolves through the OS (#10138). #[test] fn a_saved_language_choice_is_never_overridden() { diff --git a/crates/ui-egui/src/prefs.rs b/crates/ui-egui/src/prefs.rs index d64c99ee9..0864b2d1c 100644 --- a/crates/ui-egui/src/prefs.rs +++ b/crates/ui-egui/src/prefs.rs @@ -8917,9 +8917,8 @@ mod tests { #[test] fn language_preference_switches_and_persists() { let mut app = SolveApp::new(solidcraft_engine::Session::default(), Default::default()); - // A first start follows the system (#10138); pin English so the words below are fixed. + // A first start follows the system (#10138), which is English in a test. assert_eq!(app.preferences.language, crate::i18n::SYSTEM); - app.preferences.language = "en".into(); assert_eq!(app.tr("ui.preferences"), "Preferences"); assert_eq!(app.tr("ui.extrude"), "Extrude"); diff --git a/crates/ui-egui/src/scenario.rs b/crates/ui-egui/src/scenario.rs index 277466f1c..36c7b3b09 100644 --- a/crates/ui-egui/src/scenario.rs +++ b/crates/ui-egui/src/scenario.rs @@ -178,6 +178,7 @@ impl Drop for Harness { impl Harness { pub fn new() -> Harness { + crate::i18n::pin_system_language(); let mut h = Harness { app: SolveApp::new(Session::default(), Services::default()), ctx: { diff --git a/crates/ui-egui/tests/ui_layout.rs b/crates/ui-egui/tests/ui_layout.rs index e5c196fac..5d549e644 100644 --- a/crates/ui-egui/tests/ui_layout.rs +++ b/crates/ui-egui/tests/ui_layout.rs @@ -20,6 +20,14 @@ fn harness() -> Harness { h } +/// These tests and the scenarios name English words, whatever the PC's language (#10297). +#[test] +fn the_harness_takes_english_as_the_system_language() { + let h = Harness::new(); + assert_eq!(h.app.preferences.language, solidcraft_ui_egui::i18n::SYSTEM); + assert_eq!(solidcraft_ui_egui::i18n::effective_language(&h.app.preferences.language), "en"); +} + #[test] fn every_dialog_opens_docked_within_its_width_limits() { let mut bad = Vec::new(); diff --git a/docs/localization.md b/docs/localization.md index 2e71098df..a195be202 100644 --- a/docs/localization.md +++ b/docs/localization.md @@ -10,7 +10,8 @@ the app then matches the system's preferred locales — the OS locale on desktop `navigator.languages` in the browser, read with the `sys-locale` crate — against the registry: exact tag, then base language, then English (`match_system_tags` in `crates/ui-egui/src/i18n.rs`). A saved specific language always wins, so existing users keep -their choice. +their choice. In tests and scenarios the system's language is English, so they read the same +words on every PC. ## Messages