Bug 1491676 - Moves master password dialog strings r=flod,Gijs,zbraniecki
authorJack Smith <jack@jackdeansmith.com>
Wed, 14 Nov 2018 23:08:51 +0000
changeset 502879 dc9fd82a26a5be15257b468de5ed0378dd800aef
parent 502878 2f24864bdfcdffa68662b4d06bc1a762ecf7754a
child 502880 b7b03bffac5e1dd32b3fbe71c5fa3c64d534f2e1
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflod, Gijs, zbraniecki
bugs1491676
milestone65.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 1491676 - Moves master password dialog strings r=flod,Gijs,zbraniecki Depends on D8552 Differential Revision: https://phabricator.services.mozilla.com/D8553
python/l10n/fluent_migrations/bug_1491676_preferences_properties.py
toolkit/locales/en-US/chrome/mozapps/preferences/preferences.properties
toolkit/locales/en-US/toolkit/preferences/preferences.ftl
toolkit/locales/jar.mn
toolkit/mozapps/preferences/changemp.js
toolkit/mozapps/preferences/changemp.xul
toolkit/mozapps/preferences/removemp.js
toolkit/mozapps/preferences/removemp.xul
new file mode 100644
--- /dev/null
+++ b/python/l10n/fluent_migrations/bug_1491676_preferences_properties.py
@@ -0,0 +1,34 @@
+# coding=utf8
+
+# Any copyright is dedicated to the Public Domain.
+# http://creativecommons.org/publicdomain/zero/1.0/
+
+from __future__ import absolute_import
+import fluent.syntax.ast as FTL
+from fluent.migrate.helpers import transforms_from
+from fluent.migrate.helpers import VARIABLE_REFERENCE, TERM_REFERENCE
+from fluent.migrate import REPLACE, COPY
+
+
+def migrate(ctx):
+    """Bug 1486937 - Move strings from preferences.properties to Fluent"""
+
+    ctx.add_transforms(
+        "toolkit/toolkit/preferences/preferences.ftl",
+        "toolkit/toolkit/preferences/preferences.ftl",
+        transforms_from(
+"""
+password-not-set =
+        .value = { COPY(from_path, "password_not_set") }
+failed-pw-change = { COPY(from_path, "failed_pw_change") }
+incorrect-pw = { COPY(from_path, "incorrect_pw") }
+pw-empty-warning = { COPY(from_path, "pw_empty_warning") }
+pw-change-ok = { COPY(from_path, "pw_change_ok") } { -pw-empty-warning }
+pw-erased-ok = { COPY(from_path, "pw_erased_ok") } { -pw-empty-warning }
+pw-not-wanted = { COPY(from_path, "pw_not_wanted") }
+pw-change2empty-in-fips-mode = { COPY(from_path, "pw_change2empty_in_fips_mode") }
+pw-change-success-title = { COPY(from_path, "pw_change_success_title") }
+pw-change-failed-title = { COPY(from_path, "pw_change_failed_title") }
+pw-remove-button =
+    .label = { COPY(from_path, "pw_remove_button") }
+""", from_path="toolkit/chrome/mozapps/preferences/preferences.properties"))
deleted file mode 100644
--- a/toolkit/locales/en-US/chrome/mozapps/preferences/preferences.properties
+++ /dev/null
@@ -1,17 +0,0 @@
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-#### Master Password
-
-password_not_set=(not set)
-failed_pw_change=Unable to change Master Password.
-incorrect_pw=You did not enter the correct current Master Password. Please try again.
-pw_change_ok=Master Password successfully changed.
-pw_erased_ok=You have deleted your Master Password. 
-pw_not_wanted=Warning! You have decided not to use a Master Password.
-pw_empty_warning=Your stored web and email passwords, form data, and private keys will not be protected.
-pw_change2empty_in_fips_mode=You are currently in FIPS mode. FIPS requires a non-empty Master Password.
-pw_change_success_title=Password Change Succeeded
-pw_change_failed_title=Password Change Failed
-pw_remove_button=Remove
new file mode 100644
--- /dev/null
+++ b/toolkit/locales/en-US/toolkit/preferences/preferences.ftl
@@ -0,0 +1,20 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+password-not-set =
+    .value = (not set)
+
+failed-pw-change = Unable to change Master Password.
+incorrect-pw = You did not enter the correct current Master Password. Please try again.
+pw-change-ok = Master Password successfully changed.
+
+pw-empty-warning = Your stored web and email passwords, form data, and private keys will not be protected.
+pw-erased-ok = You have deleted your Master Password. { pw-empty-warning }
+pw-not-wanted = Warning! You have decided not to use a Master Password. { pw-empty-warning }
+
+pw-change2empty-in-fips-mode = You are currently in FIPS mode. FIPS requires a non-empty Master Password.
+pw-change-success-title = Password Change Succeeded
+pw-change-failed-title = Password Change Failed
+pw-remove-button =
+    .label = Remove
--- a/toolkit/locales/jar.mn
+++ b/toolkit/locales/jar.mn
@@ -84,17 +84,16 @@
 #ifndef MOZ_FENNEC
   locale/@AB_CD@/mozapps/extensions/extensions.properties         (%chrome/mozapps/extensions/extensions.properties)
   locale/@AB_CD@/mozapps/extensions/blocklist.dtd                 (%chrome/mozapps/extensions/blocklist.dtd)
 #endif
   locale/@AB_CD@/mozapps/handling/handling.dtd                    (%chrome/mozapps/handling/handling.dtd)
   locale/@AB_CD@/mozapps/handling/handling.properties             (%chrome/mozapps/handling/handling.properties)
   locale/@AB_CD@/mozapps/preferences/changemp.dtd                 (%chrome/mozapps/preferences/changemp.dtd)
   locale/@AB_CD@/mozapps/preferences/removemp.dtd                 (%chrome/mozapps/preferences/removemp.dtd)
