Fixed sys-lang in Windows 10.

This commit is contained in:
Samuel Guerra 2023-05-26 20:53:48 -03:00
parent 69d47b8ee2
commit 750e01acd6
4 changed files with 22 additions and 10 deletions

View File

@ -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.

View File

@ -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();
}

View File

@ -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"

View File

@ -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<String> = 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;