Bug 1469688 - Part 1: Generalize language switching code in prefs r=jaws,zbraniecki
authorMark Striemer <mstriemer@mozilla.com>
Fri, 10 Aug 2018 15:45:39 -0500
changeset 491706 505226ad06ab36d8a66ceabead0ccab9aed2b3e8
parent 491705 dacda8522abacd0880311e95890c8ede79958f5c
child 491707 6edbb5f98d6ee6d3e0ca8af088981c969924b220
push id1815
push userffxbld-merge
push dateMon, 15 Oct 2018 10:40:45 +0000
treeherdermozilla-release@18d4c09e9378 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws, zbraniecki
bugs1469688
milestone63.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 1469688 - Part 1: Generalize language switching code in prefs r=jaws,zbraniecki Differential Revision: https://phabricator.services.mozilla.com/D3136
browser/components/preferences/in-content/main.js
browser/components/preferences/in-content/main.xul
--- a/browser/components/preferences/in-content/main.js
+++ b/browser/components/preferences/in-content/main.js
@@ -229,20 +229,20 @@ if (AppConstants.MOZ_UPDATER) {
     ]);
   }
 }
 
 // A promise that resolves when the list of application handlers is loaded.
 // We store this in a global so tests can await it.
 var promiseLoadHandlersList;
 
-// Load the preferences string bundle for a given locale with fallbacks.
-function getBundleForLocale(locale) {
+// Load the preferences string bundle for other locales with fallbacks.
+function getBundleForLocales(newLocales) {
   let locales = Array.from(new Set([
-    locale,
+    ...newLocales,
     ...Services.locale.getRequestedLocales(),
     Services.locale.lastFallbackLocale,
   ]));
   function generateContexts(resourceIds) {
     return L10nRegistry.generateContexts(locales, resourceIds);
   }
   return new Localization([
     "browser/preferences/preferences.ftl",
@@ -800,49 +800,70 @@ var gMainPane = {
     let menulist = document.getElementById("defaultBrowserLanguage");
     let menupopup = menulist.querySelector("menupopup");
     menupopup.appendChild(fragment);
     menulist.value = Services.locale.getRequestedLocale();
 
     document.getElementById("browserLanguagesBox").hidden = false;
   },
 
-  /* Show the confirmation message bar to allow a restart into the new language. */
-  async onBrowserLanguageChange(event) {
-    let locale = event.target.value;
+  /* Show the confirmation message bar to allow a restart into the new locales. */
+  async showConfirmLanguageChangeMessageBar(locales) {
     let messageBar = document.getElementById("confirmBrowserLanguage");
-    if (locale == Services.locale.getRequestedLocale()) {
-      messageBar.hidden = true;
-      return;
-    }
     // Set the text in the message bar for the new locale.
-    let newBundle = getBundleForLocale(locale);
-    let description = messageBar.querySelector("description");
+    let newBundle = getBundleForLocales(locales);
+    let description = messageBar.querySelector(".message-bar-description");
     description.textContent = await newBundle.formatValue(
       "confirm-browser-language-change-description");
-    let button = messageBar.querySelector("button");
+    let button = messageBar.querySelector(".message-bar-button");
     button.setAttribute(
       "label", await newBundle.formatValue(
         "confirm-browser-language-change-button"));
+    button.setAttribute("locales", locales.join(","));
     messageBar.hidden = false;
   },
 
+  hideConfirmLanguageChangeMessageBar() {
+    let messageBar = document.getElementById("confirmBrowserLanguage");
+    messageBar.hidden = true;
+    messageBar.querySelector(".message-bar-button").removeAttribute("locales");
+  },
+
   /* Confirm the locale change and restart the browser in the new locale. */
   confirmBrowserLanguageChange() {
-    let locale = document.getElementById("defaultBrowserLanguage").value;
-    Services.locale.setRequestedLocales([locale]);
+    let localesString = (event.target.getAttribute("locales") || "").trim();
+    if (!localesString || localesString.length == 0) {
+      return;
+    }
+    let locales = localesString.split(",");
+    Services.locale.setRequestedLocales(locales);
 
     // Restart with the new locale.
     let cancelQuit = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool);
     Services.obs.notifyObservers(cancelQuit, "quit-application-requested", "restart");
     if (!cancelQuit.data) {
       Services.startup.quit(Services.startup.eAttemptQuit | Services.startup.eRestart);
     }
   },
 
+  /* Show or hide the confirm change message bar based on the new locale. */
+  onBrowserLanguageChange(event) {
+    let locale = event.target.value;
+    if (locale == Services.locale.getRequestedLocale()) {
+      this.hideConfirmLanguageChangeMessageBar();
+      return;
+    }
+    let locales = Array.from(new Set([
+      locale,
+      ...Services.locale.getRequestedLocales(),
+      ...Services.locale.getAvailableLocales(),
+    ]).values());
+    this.showConfirmLanguageChangeMessageBar(locales);
+  },
+
   onBrowserRestoreSessionChange(event) {
     const value = event.target.checked;
     const startupPref = Preferences.get("browser.startup.page");
     let newValue;
 
     if (value) {
       // We need to restore the blank homepage setting in our other pref
       if (startupPref.value === this.STARTUP_PREF_BLANK) {
--- a/browser/components/preferences/in-content/main.xul
+++ b/browser/components/preferences/in-content/main.xul
@@ -287,17 +287,17 @@
     <description flex="1" controls="chooseBrowserLanguage" data-l10n-id="choose-browser-language-description"/>
     <menulist id="defaultBrowserLanguage" class="accessory-button" oncommand="gMainPane.onBrowserLanguageChange(event)" flex="1">
       <menupopup/>
     </menulist>
   </vbox>
   <hbox id="confirmBrowserLanguage" class="message-bar" align="center" hidden="true">
     <image class="message-bar-icon"/>
     <hbox class="message-bar-content" align="center" flex="1">
-      <description flex="1"/>
+      <description class="message-bar-description" flex="1"/>
       <button class="message-bar-button" oncommand="gMainPane.confirmBrowserLanguageChange()"/>
     </hbox>
   </hbox>
 
   <hbox id="languagesBox" align="center">
     <description flex="1" control="chooseLanguage" data-l10n-id="choose-language-description"/>
     <!-- Please don't remove the wrapping hbox/vbox/box for these elements. It's used to properly compute the search tooltip position. -->
     <hbox>