Bug 1509628 - Port bug 1479013: Include both languages in the browser language switch confirmation. r=jorgk
authorRichard Marti <richard.marti@gmail.com>
Sat, 24 Nov 2018 12:26:52 +0100
changeset 33781 5b12fb711cd812184f33936024eb487eb6910d96
parent 33780 269065e13f69fe4c65896418a7ee91ea7d20648f
child 33782 eb66bb3b1b7600ad93ea6664c13964fc7d9bba50
push id388
push userclokep@gmail.com
push dateMon, 28 Jan 2019 20:54:56 +0000
reviewersjorgk
bugs1509628, 1479013
Bug 1509628 - Port bug 1479013: Include both languages in the browser language switch confirmation. r=jorgk
mail/components/preferences/advanced.inc.xul
mail/components/preferences/advanced.js
--- a/mail/components/preferences/advanced.inc.xul
+++ b/mail/components/preferences/advanced.inc.xul
@@ -197,21 +197,17 @@
                         oncommand="gAdvancedPane.showMessengerLanguages()"/>
               </hbox>
             </vbox>
             <hbox id="confirmMessengerLanguage"
                   class="message-bar"
                   align="center"
                   hidden="true">
               <image class="message-bar-icon"/>
-              <hbox class="message-bar-content" align="center" flex="1">
-                <description class="message-bar-description" flex="1"/>
-                <button class="message-bar-button"
-                        oncommand="gAdvancedPane.confirmLanguageChange(event)"/>
-              </hbox>
+              <vbox class="message-bar-content-container" align="stretch" flex="1"/>
             </hbox>
           </groupbox>
 
 #ifdef HAVE_SHELL_SERVICE
           <groupbox id="systemDefaultsGroup" orient="vertical">
             <caption>&systemIntegration.label;</caption>
             <hbox id="checkDefaultBox" align="center">
               <checkbox id="alwaysCheckDefault"
--- a/mail/components/preferences/advanced.js
+++ b/mail/components/preferences/advanced.js
@@ -588,26 +588,57 @@ var gAdvancedPane = {
     }
     defaultMessengerLanguage.value = Services.locale.requestedLocale;
     gAdvancedPane.hideConfirmLanguageChangeMessageBar();
   },
 
   /* Show the confirmation message bar to allow a restart into the new locales. */
   async showConfirmLanguageChangeMessageBar(locales) {
     let messageBar = document.getElementById("confirmMessengerLanguage");
-    // Set the text in the message bar for the new locale.
+
+    // Get the bundle for the new locale.
     let newBundle = this.getBundleForLocales(locales);
-    let description = messageBar.querySelector(".message-bar-description");
-    description.textContent = await newBundle.formatValue(
-      "confirm-messenger-language-change-description");
-    let button = messageBar.querySelector(".message-bar-button");
-    button.setAttribute(
-      "label", await newBundle.formatValue(
-        "confirm-messenger-language-change-button"));
-    button.setAttribute("locales", locales.join(","));
+
+    // Find the messages and labels.
+    let messages = await Promise.all([newBundle, document.l10n].map(
+      async (bundle) => bundle.formatValue("confirm-messenger-language-change-description")));
+    let buttonLabels = await Promise.all([newBundle, document.l10n].map(
+      async (bundle) => bundle.formatValue("confirm-messenger-language-change-button")));
+
+    // If both the message and label are the same, just include one row.
+    if (messages[0] == messages[1] && buttonLabels[0] == buttonLabels[1]) {
+      messages.pop();
+      buttonLabels.pop();
+    }
+
+    let contentContainer = messageBar.querySelector(".message-bar-content-container");
+    contentContainer.textContent = "";
+
+    for (let i = 0; i < messages.length; i++) {
+      let messageContainer = document.createXULElement("hbox");
+      messageContainer.classList.add("message-bar-content");
+      messageContainer.setAttribute("flex", "1");
+      messageContainer.setAttribute("align", "center");
+
+      let description = document.createXULElement("description");
+      description.classList.add("message-bar-description");
+      description.setAttribute("flex", "1");
+      description.textContent = messages[i];
+      messageContainer.appendChild(description);
+
+      let button = document.createXULElement("button");
+      button.addEventListener("command", gAdvancedPane.confirmLanguageChange);
+      button.classList.add("message-bar-button");
+      button.setAttribute("locales", locales.join(","));
+      button.setAttribute("label", buttonLabels[i]);
+      messageContainer.appendChild(button);
+
+      contentContainer.appendChild(messageContainer);
+    }
+
     messageBar.hidden = false;
     this.requestingLocales = locales;
   },
 
   hideConfirmLanguageChangeMessageBar() {
     let messageBar = document.getElementById("confirmMessengerLanguage");
     messageBar.hidden = true;
     messageBar.querySelector(".message-bar-button").removeAttribute("locales");