cromite/build/patches/Override-Navigator-Language.patch
2025-11-22 16:25:29 +01:00

86 lines
3.9 KiB
Diff

From: uazo <uazo@users.noreply.github.com>
Date: Fri, 2 Sep 2022 07:44:58 +0000
Subject: Override Navigator Language
Uses the first of the accept-languages as the system language for blink
and fix the selection in the UI for the browser language
Original License: GPL-2.0-or-later - https://spdx.org/licenses/GPL-2.0-or-later.html
License: GPL-3.0-only - https://spdx.org/licenses/GPL-3.0-only.html
---
.../browser/language/AppLocaleUtils.java | 22 ++++++++++++++++++-
.../renderer_host/render_process_host_impl.cc | 6 ++++-
2 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/chrome/browser/language/android/java/src/org/chromium/chrome/browser/language/AppLocaleUtils.java b/chrome/browser/language/android/java/src/org/chromium/chrome/browser/language/AppLocaleUtils.java
--- a/chrome/browser/language/android/java/src/org/chromium/chrome/browser/language/AppLocaleUtils.java
+++ b/chrome/browser/language/android/java/src/org/chromium/chrome/browser/language/AppLocaleUtils.java
@@ -35,6 +35,10 @@ import java.util.Locale;
public class AppLocaleUtils {
private AppLocaleUtils() {}
+ public interface InstallListener {
+ void onComplete(boolean success);
+ }
+
// Value of AppLocale preference when the system language is used.
public static final @Nullable String APP_LOCALE_USE_SYSTEM_LANGUAGE = null;
@@ -106,6 +110,22 @@ public class AppLocaleUtils {
return locales.get(0).toLanguageTag();
}
+ public static void setAppLanguagePref(
+ String languageName, InstallListener listener) {
+ InstallListener wrappedListener = (success) -> {
+ if (success) {
+ if (shouldUseSystemManagedLocale()) {
+ setSystemManagedAppLanguage(languageName);
+ } else {
+ ChromeSharedPreferences.getInstance().writeString(
+ ChromePreferenceKeys.APPLICATION_OVERRIDE_LANGUAGE, languageName);
+ }
+ }
+ listener.onComplete(success);
+ };
+ wrappedListener.onComplete(true);
+ }
+
/**
* Gets the first original system locale from {@link LocaleManager}. This is the language that
* Chrome would use if there was no override set. If there are no possible UI languages en-US is
@@ -189,7 +209,7 @@ public class AppLocaleUtils {
*/
@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.TIRAMISU)
public static boolean shouldUseSystemManagedLocale() {
- return Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU;
+ return false; // Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU;
}
/**
diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc
--- a/content/browser/renderer_host/render_process_host_impl.cc
+++ b/content/browser/renderer_host/render_process_host_impl.cc
@@ -76,6 +76,7 @@
#include "components/input/features.h"
#include "components/input/utils.h"
#include "components/metrics/histogram_controller.h"
+#include "components/language/core/browser/language_prefs.h"
#include "components/metrics/single_sample_metrics.h"
#include "components/services/storage/privileged/mojom/indexed_db_control.mojom.h"
#include "components/services/storage/public/cpp/buckets/bucket_id.h"
@@ -3562,8 +3563,11 @@ void RenderProcessHostImpl::AppendRendererCommandLine(
PropagateBrowserCommandLineToRenderer(browser_command_line, command_line);
// Pass on the browser locale.
- const std::string locale =
+ std::string locale =
GetContentClient()->browser()->GetApplicationLocale();
+ const std::string accept_langs = GetContentClient()->browser()->GetAcceptLangs(browser_context_);
+ if (!accept_langs.empty())
+ locale = language::GetFirstLanguage(accept_langs);
command_line->AppendSwitchASCII(switches::kLang, locale);
// A non-empty RendererCmdPrefix implies that Zygote is disabled.
--