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 <noreply@anthropic.com>
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user