From f31d98a27269a255d37f5e783b3f3d11c68e83c6 Mon Sep 17 00:00:00 2001 From: Richard Newman Date: Fri, 8 Sep 2017 07:54:13 -0700 Subject: [PATCH] Bug 1378501 - Tell Gecko when the OS locale changes, even when backgrounded. r=mcomella This ensures that `intl.locale.os` is always set, even if the system locale changes while Fennec is in the background. This commit also restores `Strings.flush()` calls that are necessary to have Fennec's non-Java UI reflect locale changes. With this commit, the geolocation popup still doesn't behave correctly: when the locale system is set to match OS locale, although the pref is set the locale doesn't change. This applies in two scenarios: on first run (the popup is always English) and when the locale changes at runtime (the popup uses an earlier OS locale). Bug 1397925 should complete the fix. MozReview-Commit-ID: 8zeZuYXFYdy --HG-- extra : rebase_source : 9da9aae7ed8420faa7567c9db29b1110b3289d9f --- .../java/org/mozilla/gecko/BrowserLocaleManager.java | 10 ++++++++++ mobile/android/chrome/content/browser.js | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/mobile/android/base/java/org/mozilla/gecko/BrowserLocaleManager.java b/mobile/android/base/java/org/mozilla/gecko/BrowserLocaleManager.java index ba1f328483b3..1d24251d277c 100644 --- a/mobile/android/base/java/org/mozilla/gecko/BrowserLocaleManager.java +++ b/mobile/android/base/java/org/mozilla/gecko/BrowserLocaleManager.java @@ -106,6 +106,10 @@ public class BrowserLocaleManager implements LocaleManager { systemLocaleDidChange = true; Log.d(LOG_TAG, "System locale changed from " + current + " to " + systemLocale); + + // If the OS locale changed, we need to tell Gecko. + final SharedPreferences prefs = GeckoSharedPrefs.forProfile(context); + BrowserLocaleManager.storeAndNotifyOSLocale(prefs, systemLocale); } }; context.registerReceiver(receiver, new IntentFilter(Intent.ACTION_LOCALE_CHANGED)); @@ -208,6 +212,7 @@ public class BrowserLocaleManager implements LocaleManager { final String osLocaleString = osLocale.toString(); if (osLocaleString.equals(lastOSLocale)) { + Log.d(LOG_TAG, "Previous locale " + lastOSLocale + " same as new. Doing nothing."); return; } @@ -218,6 +223,7 @@ public class BrowserLocaleManager implements LocaleManager { // a Java locale string. final GeckoBundle data = new GeckoBundle(1); data.putString("languageTag", Locales.getLanguageTag(osLocale)); + EventDispatcher.getInstance().dispatch("Locale:OS", data); } @@ -304,6 +310,10 @@ public class BrowserLocaleManager implements LocaleManager { } private SharedPreferences getSharedPreferences(Context context) { + // We should be using per-profile prefs here, because we're tracking against + // a Gecko pref. The same applies to the locale switcher! + // Bug 940575, Bug 873166 are relevant, and see Bug 1378501 for the commit + // that added this comment. return GeckoSharedPrefs.forApp(context); } diff --git a/mobile/android/chrome/content/browser.js b/mobile/android/chrome/content/browser.js index d1d6906e2a07..c93df2141b5b 100644 --- a/mobile/android/chrome/content/browser.js +++ b/mobile/android/chrome/content/browser.js @@ -1742,6 +1742,9 @@ var BrowserApp = { let appLocale = this.getUALocalePref(); this.computeAcceptLanguages(languageTag, appLocale); + + // Rebuild strings, in case we're mirroring OS locale. + Strings.flush(); break; } @@ -1752,6 +1755,11 @@ var BrowserApp = { Services.locale.setRequestedLocales([]); } + console.log("Gecko display locale: " + this.getUALocalePref()); + + // Rebuild strings to reflect the new locale. + Strings.flush(); + // Make sure we use the right Accept-Language header. let osLocale; try {