From 750e01acd67d6bf61d8a9588c8d41a174246fa64 Mon Sep 17 00:00:00 2001 From: Samuel Guerra Date: Fri, 26 May 2023 20:53:48 -0300 Subject: [PATCH] Fixed sys-lang in Windows 10. --- TODO/_current.md | 7 ++----- examples/localize.rs | 8 ++++---- zero-ui-view/Cargo.toml | 6 ++++++ zero-ui-view/src/config.rs | 11 ++++++++++- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/TODO/_current.md b/TODO/_current.md index b5ad17e86..868d39022 100644 --- a/TODO/_current.md +++ b/TODO/_current.md @@ -26,11 +26,8 @@ # Localization * Test system lang change. - - Windows forces a log-out to change lang, how to test the event? - -* Windows lang preferences still wrong, MS added a COM api that overrides what we are using. - - See https://searchfox.org/mozilla-central/source/intl/locale/windows/OSPreferences_win.cpp#87 - - This is a WRT COM thing, not sure if can be called with "windows-sys" only. + - Does not update after first system change? + - Event is received, sys_lang is set. * A trait that provides the available locales and locales on demand. - Replace `L10N.load_dir` with this trait. diff --git a/examples/localize.rs b/examples/localize.rs index c282efdca..ba2597474 100644 --- a/examples/localize.rs +++ b/examples/localize.rs @@ -13,16 +13,16 @@ use zero_ui::core::l10n::{Lang, LangMap, L10N}; // Run this command to scrap template: // cargo run -p zero-ui-l10n-scraper -- -i"examples/localize*" -o"examples/res/localize" -// use zero_ui_view_prebuilt as zero_ui_view; +use zero_ui_view_prebuilt as zero_ui_view; fn main() { examples_util::print_info(); - // zero_ui_view::init(); + zero_ui_view::init(); // let rec = examples_util::record_profile("localize"); - zero_ui_view::run_same_process(app_main); - // app_main(); + // zero_ui_view::run_same_process(app_main); + app_main(); // rec.finish(); } diff --git a/zero-ui-view/Cargo.toml b/zero-ui-view/Cargo.toml index ec105675d..6c3b91a5b 100644 --- a/zero-ui-view/Cargo.toml +++ b/zero-ui-view/Cargo.toml @@ -91,6 +91,12 @@ features = [ "Win32_Graphics_OpenGL", "Win32_UI_Accessibility", ] +[target.'cfg(windows)'.dependencies.windows] +version = "0.48.0" +features = [ + "Foundation_Collections", + "System_UserProfile" +] [target.'cfg(not(windows))'.dependencies] sys-locale = "0.3" diff --git a/zero-ui-view/src/config.rs b/zero-ui-view/src/config.rs index 229d03966..6170920a9 100644 --- a/zero-ui-view/src/config.rs +++ b/zero-ui-view/src/config.rs @@ -364,13 +364,22 @@ pub(crate) fn locale_config() -> LocaleConfig { #[cfg(windows)] pub(crate) fn locale_config() -> LocaleConfig { - // sys_locale returns only one lang, this code adapted from `whoami` crate. + // sys_locale returns only one lang, this code adapted from `whoami` crate and Firefox. + use windows::System::UserProfile::GlobalizationPreferences; use windows_sys::Win32::{ Foundation::FALSE, Globalization::{GetUserPreferredUILanguages, MUI_LANGUAGE_NAME}, }; + // Try newer WinRT COM API (Windows8+) + if let Ok(r) = GlobalizationPreferences::Languages() { + let r: Vec = r.into_iter().map(|l| l.to_string_lossy()).collect(); + if !r.is_empty() { + return LocaleConfig { langs: r }; + } + } + let mut num_languages = 0; let mut buffer_size = 0; let mut buffer;