Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Tests: the same language on every PC (#10297) (#10298)

CamWight9d7544929e44
diff --git a/crates/ui-egui/src/i18n.rs b/crates/ui-egui/src/i18n.rs
index db623ddeb5..67ca10b912 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::<Vec<_>>()))
+ 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::<Vec<_>>()) }
+ })
+}
+
+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 d64c99ee9a..0864b2d1c6 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 277466f1ca..36c7b3b098 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 e5c196fac1..5d549e6441 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 2e71098dfd..a195be2029 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