[tor-commits] [tor-browser] 38/90: Bug 40199: Avoid using system locale for intl.accept_languages in GeckoView

gitolite role git at cupani.torproject.org
Tue Nov 22 09:58:13 UTC 2022


This is an automated email from the git hooks/post-receive script.

richard pushed a commit to branch tor-browser-102.5.0esr-12.0-1
in repository tor-browser.

commit 1fe9568f55fbd20f2442b5d4827ded29ec7f2672
Author: Alex Catarineu <acat at torproject.org>
AuthorDate: Tue Oct 20 17:44:36 2020 +0200

    Bug 40199: Avoid using system locale for intl.accept_languages in GeckoView
---
 .../mozilla/geckoview/GeckoRuntimeSettings.java    | 28 +++++++++++++---------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntimeSettings.java b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntimeSettings.java
index ff7b6dfee54e..1a3da74d143b 100644
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntimeSettings.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntimeSettings.java
@@ -792,19 +792,25 @@ public final class GeckoRuntimeSettings extends RuntimeSettings {
   private String computeAcceptLanguages() {
     final ArrayList<String> locales = new ArrayList<String>();
 
-    // Explicitly-set app prefs come first:
-    if (mRequestedLocales != null) {
-      for (final String locale : mRequestedLocales) {
-        locales.add(locale.toLowerCase(Locale.ROOT));
-      }
-    }
-    // OS prefs come second:
-    for (final String locale : getDefaultLocales()) {
-      final String localeLowerCase = locale.toLowerCase(Locale.ROOT);
-      if (!locales.contains(localeLowerCase)) {
-        locales.add(localeLowerCase);
+    // In Desktop, these are defined in the `intl.accept_languages` localized property.
+    // At some point we should probably use the same values here, but for now we use a simple
+    // strategy which will hopefully result in reasonable acceptLanguage values.
+    if (mRequestedLocales != null && mRequestedLocales.length > 0) {
+      String locale = mRequestedLocales[0].toLowerCase(Locale.ROOT);
+      // No need to include `en-us` twice.
+      if (!locale.equals("en-us")) {
+        locales.add(locale);
+        if (locale.contains("-")) {
+          String lang = locale.split("-")[0];
+          // No need to include `en` twice.
+          if (!lang.equals("en")) {
+            locales.add(lang);
+          }
+        }
       }
     }
+    locales.add("en-us");
+    locales.add("en");
 
     return TextUtils.join(",", locales);
   }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the tor-commits mailing list