-
-
Notifications
You must be signed in to change notification settings - Fork 307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
better l18n support in webview (navigator.language) #442
Comments
I switched the MacOS system language setting from "English" to "Japanese" and it seems to be working as intended. |
edit: ahh it's WSL2, maybe that's the problem. |
I can't find a way to change it in Windows though :( |
Looks like this is the way to read and set the language in webview2: https://docs.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2environmentoptions.language?view=webview2-dotnet-1.0.902.49 |
It looks good. I will try to implement it. |
I manage to overwrite let options: ICoreWebView2EnvironmentOptions = CoreWebView2EnvironmentOptions::default().into();
let mut language = String::from("pt-BR\0").encode_utf16().collect::<Vec<u16>>();
let lang = PWSTR(text.as_mut_ptr());
options.SetLanguage(lang); |
And an ugly code to read it: let mut buffer = Vec::<u16>::with_capacity(6);
let mut lang = PWSTR(buffer.as_mut_ptr());
options.Language(&mut lang);
let buffer = unsafe { std::slice::from_raw_parts(lang.0, 5) };
let lang = String::from_utf16_lossy(buffer); oh boy it's hard to learn the windows api :| |
I found this issue. |
invalid in Windows |
Hey there. If you have a time, could you run this branch and tell me whether this works or not on windows. |
@keiya01 it works perfectly on my x86 Windows machine. Don't worry about ARM now. we can fix it later if someone else reports it. |
Wooo! Thank you @amrbashir !! |
on a second test, I'll still merge the PR since it does have the desired effect on some other i18n components like |
Are there any news about this issue? @amrbashir |
@John0x please file a new issue with the results an full |
Is your feature request related to a problem? Please describe.
I want to rely on
navigator.language
ornavigator.languages
in the webview to determine which language a user prefers and to then translate the app.On WSL 2 / Ubuntu 20 the language is just "c", on Windows 10 with WebView2 it does not respect language settings on the system or browser (Edge) level, on native Ubuntu 20 it had a language that was actually more accurate then the system setting, but did not respect the system setting as well. I don't have access to a macos device.
Describe the solution you'd like
Ideally
navigator.language
ornavigator.languages
contain languages that match the system level user preferences.Describe alternatives you've considered
One could call system level APIs (different for every platform, i guess) from Rust to determine the preferences and expose those to Rust and finally the webview. Without changing
navigator.language
ornavigator.languages
this approach is not ideal, because some libraries rely on those fields. Maybe an approach where those preferences are exposed on thenavigator
and additionally have exposed to Rust and Webview via functions.The text was updated successfully, but these errors were encountered: