Bug 1420332 - Use system locale when system default is selected for browser locale. r=snorp
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Mon, 27 Nov 2017 10:55:25 +0900
changeset 394173 5840e049e5aa57d96afd51254882f86da990d3c0
parent 394172 b84de8dee9f6a65a263f79b7af6a318cc78afe32
child 394174 9a4a5661cd9460bffeba2c391dd9168086fb9818
push id32994
push userbtara@mozilla.com
push dateWed, 29 Nov 2017 22:37:27 +0000
treeherdermozilla-central@60db335c1726 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1420332, 1337078
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1420332 - Use system locale when system default is selected for browser locale. r=snorp This is a regression by bug 1337078. When user selects system default for Browser language, "locale" pref is empty. So BrowserLocaleManager.getLocale always returns null. So, current locale is always en-US in Gecko code. So we should return system locale when "locale" pref is empty. Also, ReadSystemLocales expects language tag string for locale. Since Locale.toString doesn't return language tag, so we should convert to it. MozReview-Commit-ID: 3NhAkuA4HaH
mobile/android/base/java/org/mozilla/gecko/BrowserLocaleManager.java
mobile/android/base/java/org/mozilla/gecko/LocaleManager.java
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserLocaleManager.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserLocaleManager.java
@@ -350,16 +350,21 @@ public class BrowserLocaleManager implem
 
         final String current = getPersistedLocale(context);
         if (current == null) {
             return null;
         }
         return currentLocale = Locales.parseLocaleCode(current);
     }
 
+    @Override
+    public Locale getDefaultSystemLocale() {
+        return systemLocale;
+    }
+
     /**
      * Updates the Java locale and the Android configuration.
      *
      * Returns the persisted locale if it differed.
      *
      * Does not notify Gecko.
      *
      * @param localeCode a locale string in Java format: "en_US".
@@ -390,17 +395,18 @@ public class BrowserLocaleManager implem
         currentLocale = locale;
 
         // Update resources.
         updateConfiguration(context, locale);
 
         return locale.toString();
     }
 
-    private boolean isMirroringSystemLocale(final Context context) {
+    @Override
+    public boolean isMirroringSystemLocale(Context context) {
         return getPersistedLocale(context) == null;
     }
 
     /**
      * Examines <code>multilocale.json</code>, returning the included list of
      * locale codes.
      *
      * If <code>multilocale.json</code> is not present, returns
@@ -461,15 +467,23 @@ public class BrowserLocaleManager implem
 
     @WrapForJNI
     public static native void refreshLocales();
 
 
     @WrapForJNI
     private static String getLocale() {
         try {
-            return Locales.getLocaleManager().getCurrentLocale(GeckoAppShell.getApplicationContext()).toString();
+            LocaleManager localeManager = Locales.getLocaleManager();
+            Context context = GeckoAppShell.getApplicationContext();
+            if (!localeManager.isMirroringSystemLocale(context)) {
+                // User uses specific browser locale instead of system locale
+                return Locales.getLanguageTag(localeManager.getCurrentLocale(context));
+            }
+            // Since user selects system default for browser locale, we should return system locale
+            Locale locale = localeManager.getDefaultSystemLocale();
+            return Locales.getLanguageTag(locale);
         } catch (NullPointerException e) {
             Log.i(LOG_TAG, "Couldn't get current locale.");
             return null;
         }
     }
 }
--- a/mobile/android/base/java/org/mozilla/gecko/LocaleManager.java
+++ b/mobile/android/base/java/org/mozilla/gecko/LocaleManager.java
@@ -15,16 +15,18 @@ import android.content.res.Resources;
  *
  * The LocaleManager is responsible for persisting and applying selected locales,
  * and correcting configurations after Android has changed them.
  */
 public interface LocaleManager {
     void initialize(Context context);
 
     Locale getCurrentLocale(Context context);
+    Locale getDefaultSystemLocale();
+    boolean isMirroringSystemLocale(Context context);
     String getAndApplyPersistedLocale(Context context);
     void correctLocale(Context context, Resources resources, Configuration newConfig);
     void updateConfiguration(Context context, Locale locale);
     String setSelectedLocale(Context context, String localeCode);
     boolean systemLocaleDidChange();
     void resetToSystemLocale(Context context);
 
     /**