-  locale/@AB_CD@/mozapps/preferences/preferences.properties       (%chrome/mozapps/preferences/preferences.properties)
   locale/@AB_CD@/mozapps/profile/createProfileWizard.dtd          (%chrome/mozapps/profile/createProfileWizard.dtd)
   locale/@AB_CD@/mozapps/profile/profileSelection.properties      (%chrome/mozapps/profile/profileSelection.properties)
   locale/@AB_CD@/mozapps/profile/profileSelection.dtd             (%chrome/mozapps/profile/profileSelection.dtd)
 #ifndef MOZ_FENNEC
   locale/@AB_CD@/mozapps/update/updates.dtd                       (%chrome/mozapps/update/updates.dtd)
   locale/@AB_CD@/mozapps/update/updates.properties                (%chrome/mozapps/update/updates.properties)
 #endif
 % locale pluginproblem @AB_CD@ %locale/@AB_CD@/pluginproblem/
--- a/toolkit/mozapps/preferences/changemp.js
+++ b/toolkit/mozapps/preferences/changemp.js
@@ -21,30 +21,28 @@ var pw1;
 function init() {
   pw1 = document.getElementById("pw1");
 
   process();
 }
 
 
 function process() {
-  let bundle = document.getElementById("bundlePreferences");
-
   // If the token is unitialized, don't use the old password box.
   // Otherwise, do.
 
   let tokenDB = Cc["@mozilla.org/security/pk11tokendb;1"]
                   .getService(Ci.nsIPK11TokenDB);
   let token = tokenDB.getInternalKeyToken();
   if (token) {
     let oldpwbox = document.getElementById("oldpw");
     let msgBox = document.getElementById("message");
     if ((token.needsLogin() && token.needsUserInit) || !token.needsLogin()) {
       oldpwbox.setAttribute("hidden", "true");
-      msgBox.setAttribute("value", bundle.getString("password_not_set"));
+      document.l10n.setAttributes(msgBox, "password-not-set");
       msgBox.setAttribute("hidden", "false");
 
       if (!token.needsLogin()) {
         oldpwbox.setAttribute("inited", "empty");
       } else {
         oldpwbox.setAttribute("inited", "true");
       }
 
@@ -62,23 +60,30 @@ function process() {
   if (params) {
     // Return value 0 means "canceled"
     params.SetInt(1, 0);
   }
 
   checkPasswords();
 }
 
+async function createAlert(titleL10nId, messageL10nId) {
+  const [title, message] = await document.l10n.formatValues([
+    {id: titleL10nId},
+    {id: messageL10nId},
+  ]);
+  Services.prompt.alert(window, title, message);
+}
+
 function setPassword() {
   var pk11db = Cc[nsPK11TokenDB].getService(nsIPK11TokenDB);
   var token = pk11db.getInternalKeyToken();
 
   var oldpwbox = document.getElementById("oldpw");
   var initpw = oldpwbox.getAttribute("inited");
-  var bundle = document.getElementById("bundlePreferences");
 
   var success = false;
 
   if (initpw == "false" || initpw == "empty") {
     try {
       var oldpw = "";
       var passok = 0;
 
@@ -93,63 +98,51 @@ function setPassword() {
         if (initpw == "empty" && pw1.value == "") {
           // This makes no sense that we arrive here,
           // we reached a case that should have been prevented by checkPasswords.
         } else {
           if (pw1.value == "") {
             var secmoddb = Cc[nsPKCS11ModuleDB].getService(nsIPKCS11ModuleDB);
             if (secmoddb.isFIPSEnabled) {
               // empty passwords are not allowed in FIPS mode
-              Services.prompt.alert(window,
-                                    bundle.getString("pw_change_failed_title"),
-                                    bundle.getString("pw_change2empty_in_fips_mode"));
+              createAlert("pw-change-failed-title", "pw-change2empty-in-fips-mode");
               passok = 0;
             }
           }
           if (passok) {
             token.changePassword(oldpw, pw1.value);
             if (pw1.value == "") {
-              Services.prompt.alert(window,
-                                    bundle.getString("pw_change_success_title"),
-                                    bundle.getString("pw_erased_ok")
-                                    + " " + bundle.getString("pw_empty_warning"));
+              createAlert("pw-change-success-title", "pw-erased-ok");
             } else {
-              Services.prompt.alert(window,
-                                    bundle.getString("pw_change_success_title"),
-                                    bundle.getString("pw_change_ok"));
+              createAlert("pw-change-success-title", "pw-change-ok");
             }
             success = true;
           }
         }
       } else {
         oldpwbox.focus();
         oldpwbox.setAttribute("value", "");
-        Services.prompt.alert(window,
-                              bundle.getString("pw_change_failed_title"),
-                              bundle.getString("incorrect_pw"));
+        createAlert("pw-change-failed-title", "incorrect-pw");
       }
     } catch (e) {
-      Services.prompt.alert(window,
-                            bundle.getString("pw_change_failed_title"),
-                            bundle.getString("failed_pw_change"));
+      createAlert("pw-change-failed-title", "failed-pw-change");
     }
   } else {
     token.initPassword(pw1.value);
     if (pw1.value == "") {
-      Services.prompt.alert(window,
-                            bundle.getString("pw_change_success_title"),
-                            bundle.getString("pw_not_wanted")
-                            + " " + bundle.getString("pw_empty_warning"));
+      createAlert("pw-change-success-title", "pw-not-wanted");
     }
     success = true;
   }
 
   // Terminate dialog
   if (success)
     window.close();
+
+  return success;
 }
 
 function setPasswordStrength() {
 // Here is how we weigh the quality of the password
 // number of characters
 // numbers
 // non-alpha-numeric chars
 // upper and lower case characters
--- a/toolkit/mozapps/preferences/changemp.xul
+++ b/toolkit/mozapps/preferences/changemp.xul
@@ -17,17 +17,19 @@
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml"
         style="width: 40em;" 
         ondialogaccept="setPassword();"
         onload="init()">
 
   <script type="application/javascript" src="chrome://mozapps/content/preferences/changemp.js"/>
 
-  <stringbundle id="bundlePreferences" src="chrome://mozapps/locale/preferences/preferences.properties"/>
+  <linkset>
+    <link rel="localization" href="toolkit/preferences/preferences.ftl"/>
+  </linkset>
 
   <description control="pw1">&masterPasswordDescription.label;</description>
 
   <grid>
     <columns>
       <column flex="1"/>
       <column/>
     </columns>
--- a/toolkit/mozapps/preferences/removemp.js
+++ b/toolkit/mozapps/preferences/removemp.js
@@ -3,48 +3,48 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 var gRemovePasswordDialog = {
   _token: null,
-  _bundle: null,
   _okButton: null,
   _password: null,
   init() {
-    this._bundle = document.getElementById("bundlePreferences");
-
     this._okButton = document.documentElement.getButton("accept");
-    this._okButton.label = this._bundle.getString("pw_remove_button");
+    document.l10n.setAttributes(this._okButton, "pw-remove-button");
 
     this._password = document.getElementById("password");
 
     var pk11db = Cc["@mozilla.org/security/pk11tokendb;1"]
                    .getService(Ci.nsIPK11TokenDB);
     this._token = pk11db.getInternalKeyToken();
 
     // Initialize the enabled state of the Remove button by checking the
     // initial value of the password ("" should be incorrect).
     this.validateInput();
   },
 
   validateInput() {
     this._okButton.disabled = !this._token.checkPassword(this._password.value);
   },
 
+  async createAlert(titleL10nId, messageL10nId) {
+    const [title, message] = await document.l10n.formatValues([
+      {id: titleL10nId},
+      {id: messageL10nId},
+    ]);
+    Services.prompt.alert(window, title, message);
+  },
+
   removePassword() {
     if (this._token.checkPassword(this._password.value)) {
       this._token.changePassword(this._password.value, "");
-      Services.prompt.alert(window,
-                            this._bundle.getString("pw_change_success_title"),
-                            this._bundle.getString("pw_erased_ok")
-                            + " " + this._bundle.getString("pw_empty_warning"));
+      this.createAlert("pw-change-success-title", "pw-erased-ok");
     } else {
       this._password.value = "";
       this._password.focus();
-      Services.prompt.alert(window,
-                            this._bundle.getString("pw_change_failed_title"),
-                            this._bundle.getString("incorrect_pw"));
+      this.createAlert("pw-change-failed-title", "incorrect-pw");
     }
   },
 };
--- a/toolkit/mozapps/preferences/removemp.xul
+++ b/toolkit/mozapps/preferences/removemp.xul
@@ -16,17 +16,19 @@
 <dialog id="removemp" title="&removePassword.title;"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 
         style="width: 35em;" 
         ondialogaccept="gRemovePasswordDialog.removePassword();" 
         onload="gRemovePasswordDialog.init()">
 
   <script type="application/javascript" src="chrome://mozapps/content/preferences/removemp.js"/>
 
-  <stringbundle id="bundlePreferences" src="chrome://mozapps/locale/preferences/preferences.properties"/>
+  <linkset>
+    <link rel="localization" href="toolkit/preferences/preferences.ftl"/>
+  </linkset>
 
   <vbox id="warnings">
     <description>&removeWarning1.label;</description>
     <description class="header">&removeWarning2.label;</description>
   </vbox>
   
   <separator class="thin"/>