Bug 1491676 - Moves out of space warning strings r=flod,Gijs,zbraniecki
☠☠ backed out by 0137b019c6fa ☠ ☠
authorJack Smith <jack@jackdeansmith.com>
Wed, 07 Nov 2018 18:05:13 +0000
changeset 444904 aeb045b903218c6cc1a9c55e1ccd916c40fb8a00
parent 444903 e75c59f129eae228fd19157d706351b9e05f91bc
child 444905 fae949de1ed559e482904b797f09f2640dd81f88
push id72542
push usergijskruitbosch@gmail.com
push dateWed, 07 Nov 2018 18:09:54 +0000
treeherderautoland@08cbaa2f9183 [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 out of space warning strings r=flod,Gijs,zbraniecki Depends on D8553 Differential Revision: https://phabricator.services.mozilla.com/D8554
browser/base/content/browser-sets.inc
browser/base/content/browser.js
browser/locales/en-US/browser/preferences/preferences.ftl
browser/locales/en-US/chrome/browser/preferences/preferences.properties
python/l10n/fluent_migrations/bug_1491676_preferences_properties.py
toolkit/content/widgets/notification.xml
--- a/browser/base/content/browser-sets.inc
+++ b/browser/base/content/browser-sets.inc
@@ -9,17 +9,16 @@
 #endif
 #endif
 
   <stringbundleset id="stringbundleset"
                    string-bookmarkthispage="&bookmarkThisPageCmd.label;"
                    string-editthisbookmark="&editThisBookmarkCmd.label;">
     <stringbundle id="bundle_brand" src="chrome://branding/locale/brand.properties"/>
     <stringbundle id="bundle_shell" src="chrome://browser/locale/shellservice.properties"/>
-    <stringbundle id="bundle_preferences" src="chrome://browser/locale/preferences/preferences.properties"/>
   </stringbundleset>
 
   <commandset id="mainCommandSet">
     <command id="cmd_newNavigator" oncommand="OpenBrowserWindow()"/>
     <command id="cmd_handleBackspace" oncommand="BrowserHandleBackspace();" />
     <command id="cmd_handleShiftBackspace" oncommand="BrowserHandleShiftBackspace();" />
 
     <command id="cmd_newNavigatorTab" oncommand="BrowserOpenTab(event);"/>
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -516,17 +516,17 @@ const gSessionHistoryObserver = {
     // Clear undo history of the URL bar
     gURLBar.editor.transactionManager.clear();
   },
 };
 
 const gStoragePressureObserver = {
   _lastNotificationTime: -1,
 
-  observe(subject, topic, data) {
+  async observe(subject, topic, data) {
     if (topic != "QuotaManager::StoragePressure") {
       return;
     }
 
     const NOTIFICATION_VALUE = "storage-pressure-notification";
     let notificationBox = document.getElementById("high-priority-global-notificationbox");
     if (notificationBox.getNotificationWithValue(NOTIFICATION_VALUE)) {
       // Do not display the 2nd notification when there is already one
@@ -541,69 +541,63 @@ const gStoragePressureObserver = {
     const MIN_NOTIFICATION_INTERVAL_MS =
       Services.prefs.getIntPref("browser.storageManager.pressureNotification.minIntervalMS");
     let duration = Date.now() - this._lastNotificationTime;
     if (duration <= MIN_NOTIFICATION_INTERVAL_MS) {
       return;
     }
     this._lastNotificationTime = Date.now();
 
+    MozXULElement.insertFTLIfNeeded("branding/brand.ftl");
+    MozXULElement.insertFTLIfNeeded("browser/preferences/preferences.ftl");
+
     const BYTES_IN_GIGABYTE = 1073741824;
     const USAGE_THRESHOLD_BYTES = BYTES_IN_GIGABYTE *
       Services.prefs.getIntPref("browser.storageManager.pressureNotification.usageThresholdGB");
     let msg = "";
     let buttons = [];
     let usage = subject.QueryInterface(Ci.nsISupportsPRUint64).data;
-    let prefStrBundle = document.getElementById("bundle_preferences");
-    let brandShortName = document.getElementById("bundle_brand").getString("brandShortName");
     buttons.push({
-      label: prefStrBundle.getString("spaceAlert.learnMoreButton.label"),
-      accessKey: prefStrBundle.getString("spaceAlert.learnMoreButton.accesskey"),
+      "l10n-id": "space-alert-learn-more-button",
       callback(notificationBar, button) {
         let learnMoreURL = Services.urlFormatter.formatURLPref("app.support.baseURL") + "storage-permissions";
         // This is a content URL, loaded from trusted UX.
         openTrustedLinkIn(learnMoreURL, "tab");
       },
     });
     if (usage < USAGE_THRESHOLD_BYTES) {
       // The firefox-used space < 5GB, then warn user to free some disk space.
       // This is because this usage is small and not the main cause for space issue.
       // In order to avoid the bad and wrong impression among users that
       // firefox eats disk space a lot, indicate users to clean up other disk space.
-      msg = prefStrBundle.getFormattedString("spaceAlert.under5GB.message", [brandShortName]);
+      [msg] = await document.l10n.formatValues([{id: "space-alert-under-5gb-message"}]);
       buttons.push({
-        label: prefStrBundle.getString("spaceAlert.under5GB.okButton.label"),
-        accessKey: prefStrBundle.getString("spaceAlert.under5GB.okButton.accesskey"),
+        "l10n-id": "space-alert-under-5gb-ok-button",
         callback() {},
       });
     } else {
       // The firefox-used space >= 5GB, then guide users to about:preferences
       // to clear some data stored on firefox by websites.
-      let descriptionStringID = "spaceAlert.over5GB.message1";
-      let prefButtonLabelStringID = "spaceAlert.over5GB.prefButton.label";
-      let prefButtonAccesskeyStringID = "spaceAlert.over5GB.prefButton.accesskey";
-      if (AppConstants.platform == "win") {
-        descriptionStringID = "spaceAlert.over5GB.messageWin1";
-        prefButtonLabelStringID = "spaceAlert.over5GB.prefButtonWin.label";
-        prefButtonAccesskeyStringID = "spaceAlert.over5GB.prefButtonWin.accesskey";
-      }
-      msg = prefStrBundle.getFormattedString(descriptionStringID, [brandShortName]);
+      [msg] = await document.l10n.formatValues([{id: "space-alert-over-5gb-message"}]);
       buttons.push({
-        label: prefStrBundle.getString(prefButtonLabelStringID),
-        accessKey: prefStrBundle.getString(prefButtonAccesskeyStringID),
+        "l10n-id": "space-alert-over-5gb-pref-button",
         callback(notificationBar, button) {
           // The advanced subpanes are only supported in the old organization, which will
           // be removed by bug 1349689.
           openPreferences("privacy-sitedata", { origin: "storagePressure" });
         },
       });
     }
 
     notificationBox.appendNotification(
       msg, NOTIFICATION_VALUE, null, notificationBox.PRIORITY_WARNING_HIGH, buttons, null);
+
+    // This seems to be necessary to get the buttons to display correctly
+    // See: https://bugzilla.mozilla.org/show_bug.cgi?id=1504216
+    document.l10n.translateFragment(notificationBox);
   },
 };
 
 var gPopupBlockerObserver = {
   handleEvent(aEvent) {
     if (aEvent.originalTarget != gBrowser.selectedBrowser)
       return;
 
--- a/browser/locales/en-US/browser/preferences/preferences.ftl
+++ b/browser/locales/en-US/browser/preferences/preferences.ftl
@@ -1005,12 +1005,40 @@ certs-enable-ocsp =
 certs-view =
     .label = View Certificates…
     .accesskey = C
 
 certs-devices =
     .label = Security Devices…
     .accesskey = D
 
+space-alert-learn-more-button =
+    .label = Learn More
+    .accesskey = L
+
+space-alert-over-5gb-pref-button =
+    .label =
+        { PLATFORM() ->
+            [windows] Open Options
+           *[other] Open Preferences
+        }
+    .accesskey =
+        { PLATFORM() ->
+            [windows] O
+           *[other] O
+        }
+
+space-alert-over-5gb-message =
+    { PLATFORM() ->
+        [windows] { -brand-short-name } is running out of disk space. Website contents may not display properly. You can clear stored data in Options > Privacy & Security > Cookies and Site Data.
+       *[other] { -brand-short-name } is running out of disk space. Website contents may not display properly. You can clear stored data in Preferences > Privacy & Security > Cookies and Site Data.
+    }
+
+space-alert-under-5gb-ok-button =
+    .label = OK, Got it
+    .accesskey = K
+
+space-alert-under-5gb-message = { -brand-short-name } is running out of disk space. Website contents may not display properly. Visit “Learn More” to optimize your disk usage for better browsing experience.
+
 # Variables:
 #   $service-name (String) - Name of a cloud storage provider like Dropbox, Google Drive, etc...
 save-files-to-cloud-storage =
     .label = Save files to { $service-name }
--- a/browser/locales/en-US/chrome/browser/preferences/preferences.properties
+++ b/browser/locales/en-US/chrome/browser/preferences/preferences.properties
@@ -43,26 +43,8 @@ typeDescriptionWithType=%S (%S)
 
 #### Permission labels
 
 can=Allow
 canAccessFirstParty=Allow first party only
 canSession=Allow for Session
 cannot=Block
 prompt=Always Ask
-
-spaceAlert.learnMoreButton.label=Learn More
-spaceAlert.learnMoreButton.accesskey=L
-spaceAlert.over5GB.prefButton.label=Open Preferences
-spaceAlert.over5GB.prefButton.accesskey=O
-# LOCALIZATION NOTE (spaceAlert.over5GB.prefButtonWin.label): On Windows Preferences is called Options
-spaceAlert.over5GB.prefButtonWin.label=Open Options
-spaceAlert.over5GB.prefButtonWin.accesskey=O
-# LOCALIZATION NOTE (spaceAlert.over5GB.message1): %S = brandShortName
-spaceAlert.over5GB.message1=%S is running out of disk space. Website contents may not display properly. You can clear stored data in Preferences > Privacy & Security > Cookies and Site Data.
-# LOCALIZATION NOTE (spaceAlert.over5GB.messageWin1):
-# - On Windows Preferences is called Options
-# - %S = brandShortName
-spaceAlert.over5GB.messageWin1=%S is running out of disk space. Website contents may not display properly. You can clear stored data in Options > Privacy & Security > Cookies and Site Data.
-spaceAlert.under5GB.okButton.label=OK, Got it
-spaceAlert.under5GB.okButton.accesskey=K
-# LOCALIZATION NOTE (spaceAlert.under5GB.message): %S = brandShortName
-spaceAlert.under5GB.message=%S is running out of disk space. Website contents may not display properly. Visit “Learn More” to optimize your disk usage for better browsing experience.
--- a/python/l10n/fluent_migrations/bug_1491676_preferences_properties.py
+++ b/python/l10n/fluent_migrations/bug_1491676_preferences_properties.py
@@ -12,23 +12,166 @@ 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"))
+
+    ctx.add_transforms(
+        "browser/browser/preferences/preferences.ftl",
+        "browser/browser/preferences/preferences.ftl",
+        transforms_from(
+            """
+space-alert-learn-more-button =
+        .label = { COPY(from_path, "spaceAlert.learnMoreButton.label")}
+        .accesskey = { COPY(from_path, "spaceAlert.learnMoreButton.accesskey")}
+space-alert-under-5gb-ok-button =
+        .label = { COPY(from_path, "spaceAlert.under5GB.okButton.label")}
+        .accesskey = { COPY(from_path, "spaceAlert.under5GB.okButton.accesskey")}
+""", from_path="browser/chrome/browser/preferences/preferences.properties"))
+
+    ctx.add_transforms(
+        "browser/browser/preferences/preferences.ftl",
+        "browser/browser/preferences/preferences.ftl",
+        [
+            FTL.Message(
+                id=FTL.Identifier("space-alert-under-5gb-message"),
+                value=REPLACE(
+                    "browser/chrome/browser/preferences/preferences.properties",
+                    "spaceAlert.under5GB.message",
+                    {
+                        "%S": TERM_REFERENCE(
+                            "-brand-short-name"
+                        ),
+                    }
+                )
+            ),
+            FTL.Message(
+                id=FTL.Identifier("space-alert-over-5gb-pref-button"),
+                attributes=[
+                    FTL.Attribute(
+                        id=FTL.Identifier("label"),
+                        value=FTL.Pattern(
+                            elements=[
+                                FTL.Placeable(
+                                    expression=FTL.SelectExpression(
+                                        selector=FTL.CallExpression(
+                                            callee=FTL.Function("PLATFORM")
+                                        ),
+                                        variants=[
+                                            FTL.Variant(
+                                                key=FTL.VariantName("windows"),
+                                                default=False,
+                                                value=COPY(
+                                                    "browser/chrome/browser/preferences/preferences.properties",
+                                                    "spaceAlert.over5GB.prefButtonWin.label"
+                                                )
+                                            ),
+                                            FTL.Variant(
+                                                key=FTL.VariantName("other"),
+                                                default=True,
+                                                value=COPY(
+                                                    "browser/chrome/browser/preferences/preferences.properties",
+                                                    "spaceAlert.over5GB.prefButton.label"
+                                                )
+                                            ),
+                                        ]
+                                    )
+                                )
+                            ]
+                        )
+                    ),
+                    FTL.Attribute(
+                        id=FTL.Identifier("accesskey"),
+                        value=FTL.Pattern(
+                            elements=[
+                                FTL.Placeable(
+                                    expression=FTL.SelectExpression(
+                                        selector=FTL.CallExpression(
+                                            callee=FTL.Function("PLATFORM")
+                                        ),
+                                        variants=[
+                                            FTL.Variant(
+                                                key=FTL.VariantName("windows"),
+                                                default=False,
+                                                value=COPY(
+                                                    "browser/chrome/browser/preferences/preferences.properties",
+                                                    "spaceAlert.over5GB.prefButtonWin.accesskey"
+                                                )
+                                            ),
+                                            FTL.Variant(
+                                                key=FTL.VariantName("other"),
+                                                default=True,
+                                                value=COPY(
+                                                    "browser/chrome/browser/preferences/preferences.properties",
+                                                    "spaceAlert.over5GB.prefButton.accesskey"
+                                                )
+                                            ),
+                                        ]
+                                    )
+                                )
+                            ]
+                        )
+                    ),
+                ]
+            ),
+            FTL.Message(
+                id=FTL.Identifier("space-alert-over-5gb-message"),
+                value=FTL.Pattern(
+                    elements=[
+                        FTL.Placeable(
+                            expression=FTL.SelectExpression(
+                                selector=FTL.CallExpression(
+                                    callee=FTL.Function("PLATFORM")
+                                ),
+                                variants=[
+                                    FTL.Variant(
+                                        key=FTL.VariantName("windows"),
+                                        default=False,
+                                        value=REPLACE(
+                                            "browser/chrome/browser/preferences/preferences.properties",
+                                            "spaceAlert.over5GB.messageWin1",
+                                            {
+                                                "%S": TERM_REFERENCE(
+                                                    "-brand-short-name"
+                                                ),
+                                            }
+                                        )
+                                    ),
+                                    FTL.Variant(
+                                        key=FTL.VariantName("other"),
+                                        default=True,
+                                        value=REPLACE(
+                                            "browser/chrome/browser/preferences/preferences.properties",
+                                            "spaceAlert.over5GB.message1",
+                                            {
+                                                "%S": TERM_REFERENCE(
+                                                    "-brand-short-name"
+                                                ),
+                                            }
+                                        )
+                                    ),
+                                ]
+                            )
+                        )
+                    ]
+                )
+            ),
+        ],
+    )
--- a/toolkit/content/widgets/notification.xml
+++ b/toolkit/content/widgets/notification.xml
@@ -128,19 +128,25 @@
               // with isDefault set to true. If there is no such button, it is
               // added to the first button (unless that button has isDefault
               // set to false). There cannot be multiple default buttons.
               var defaultElem;
 
               for (var b = 0; b < aButtons.length; b++) {
                 var button = aButtons[b];
                 var buttonElem = document.createXULElement("button");
-                buttonElem.setAttribute("label", button.label);
-                if (typeof button.accessKey == "string")
-                  buttonElem.setAttribute("accesskey", button.accessKey);
+
+                if (button["l10n-id"]) {
+                  buttonElem.setAttribute("data-l10n-id", button["l10n-id"]);
+                } else {
+                  buttonElem.setAttribute("label", button.label);
+                  if (typeof button.accessKey == "string")
+                    buttonElem.setAttribute("accesskey", button.accessKey);
+                }
+
                 buttonElem.classList.add("notification-button");
 
                 if (button.isDefault ||
                     b == 0 && !("isDefault" in button))
                   defaultElem = buttonElem;
 
                 newitem.appendChild(buttonElem);
                 buttonElem.buttonInfo = button;