Bug 1420332 - Use system locale when system default is selected for browser locale. r=snorp, a=gchang
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Mon, 27 Nov 2017 10:55:25 +0900
changeset 442679 9ebc50b8692dfa0e779024b28396b69dea7ee6a5
parent 442678 9b8d0f0783279786b4e5a59414308f47cbec15b1
child 442680 005f0819a0cdbb88070d7fd1a8fa24e6903354c8
push id8299
push userryanvm@gmail.com
push dateSun, 03 Dec 2017 18:46:48 +0000
treeherdermozilla-beta@43f74013ae08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp, gchang
bugs1420332, 1337078
milestone58.0
Bug 1420332 - Use system locale when system default is selected for browser locale. r=snorp, a=gchang 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);
 
     /**