From 8243f2a856956ea7e88847cf2e52e45e40f0cb07 Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Tue, 23 Jun 2026 14:02:04 -0600 Subject: [PATCH] i18n: language selector switches translations live + persists Wire the Appearance language selector (appearance-select "language"): map the dropdown index to a language key via the verified order (0 Auto, 1 English, 2 Espanol, 3 Francais, 4 Deutsch, 5 Portugues), persist the raw user choice, resolve "auto", then set_language() + select_bundled_translation() to switch all @tr bindings live with no restart. Seed the selector index from the persisted key at startup. cc --- crates/qbz-slint/src/main.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/crates/qbz-slint/src/main.rs b/crates/qbz-slint/src/main.rs index 571d59cb9..371249491 100644 --- a/crates/qbz-slint/src/main.rs +++ b/crates/qbz-slint/src/main.rs @@ -4859,6 +4859,12 @@ fn main() -> Result<(), Box> { window.global::().set_startup_page_index( crate::ui_prefs::startup_page_index(&crate::ui_prefs::load().startup_page), ); + // Language selector: seed the dropdown index from the persisted key (the raw + // user choice, "auto" -> index 0). The live translation was already applied + // before the window was created. + window.global::().set_language_index( + crate::ui_prefs::language_index(&crate::ui_prefs::load().language), + ); // Theme: seed the dropdown list from the Rust registry, then restore the // persisted theme (slug is the source of truth; the dropdown index is @@ -6910,6 +6916,27 @@ fn main() -> Result<(), Box> { prefs.startup_page = crate::ui_prefs::startup_page_for_index(index).to_string(); crate::ui_prefs::save(&prefs); } + "language" => { + // 0 = Auto, 1 = English, 2 = Español, 3 = Français, 4 = Deutsch, + // 5 = Português. Persist the RAW user choice ("auto" stays + // "auto"), but resolve "auto" to a concrete language before + // switching the live translations. + let chosen = crate::ui_prefs::language_for_index(index); + let mut prefs = crate::ui_prefs::load(); + prefs.language = chosen.to_string(); + crate::ui_prefs::save(&prefs); + let lang = if chosen == "auto" { + qbz_i18n::resolve_auto() + } else { + chosen + }; + qbz_i18n::set_language(lang); + if let Err(e) = slint::select_bundled_translation(lang) { + log::warn!( + "[qbz-slint] select_bundled_translation('{lang}') failed: {e:?}" + ); + } + } "theme" => { // Slug is the source of truth: map the dropdown index -> stable // id, persist the slug, then hot-switch the live palette.