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
fix: respect system language preferences on Windows & macOS #23247
Conversation
💖 Thanks for opening this pull request! 💖 We use semantic commit messages to streamline the release process. Before your pull request can be merged, you should update your pull request title to start with a semantic prefix. Examples of commit messages with semantic prefixes:
Things that will help get your PR across the finish line:
We get a lot of pull requests on this repo, so please be patient and we will get back to you as soon as we can. |
68ba39b
to
e5f23cb
Compare
I have a sample application to retrieve Windows 10's Preferred Language setting: https://github.com/hanazuki/win-accept-languages-sample This program makes use of GlobalizationPreferences.Languages from WinRT library, which is available since Windows 10 as with the Preferred Languages setting itself. Note on compatibility for old Windows:
I hope this will help. |
Nice. I regret that I did not imagine that Chrome should have such utility as Chrome is utilizing modern Windows APIs... |
Changed to utilize Globalization API when available. Now trying to fix failing CIs. |
CI Passed. Lint failure seems not relevant to my changes.. |
Opened #23266 for lint failure. |
ebcc0e9
to
02de6fa
Compare
rebased and only linux-ia32 is failing with flaky timeout. my change is ready. |
@@ -535,7 +535,7 @@ void WebContents::InitWithSessionAndOptions( | |||
managed_web_contents()->GetView()->SetDelegate(this); | |||
|
|||
auto* prefs = web_contents()->GetMutableRendererPrefs(); | |||
prefs->accept_languages = g_browser_process->GetApplicationLocale(); | |||
SetAcceptLanguages(prefs); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move the language preferences code into separate files and then reference it here? Like this:
#include "shell/common/lang_util.h"
prefs->accept_languages = GetSystemLanguage();
It would make the code easier to maintain, and we might want to reuse the code in other places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure where to put this kind of code. Extracted: d947ed9
Can you fix the lint waring?
|
Fixed, rebased & squashed. |
nah,
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, nice change 👍
This commit fixes electron#18829 Previously the full preferences set to OS was not given to Chromium. Also, this commit improves fallback font selection for CJK text. Chromium uses browser languages to determine fallback fonts on Windows, especially kanji/han characters in CJK. For instance, when user sets 'en-US, ja-JP' to Accept-Language, while Chromium chooses Japanese font for kanji text, but Electron chooses Chinese font. This is because only the first language was given to Accept-Language on Electron. This patch is based on electron#15532 Co-authored-by: Nitish Sakhawalkar <nitsakh@icloud.com> Co-authored-by: Kasumi Hanazuki <kasumi@rollingapple.net>
This commit fixes #18829 Previously the full preferences set to OS was not given to Chromium. Also, this commit improves fallback font selection for CJK text. Chromium uses browser languages to determine fallback fonts on Windows, especially kanji/han characters in CJK. For instance, when user sets 'en-US, ja-JP' to Accept-Language, while Chromium chooses Japanese font for kanji text, but Electron chooses Chinese font. This is because only the first language was given to Accept-Language on Electron. This patch is based on #15532 Co-authored-by: Nitish Sakhawalkar <nitsakh@icloud.com> Co-authored-by: Kasumi Hanazuki <kasumi@rollingapple.net> Co-authored-by: Nitish Sakhawalkar <nitsakh@icloud.com> Co-authored-by: Kasumi Hanazuki <kasumi@rollingapple.net>
This commit fixes #18829 Previously the full preferences set to OS was not given to Chromium. Also, this commit improves fallback font selection for CJK text. Chromium uses browser languages to determine fallback fonts on Windows, especially kanji/han characters in CJK. For instance, when user sets 'en-US, ja-JP' to Accept-Language, while Chromium chooses Japanese font for kanji text, but Electron chooses Chinese font. This is because only the first language was given to Accept-Language on Electron. This patch is based on #15532 Co-authored-by: Nitish Sakhawalkar <nitsakh@icloud.com> Co-authored-by: Kasumi Hanazuki <kasumi@rollingapple.net> Co-authored-by: Nitish Sakhawalkar <nitsakh@icloud.com> Co-authored-by: Kasumi Hanazuki <kasumi@rollingapple.net>
This commit fixes #18829 Previously the full preferences set to OS was not given to Chromium. Also, this commit improves fallback font selection for CJK text. Chromium uses browser languages to determine fallback fonts on Windows, especially kanji/han characters in CJK. For instance, when user sets 'en-US, ja-JP' to Accept-Language, while Chromium chooses Japanese font for kanji text, but Electron chooses Chinese font. This is because only the first language was given to Accept-Language on Electron. This patch is based on #15532 Co-authored-by: Nitish Sakhawalkar <nitsakh@icloud.com> Co-authored-by: Kasumi Hanazuki <kasumi@rollingapple.net> Co-authored-by: Nitish Sakhawalkar <nitsakh@icloud.com> Co-authored-by: Kasumi Hanazuki <kasumi@rollingapple.net> Co-authored-by: Sorah Fukumori <her@sorah.jp> Co-authored-by: Nitish Sakhawalkar <nitsakh@icloud.com> Co-authored-by: Kasumi Hanazuki <kasumi@rollingapple.net>
thank you for treating this patch as a fix! 🤗 |
* fix: respect system language preferences on Win/macOS (#23247) This commit fixes #18829 Previously the full preferences set to OS was not given to Chromium. Also, this commit improves fallback font selection for CJK text. Chromium uses browser languages to determine fallback fonts on Windows, especially kanji/han characters in CJK. For instance, when user sets 'en-US, ja-JP' to Accept-Language, while Chromium chooses Japanese font for kanji text, but Electron chooses Chinese font. This is because only the first language was given to Accept-Language on Electron. This patch is based on #15532 Co-authored-by: Nitish Sakhawalkar <nitsakh@icloud.com> Co-authored-by: Kasumi Hanazuki <kasumi@rollingapple.net> Co-authored-by: Nitish Sakhawalkar <nitsakh@icloud.com> Co-authored-by: Kasumi Hanazuki <kasumi@rollingapple.net> * fix: remove unintentionally-committed code Some excess code was accidentally included in the last commit's cherry-pick. * chore: fix extraneous #include found by lint * fix: correct another manual backport error :P Co-authored-by: Sorah Fukumori <her@sorah.jp> Co-authored-by: Nitish Sakhawalkar <nitsakh@icloud.com> Co-authored-by: Kasumi Hanazuki <kasumi@rollingapple.net>
This commit fixes #18829 Previously the full preferences set to OS was not given to Chromium. Also, this commit improves fallback font selection for CJK text. Chromium uses browser languages to determine fallback fonts on Windows, especially kanji/han characters in CJK. For instance, when user sets 'en-US, ja-JP' to Accept-Language, while Chromium chooses Japanese font for kanji text, but Electron chooses Chinese font. This is because only the first language was given to Accept-Language on Electron. This patch is based on #15532 Co-authored-by: Nitish Sakhawalkar <nitsakh@icloud.com> Co-authored-by: Kasumi Hanazuki <kasumi@rollingapple.net> Co-authored-by: Nitish Sakhawalkar <nitsakh@icloud.com> Co-authored-by: Kasumi Hanazuki <kasumi@rollingapple.net>
* fix: respect system language preferences on Win/macOS (#23247) This commit fixes #18829 Previously the full preferences set to OS was not given to Chromium. Also, this commit improves fallback font selection for CJK text. Chromium uses browser languages to determine fallback fonts on Windows, especially kanji/han characters in CJK. For instance, when user sets 'en-US, ja-JP' to Accept-Language, while Chromium chooses Japanese font for kanji text, but Electron chooses Chinese font. This is because only the first language was given to Accept-Language on Electron. This patch is based on #15532 Co-authored-by: Nitish Sakhawalkar <nitsakh@icloud.com> Co-authored-by: Kasumi Hanazuki <kasumi@rollingapple.net> Co-authored-by: Nitish Sakhawalkar <nitsakh@icloud.com> Co-authored-by: Kasumi Hanazuki <kasumi@rollingapple.net> * fix: don't shadow the `w` local variable * fixup! fix: respect system language preferences on Win/macOS (#23247) Co-authored-by: Sorah Fukumori <her@sorah.jp> Co-authored-by: Nitish Sakhawalkar <nitsakh@icloud.com> Co-authored-by: Kasumi Hanazuki <kasumi@rollingapple.net>
Description of Change
This PR aims to fix #18829. Please refer to the issue for more details.
Add implementations to set user's OS language preferences to
Accept-Language
andnavigator.languages
, on Windows and macOS.This also improves the CJK fallback font selection on Windows. Chromium uses
Accept-Language
to determine fallback fonts on Windows, especially kanji/han characters in CJK.Previously the full preferences set to OS was not given to Chromium. For instance, when user sets
en-US, ja-JP
toAccept-Language
, while Chromium chooses Japanese font for kanji text, but Electron chooses Chinese font. This is because only the first language is given toAccept-Language
on Electron.This patch is based on the idea given at #15532 /cc @nitsakh
Considerations
fix or feat?
❓ No sure this a feat or a fix. Might be a fix, and backports would be appreciated as I'm thinking this is a bug for CJK speakers.
WinRT API
In this implementation,GetThreadPreferedUILanguages
API is used on Windows. But, I noticed this API doesn't provide the full list of user preferences.Only the system locale (i.e. used for logon screen) and the user locale (i.e. UI used while logged in) are returned.
So, how do you think about addingELECTRON_ACCEPT_LANGUAGE
environment variable to give the preferences correctly, in addition to this change?✅ Resolved using WinRT utility in Chromium #23247 (comment)
Checklist
npm test
passesRelease Notes
notes: Fixed an issue with
navigator.languages
andAccept-Language
did not fully respect users' language preferences on Windows and macOS. This also improved fallback font selection for CJK texts on Windows.