Skip to content
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: navigator.languages to use OS preferred languages #15532

Closed
wants to merge 1 commit into from
Closed

Conversation

nitsakh
Copy link
Contributor

@nitsakh nitsakh commented Nov 1, 2018

Description of Change

Until recent versions of chrome (i.e. for electron version < 4.x), navigator.language returned the system language, and the first item in navigator.languages array, was also the same system locale.
However, this behaviour has changed, (it also follows the HTML spec). The language preferences are obtained through the preferences list that chrome maintains. The user has to set these language preferences manually, through the settings menu.
For an electron app, there's no way to set these preferences. Besides, being a desktop app, it seems reasonable for the app to follow the users desktop language preferences.
This change makes the needed changes to set the right OS languages. This also fixes app.getLocale which always returned en-US.
Adding a spec for this would be difficult, as the os language preferences need to be changed to see the difference.

Checklist

  • PR description included and stakeholders cc'd
  • npm test passes
  • tests are changed or added
  • relevant documentation is changed or added
  • PR title follows semantic commit guidelines

Release Notes

Notes: Fixed behaviour of navigator.language/s and app.getLocale to use OS locale

@nitsakh nitsakh requested a review from a team November 1, 2018 21:04
atom/browser/api/atom_api_web_contents.cc Outdated Show resolved Hide resolved
atom/browser/atom_browser_main_parts.cc Outdated Show resolved Hide resolved
@nitsakh nitsakh reopened this Feb 14, 2019
@@ -61,6 +61,11 @@
base::mac::SetBaseBundleID(base_bundle_id.c_str());
}

std::string AtomMainDelegate::GetSystemPreferredLanguage() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does this get used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I think it got lost somewhere in the rebase. I'll update.

@swapnil0545
Copy link

We are using the Accept-Language Request headers and then setting the app localization accordingly.
We get the required header property in chrome browser but I don't see this in electrons dev tool. I am using electron "3.0.5".

@zcbenz
Copy link
Member

zcbenz commented Jul 11, 2019

@nitsakh Do you still want to work on this PR?

@zcbenz
Copy link
Member

zcbenz commented Aug 26, 2019

Closing as there has been no work on the PR for a long time, will reopen if anyone wants to continue working on it.

@zcbenz zcbenz closed this Aug 26, 2019
@zcbenz zcbenz deleted the lang branch August 26, 2019 01:06
sorah added a commit to sorah/electron that referenced this pull request Apr 23, 2020
This commit partially fixes electron#18829

Chromium uses navigator.languages (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' to Accept-Language,
while Chromium chooses Japanese font for kanji text, but Electron
chooses Chinese font.  This is because only the first language is given
to Accept-Language on Electron.

This patch is based on electron#15532

Co-authored-by: Nitish Sakhawalkar <nitsakh@icloud.com>
sorah added a commit to sorah/electron that referenced this pull request Apr 23, 2020
This commit partially fixes electron#18829

Chromium uses navigator.languages (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' to Accept-Language,
while Chromium chooses Japanese font for kanji text, but Electron
chooses Chinese font.  This is because only the first language is given
to Accept-Language on Electron.

This patch is based on electron#15532

Co-authored-by: Nitish Sakhawalkar <nitsakh@icloud.com>
sorah added a commit to sorah/electron that referenced this pull request Apr 23, 2020
This commit partially fixes electron#18829

Chromium uses navigator.languages (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' to Accept-Language,
while Chromium chooses Japanese font for kanji text, but Electron
chooses Chinese font.  This is because only the first language is given
to Accept-Language on Electron.

This patch is based on electron#15532

notes: Changed to respect users' OS preferences for Accept-Language, navigator.languages.

Co-authored-by: Nitish Sakhawalkar <nitsakh@icloud.com>
sorah added a commit to sorah/electron that referenced this pull request Apr 23, 2020
This commit partially fixes electron#18829

Chromium uses navigator.languages (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' to Accept-Language,
while Chromium chooses Japanese font for kanji text, but Electron
chooses Chinese font.  This is because only the first language is given
to Accept-Language on Electron.

This patch is based on electron#15532

Co-authored-by: Nitish Sakhawalkar <nitsakh@icloud.com>
sorah added a commit to sorah/electron that referenced this pull request Apr 24, 2020
This commit partially fixes electron#18829

Chromium uses navigator.languages (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' to Accept-Language,
while Chromium chooses Japanese font for kanji text, but Electron
chooses Chinese font.  This is because only the first language is 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 <hanazuki@rollingapple.net>

fix typo in spec
sorah added a commit to sorah/electron that referenced this pull request Apr 24, 2020
This commit partially fixes electron#18829

Chromium uses navigator.languages (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' to Accept-Language,
while Chromium chooses Japanese font for kanji text, but Electron
chooses Chinese font.  This is because only the first language is 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 <hanazuki@rollingapple.net>

fix typo in spec
sorah added a commit to sorah/electron that referenced this pull request Apr 24, 2020
This commit partially fixes electron#18829

Chromium uses navigator.languages (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' to Accept-Language,
while Chromium chooses Japanese font for kanji text, but Electron
chooses Chinese font.  This is because only the first language is 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 <hanazuki@rollingapple.net>
sorah added a commit to sorah/electron that referenced this pull request Apr 24, 2020
This commit partially fixes electron#18829

Chromium uses navigator.languages (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' to Accept-Language,
while Chromium chooses Japanese font for kanji text, but Electron
chooses Chinese font.  This is because only the first language is 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>
sorah added a commit to sorah/electron that referenced this pull request Apr 25, 2020
This commit partially fixes electron#18829

Chromium uses navigator.languages (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' to Accept-Language,
while Chromium chooses Japanese font for kanji text, but Electron
chooses Chinese font.  This is because only the first language is 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>
sorah added a commit to sorah/electron that referenced this pull request Apr 28, 2020
This commit partially fixes electron#18829

Chromium uses navigator.languages (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' to Accept-Language,
while Chromium chooses Japanese font for kanji text, but Electron
chooses Chinese font.  This is because only the first language is 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>
sorah added a commit to sorah/electron that referenced this pull request Apr 28, 2020
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>
sorah added a commit to sorah/electron that referenced this pull request Apr 28, 2020
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>
deepak1556 pushed a commit that referenced this pull request May 4, 2020
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>
ckerr pushed a commit that referenced this pull request May 4, 2020
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>
ckerr pushed a commit that referenced this pull request May 4, 2020
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>
deepak1556 pushed a commit that referenced this pull request May 5, 2020
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>
codebytere pushed a commit that referenced this pull request May 5, 2020
* 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>
ckerr pushed a commit that referenced this pull request May 5, 2020
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>
codebytere pushed a commit that referenced this pull request May 7, 2020
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants