Bug 1457021 - Migrate the JS of Preferences::SiteData to Fluent. r=flod,johannh
authorZibi Braniecki <zbraniecki@mozilla.com>
Mon, 23 Apr 2018 10:12:21 -0700
changeset 417604 8f74f964537dc0f86cd5ebc900977c6651d21744
parent 417603 7bb95530ceeb6901fa03379acadeb2fb3ad03fcd
child 417605 4332073c7382a7850d53ebd11a3382226d2efc6b
push id33974
push userncsoregi@mozilla.com
push dateThu, 10 May 2018 09:47:43 +0000
treeherdermozilla-central@b52b2eb81d1e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflod, johannh
bugs1457021
milestone62.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 1457021 - Migrate the JS of Preferences::SiteData to Fluent. r=flod,johannh MozReview-Commit-ID: 5sYMU3dDTRy
browser/components/preferences/in-content/privacy.js
browser/components/preferences/in-content/privacy.xul
browser/components/preferences/in-content/tests/siteData/browser_siteData.js
browser/components/preferences/siteDataRemoveSelected.js
browser/components/preferences/siteDataRemoveSelected.xul
browser/components/preferences/siteDataSettings.js
browser/components/preferences/siteDataSettings.xul
browser/locales/en-US/browser/preferences/preferences.ftl
browser/locales/en-US/browser/preferences/siteDataSettings.ftl
browser/locales/en-US/chrome/browser/preferences/preferences.properties
--- a/browser/components/preferences/in-content/privacy.js
+++ b/browser/components/preferences/in-content/privacy.js
@@ -387,20 +387,16 @@ var gPrivacyPane = {
     let signonBundle = document.getElementById("signonBundle");
     let pkiBundle = document.getElementById("pkiBundle");
     appendSearchKeywords("showPasswords", [
       signonBundle.getString("loginsDescriptionAll2"),
     ]);
     appendSearchKeywords("viewSecurityDevicesButton", [
       pkiBundle.getString("enable_fips"),
     ]);
-    appendSearchKeywords("siteDataSettings", [
-      bundlePrefs.getString("siteDataSettings3.description"),
-      bundlePrefs.getString("removeAllSiteData.label"),
-    ]);
 
     if (!PrivateBrowsingUtils.enabled) {
       document.getElementById("privateBrowsingAutoStart").hidden = true;
       document.querySelector("menuitem[value='dontremember']").hidden = true;
     }
 
     // Notify observers that the UI is now ready
     Services.obs.notifyObservers(window, "privacy-pane-loaded");
@@ -881,27 +877,28 @@ var gPrivacyPane = {
     let clearButton = document.getElementById("clearSiteDataButton");
     let settingsButton = document.getElementById("siteDataSettings");
     clearButton.disabled = !shouldShow;
     settingsButton.disabled = !shouldShow;
   },
 
   showSiteDataLoading() {
     let totalSiteDataSizeLabel = document.getElementById("totalSiteDataSize");
-    let prefStrBundle = document.getElementById("bundlePreferences");
-    totalSiteDataSizeLabel.textContent = prefStrBundle.getString("loadingSiteDataSize1");
+    document.l10n.setAttributes(totalSiteDataSizeLabel, "sitedata-total-size-calculating");
   },
 
   updateTotalDataSizeLabel(siteDataUsage) {
     SiteDataManager.getCacheSize().then(function(cacheUsage) {
-      let prefStrBundle = document.getElementById("bundlePreferences");
       let totalSiteDataSizeLabel = document.getElementById("totalSiteDataSize");
       let totalUsage = siteDataUsage + cacheUsage;
-      let size = DownloadUtils.convertByteUnits(totalUsage);
-      totalSiteDataSizeLabel.textContent = prefStrBundle.getFormattedString("totalSiteDataSize2", size);
+      let [value, unit] = DownloadUtils.convertByteUnits(totalUsage);
+      document.l10n.setAttributes(totalSiteDataSizeLabel, "sitedata-total-size", {
+        value,
+        unit
+      });
     });
   },
 
   clearSiteData() {
     gSubDialog.open("chrome://browser/content/preferences/clearSiteData.xul");
   },
 
   // GEOLOCATION
--- a/browser/components/preferences/in-content/privacy.xul
+++ b/browser/components/preferences/in-content/privacy.xul
@@ -235,16 +235,18 @@
         <button id="siteDataSettings"
                 class="accessory-button"
                 data-l10n-id="sitedata-settings"
                 search-l10n-ids="
                   site-data-settings-window.title,
                   site-data-column-host.label,
                   site-data-column-cookies.label,
                   site-data-column-storage.label,
+                  site-data-settings-description,
+                  site-data-remove-all.label,
                 "/>
       </hbox>
       <hbox>
         <button id="cookieExceptions"
                 class="accessory-button"
                 data-l10n-id="sitedata-cookies-exceptions"
                 preference="pref.privacy.disable_button.cookie_exceptions"
                 search-l10n-ids="
--- a/browser/components/preferences/in-content/tests/siteData/browser_siteData.js
+++ b/browser/components/preferences/in-content/tests/siteData/browser_siteData.js
@@ -54,50 +54,50 @@ add_task(async function() {
 
 // Test buttons are disabled and loading message shown while updating sites
 add_task(async function() {
   let updatedPromise = promiseSiteDataManagerSitesUpdated();
   await openPreferencesViaOpenPreferencesAPI("privacy", { leaveOpen: true });
   await updatedPromise;
   let cacheSize = await SiteDataManager.getCacheSize();
 
-  let actual = null;
-  let expected = null;
   let doc = gBrowser.selectedBrowser.contentDocument;
   let clearBtn = doc.getElementById("clearSiteDataButton");
   let settingsButton = doc.getElementById("siteDataSettings");
-  let prefStrBundle = doc.getElementById("bundlePreferences");
   let totalSiteDataSizeLabel = doc.getElementById("totalSiteDataSize");
   is(clearBtn.disabled, false, "Should enable clear button after sites updated");
   is(settingsButton.disabled, false, "Should enable settings button after sites updated");
   await SiteDataManager.getTotalUsage()
                        .then(usage => {
-                         actual = totalSiteDataSizeLabel.textContent;
-                         expected = prefStrBundle.getFormattedString(
-                           "totalSiteDataSize2", DownloadUtils.convertByteUnits(usage + cacheSize));
-                          is(actual, expected, "Should show the right total site data size");
+                         let [value, unit] = DownloadUtils.convertByteUnits(usage + cacheSize);
+                         Assert.deepEqual(doc.l10n.getAttributes(totalSiteDataSizeLabel), {
+                           id: "sitedata-total-size",
+                           args: {value, unit}
+                         }, "Should show the right total site data size");
                        });
 
   Services.obs.notifyObservers(null, "sitedatamanager:updating-sites");
   is(clearBtn.disabled, true, "Should disable clear button while updating sites");
   is(settingsButton.disabled, true, "Should disable settings button while updating sites");
-  actual = totalSiteDataSizeLabel.textContent;
-  expected = prefStrBundle.getString("loadingSiteDataSize1");
-  is(actual, expected, "Should show the loading message while updating");
+  Assert.deepEqual(doc.l10n.getAttributes(totalSiteDataSizeLabel), {
+    id: "sitedata-total-size-calculating",
+    args: null
+  }, "Should show the loading message while updating");
 
   Services.obs.notifyObservers(null, "sitedatamanager:sites-updated");
   is(clearBtn.disabled, false, "Should enable clear button after sites updated");
   is(settingsButton.disabled, false, "Should enable settings button after sites updated");
   cacheSize = await SiteDataManager.getCacheSize();
   await SiteDataManager.getTotalUsage()
                        .then(usage => {
-                         actual = totalSiteDataSizeLabel.textContent;
-                         expected = prefStrBundle.getFormattedString(
-                           "totalSiteDataSize2", DownloadUtils.convertByteUnits(usage + cacheSize));
-                          is(actual, expected, "Should show the right total site data size");
+                         let [value, unit] = DownloadUtils.convertByteUnits(usage + cacheSize);
+                         Assert.deepEqual(doc.l10n.getAttributes(totalSiteDataSizeLabel), {
+                           id: "sitedata-total-size",
+                           args: {value, unit}
+                         }, "Should show the right total site data size");
                        });
 
   BrowserTestUtils.removeTab(gBrowser.selectedTab);
 });
 
 // Test clearing service wroker through the settings panel
 add_task(async function() {
   // Register a test service worker
--- a/browser/components/preferences/siteDataRemoveSelected.js
+++ b/browser/components/preferences/siteDataRemoveSelected.js
@@ -3,21 +3,16 @@
  * 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/. */
 
 "use strict";
 
 let gSiteDataRemoveSelected = {
 
   init() {
-    let bundlePreferences = document.getElementById("bundlePreferences");
-    let acceptBtn = document.getElementById("SiteDataRemoveSelectedDialog")
-                            .getButton("accept");
-    acceptBtn.label = bundlePreferences.getString("acceptRemove");
-
     let hosts = window.arguments[0].hosts;
     hosts.sort();
     let list = document.getElementById("removalList");
     let fragment = document.createDocumentFragment();
     for (let host of hosts) {
       let listItem = document.createElement("listitem");
       listItem.setAttribute("label", host);
       fragment.appendChild(listItem);
--- a/browser/components/preferences/siteDataRemoveSelected.xul
+++ b/browser/components/preferences/siteDataRemoveSelected.xul
@@ -6,31 +6,28 @@
 
 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
 <?xml-stylesheet href="chrome://browser/content/preferences/siteDataSettings.css" type="text/css"?>
 <?xml-stylesheet href="chrome://browser/skin/preferences/in-content/siteDataSettings.css" type="text/css"?>
 
 <dialog id="SiteDataRemoveSelectedDialog"
         windowtype="Browser:SiteDataRemoveSelected"
         width="500"
-        data-l10n-id="site-data-removing-window"
-        data-l10n-attrs="title"
+        data-l10n-id="site-data-removing-dialog"
+        data-l10n-attrs="title, buttonlabelaccept"
         onload="gSiteDataRemoveSelected.init();"
         ondialogaccept="gSiteDataRemoveSelected.ondialogaccept(); return true;"
         ondialogcancel="gSiteDataRemoveSelected.ondialogcancel(); return true;"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
   <link rel="localization" href="browser/preferences/siteDataSettings.ftl"/>
   <script type="application/javascript" src="chrome://global/content/l10n.js"></script>
 
   <script src="chrome://browser/content/preferences/siteDataRemoveSelected.js"/>
 
-  <stringbundle id="bundlePreferences"
-                src="chrome://browser/locale/preferences/preferences.properties"/>
-
   <vbox id="contentContainer">
     <hbox flex="1">
       <vbox>
         <image class="question-icon"/>
       </vbox>
       <vbox flex="1">
         <!-- Only show this label on OS X because of no dialog title -->
         <label id="removing-label"
--- a/browser/components/preferences/siteDataSettings.js
+++ b/browser/components/preferences/siteDataSettings.js
@@ -19,57 +19,63 @@ let gSiteDataSettings = {
   // - baseDomain: base domain of the site
   // - cookies: array of cookies of that site
   // - usage: disk usage which site uses
   // - userAction: "remove" or "update-permission"; the action user wants to take.
   _sites: null,
 
   _list: null,
   _searchBox: null,
-  _prefStrBundle: null,
 
   _createSiteListItem(site) {
     let item = document.createElement("richlistitem");
     item.setAttribute("host", site.host);
     let container = document.createElement("hbox");
 
     // Creates a new column item with the specified relative width.
-    function addColumnItem(value, flexWidth) {
+    function addColumnItem(l10n, flexWidth) {
       let box = document.createElement("hbox");
       box.className = "item-box";
       box.setAttribute("flex", flexWidth);
       let label = document.createElement("label");
       label.setAttribute("crop", "end");
-      if (value) {
-        box.setAttribute("tooltiptext", value);
-        label.setAttribute("value", value);
+      if (l10n) {
+        if (l10n.raw) {
+          box.setAttribute("tooltiptext", l10n.raw);
+          label.setAttribute("value", l10n.raw);
+        } else {
+          document.l10n.setAttributes(label, l10n.id, l10n.args);
+        }
       }
       box.appendChild(label);
       container.appendChild(box);
     }
 
     // Add "Host" column.
-    addColumnItem(site.host, "4");
+    addColumnItem({raw: site.host}, "4");
 
     // Add "Cookies" column.
-    addColumnItem(site.cookies.length, "1");
+    addColumnItem({raw: site.cookies.length}, "1");
 
     // Add "Storage" column
     if (site.usage > 0 || site.persisted) {
-      let size = DownloadUtils.convertByteUnits(site.usage);
-      let strName = site.persisted ? "siteUsagePersistent" : "siteUsage";
-      addColumnItem(this._prefStrBundle.getFormattedString(strName, size), "2");
+      let [value, unit] = DownloadUtils.convertByteUnits(site.usage);
+      let strName = site.persisted ? "site-usage-persistent" : "site-usage-pattern";
+      addColumnItem({
+        id: strName,
+        args: { value, unit }
+      }, "2");
     } else {
       // Pass null to avoid showing "0KB" when there is no site data stored.
       addColumnItem(null, "2");
     }
 
     // Add "Last Used" column.
     addColumnItem(site.lastAccessed > 0 ?
-      this._formatter.format(site.lastAccessed) : null, "2");
+      {raw: this._formatter.format(site.lastAccessed)} : null, "2");
 
     item.appendChild(container);
     return item;
   },
 
   init() {
     function setEventListener(id, eventType, callback) {
       document.getElementById(id)
@@ -77,29 +83,24 @@ let gSiteDataSettings = {
     }
 
     this._formatter = new Services.intl.DateTimeFormat(undefined, {
       dateStyle: "short", timeStyle: "short",
     });
 
     this._list = document.getElementById("sitesList");
     this._searchBox = document.getElementById("searchBox");
-    this._prefStrBundle = document.getElementById("bundlePreferences");
     SiteDataManager.getSites().then(sites => {
       this._sites = sites;
       let sortCol = document.querySelector("treecol[data-isCurrentSortCol=true]");
       this._sortSites(this._sites, sortCol);
       this._buildSitesList(this._sites);
       Services.obs.notifyObservers(null, "sitedata-settings-init");
     });
 
-    let brandShortName = document.getElementById("bundle_brand").getString("brandShortName");
-    let settingsDescription = document.getElementById("settingsDescription");
-    settingsDescription.textContent = this._prefStrBundle.getFormattedString("siteDataSettings3.description", [brandShortName]);
-
     setEventListener("sitesList", "select", this.onSelect);
     setEventListener("hostCol", "click", this.onClickTreeCol);
     setEventListener("usageCol", "click", this.onClickTreeCol);
     setEventListener("lastAccessedCol", "click", this.onClickTreeCol);
     setEventListener("cookiesCol", "click", this.onClickTreeCol);
     setEventListener("cancel", "command", this.close);
     setEventListener("save", "command", this.saveChanges);
     setEventListener("searchBox", "command", this.onCommandSearch);
@@ -109,24 +110,18 @@ let gSiteDataSettings = {
 
   _updateButtonsState() {
     let items = this._list.getElementsByTagName("richlistitem");
     let removeSelectedBtn = document.getElementById("removeSelected");
     let removeAllBtn = document.getElementById("removeAll");
     removeSelectedBtn.disabled = this._list.selectedItems.length == 0;
     removeAllBtn.disabled = items.length == 0;
 
-    let removeAllBtnLabelStringID = "removeAllSiteData.label";
-    let removeAllBtnAccesskeyStringID = "removeAllSiteData.accesskey";
-    if (this._searchBox.value) {
-      removeAllBtnLabelStringID = "removeAllSiteDataShown.label";
-      removeAllBtnAccesskeyStringID = "removeAllSiteDataShown.accesskey";
-    }
-    removeAllBtn.setAttribute("label", this._prefStrBundle.getString(removeAllBtnLabelStringID));
-    removeAllBtn.setAttribute("accesskey", this._prefStrBundle.getString(removeAllBtnAccesskeyStringID));
+    let l10nId = this._searchBox.value ? "site-data-remove-shown" : "site-data-remove-all";
+    document.l10n.setAttributes(removeAllBtn, l10nId);
   },
 
   /**
    * @param sites {Array}
    * @param col {XULElement} the <treecol> being sorted on
    */
   _sortSites(sites, col) {
     let isCurrentSortCol = col.getAttribute("data-isCurrentSortCol");
--- a/browser/components/preferences/siteDataSettings.xul
+++ b/browser/components/preferences/siteDataSettings.xul
@@ -14,27 +14,24 @@
         data-l10n-attrs="title"
         class="windowDialog"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         style="width: 45em;"
         onload="gSiteDataSettings.init();"
         onkeypress="gSiteDataSettings.onKeyPress(event);"
         persist="screenX screenY width height">
 
+  <link rel="localization" href="branding/brand.ftl"/>
   <link rel="localization" href="browser/preferences/siteDataSettings.ftl"/>
   <script type="application/javascript" src="chrome://global/content/l10n.js"></script>
 
   <script src="chrome://browser/content/preferences/siteDataSettings.js"/>
 
-  <stringbundle id="bundlePreferences"
-                src="chrome://browser/locale/preferences/preferences.properties"/>
-  <stringbundle id="bundle_brand" src="chrome://branding/locale/brand.properties"/>
-
   <vbox flex="1">
-    <description id="settingsDescription"></description>
+    <description id="settingsDescription" data-l10n-id="site-data-settings-description"/>
     <separator class="thin"/>
 
     <hbox id="searchBoxContainer">
       <textbox id="searchBox" type="search" flex="1"
         data-l10n-id="site-data-search-textbox"/>
     </hbox>
     <separator class="thin"/>
 
--- a/browser/locales/en-US/browser/preferences/preferences.ftl
+++ b/browser/locales/en-US/browser/preferences/preferences.ftl
@@ -715,16 +715,23 @@ history-clear-on-close-settings =
 history-clear-button =
     .label = Clear History…
     .accesskey = s
 
 ## Privacy Section - Site Data
 
 sitedata-header = Cookies and Site Data
 
+sitedata-total-size-calculating = Calculating site data and cache size…
+
+# Variables:
+#   $value (Number) - Value of the unit (for example: 4.6, 500)
+#   $unit (String) - Name of the unit (for example: "bytes", "KB")
+sitedata-total-size = Your stored cookies, site data and cache are currently using { $value } { $unit } of disk space.
+
 sitedata-learn-more = Learn more
 
 sitedata-accept-cookies-option =
     .label = Accept cookies and site data from websites (recommended)
     .accesskey = A
 
 sitedata-block-cookies-option =
     .label = Block cookies and site data (may cause websites to break)
--- a/browser/locales/en-US/browser/preferences/siteDataSettings.ftl
+++ b/browser/locales/en-US/browser/preferences/siteDataSettings.ftl
@@ -3,16 +3,18 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 
 ## Settings
 
 site-data-settings-window =
     .title = Manage Cookies and Site Data
 
+site-data-settings-description = The following websites store cookies and site data on your computer. { -brand-short-name } keeps data from websites with persistent storage until you delete it, and deletes data from websites with non-persistent storage as space is needed.
+
 site-data-search-textbox =
     .placeholder = Search websites
     .accesskey = S
 
 site-data-column-host =
     .label = Site
 site-data-column-cookies =
     .label = Cookies
@@ -28,18 +30,33 @@ site-data-remove-selected =
 site-data-button-cancel =
     .label = Cancel
     .accesskey = C
 
 site-data-button-save =
     .label = Save Changes
     .accesskey = a
 
+# Variables:
+#   $value (Number) - Value of the unit (for example: 4.6, 500)
+#   $unit (String) - Name of the unit (for example: "bytes", "KB")
+site-usage-pattern = { $value } { $unit }
+site-usage-persistent = { site-usage-pattern } (Persistent)
+
+site-data-remove-all =
+    .label = Remove All
+    .accesskey = e
+
+site-data-remove-shown =
+    .label = Remove All Shown
+    .accesskey = e
+
 ## Removing
 
-site-data-removing-window =
+site-data-removing-dialog =
     .title = { site-data-removing-header }
+    .buttonlabelaccept = Remove
 
 site-data-removing-header = Removing Cookies and Site Data
 
 site-data-removing-desc = Removing cookies and site data may log you out of websites. Are you sure you want to make the changes?
 
 site-data-removing-table = Cookies and site data for the following websites will be removed
--- a/browser/locales/en-US/chrome/browser/preferences/preferences.properties
+++ b/browser/locales/en-US/chrome/browser/preferences/preferences.properties
@@ -64,41 +64,16 @@ typeDescriptionWithType=%S (%S)
 #### Permission labels
 
 can=Allow
 canAccessFirstParty=Allow first party only
 canSession=Allow for Session
 cannot=Block
 prompt=Always Ask
 
-#### Site Data Manager
-
-# LOCALIZATION NOTE (totalSiteDataSize2, siteUsage, siteUsagePersistent):
-#   This is the total usage of site data, where we insert storage size and unit.
-#   e.g., "The total usage is currently 200 MB"
-#   %1$S = size
-#   %2$S = unit (MB, KB, etc.)
-totalSiteDataSize2=Your stored cookies, site data and cache are currently using %1$S %2$S of disk space.
-siteUsage=%1$S %2$S
-siteUsagePersistent=%1$S %2$S (Persistent)
-loadingSiteDataSize1=Calculating site data and cache size…
-
-acceptRemove=Remove
-# LOCALIZATION NOTE (siteDataSettings3.description): %S = brandShortName
-siteDataSettings3.description=The following websites store cookies and site data on your computer. %S keeps data from websites with persistent storage until you delete it, and deletes data from websites with non-persistent storage as space is needed.
-# LOCALIZATION NOTE (removeAllSiteData, removeAllSiteDataShown):
-# removeAllSiteData and removeAllSiteDataShown are both used on the same one button,
-# never displayed together and can share the same accesskey.
-# When only partial sites are shown as a result of keyword search,
-# removeAllShown is displayed as button label.
-# removeAll is displayed when no keyword search and all sites are shown.
-removeAllSiteData.label=Remove All
-removeAllSiteData.accesskey=e
-removeAllSiteDataShown.label=Remove All Shown
-removeAllSiteDataShown.accesskey=e
 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