forked from electron/electron
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: respect language preferences on Win/macOS
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>
- Loading branch information
Showing
7 changed files
with
62 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (c) 2020 GitHub, Inc. | ||
// Use of this source code is governed by the MIT license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "shell/browser/api/electron_api_web_contents.h" | ||
|
||
#include "chrome/browser/browser_process.h" | ||
#include "content/public/common/renderer_preferences.h" | ||
|
||
namespace electron { | ||
|
||
namespace api { | ||
|
||
void WebContents::SetAcceptLanguages(blink::mojom::RendererPreferences* prefs) { | ||
prefs->accept_languages = g_browser_process->GetApplicationLocale(); | ||
} | ||
|
||
} // namespace api | ||
|
||
} // namespace electron |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) 2020 GitHub, Inc. | ||
// Use of this source code is governed by the MIT license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "shell/browser/api/electron_api_web_contents.h" | ||
|
||
#include "base/strings/sys_string_conversions.h" | ||
#include "base/win/i18n.h" | ||
#include "third_party/blink/public/mojom/renderer_preferences.mojom.h" | ||
|
||
namespace electron { | ||
|
||
namespace api { | ||
|
||
void WebContents::SetAcceptLanguages(blink::mojom::RendererPreferences* prefs) { | ||
std::vector<base::string16> languages; | ||
base::win::i18n::GetThreadPreferredUILanguageList(&languages); | ||
std::string accept_langs; | ||
for (const auto& s16 : languages) { | ||
accept_langs += base::SysWideToUTF8(s16) + ','; | ||
} | ||
accept_langs.pop_back(); | ||
prefs->accept_languages = accept_langs; | ||
} | ||
|
||
} // namespace api | ||
|
||
} // namespace electron |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters