Bug 1457021 - Migrate the JS of Preferences::Blocklists to Fluent. r?gijs,flod draft
authorZibi Braniecki <zbraniecki@mozilla.com>
Thu, 19 Apr 2018 16:59:44 -0700
changeset 793208 1df58ee48ee6041a6283d0ebedffdadad060b885
parent 792573 7c83ceac4be6d055bebd870a82b78b76de14b9d7
child 793209 0a3fba64db940c4facb924bb79e5ef85f1756280
push id109319
push userbmo:gandalf@aviary.pl
push dateWed, 09 May 2018 19:05:09 +0000
reviewersgijs, flod
bugs1457021
milestone62.0a1
Bug 1457021 - Migrate the JS of Preferences::Blocklists to Fluent. r?gijs,flod MozReview-Commit-ID: DlcJNPukzHW
browser/components/preferences/blocklists.js
browser/components/preferences/blocklists.xul
browser/locales/en-US/browser/preferences/blocklists.ftl
browser/locales/en-US/chrome/browser/preferences/preferences.properties
modules/libpref/init/all.js
--- a/browser/components/preferences/blocklists.js
+++ b/browser/components/preferences/blocklists.js
@@ -7,31 +7,27 @@ const BASE_LIST_ID = "base";
 const CONTENT_LIST_ID = "content";
 const TRACK_SUFFIX = "-track-digest256";
 const TRACKING_TABLE_PREF = "urlclassifier.trackingTable";
 const LISTS_PREF_BRANCH = "browser.safebrowsing.provider.mozilla.lists.";
 
 var gBlocklistManager = {
   _type: "",
   _blockLists: [],
-  _bundle: null,
   _tree: null,
 
   _view: {
     _rowCount: 0,
     get rowCount() {
       return this._rowCount;
     },
     getCellText(row, column) {
       if (column.id == "listCol") {
         let list = gBlocklistManager._blockLists[row];
-        let desc = list.description ? list.description : "";
-        let text = gBlocklistManager._bundle.getFormattedString("mozNameTemplate",
-                                                                [list.name, desc]);
-        return text;
+        return list.name;
       }
       return "";
     },
 
     isSeparator(index) { return false; },
     isSorted() { return false; },
     isContainer(index) { return false; },
     setTree(tree) {},
@@ -57,17 +53,16 @@ var gBlocklistManager = {
     if (event.keyCode == KeyEvent.DOM_VK_ESCAPE) {
       window.close();
     } else if (event.keyCode == KeyEvent.DOM_VK_RETURN) {
       gBlocklistManager.onApplyChanges();
     }
   },
 
   onLoad() {
-    this._bundle = document.getElementById("bundlePreferences");
     let params = window.arguments[0];
     this.init(params);
   },
 
   init(params) {
     if (this._type) {
       // reusing an open dialog, clear the old observer
       this.uninit();
@@ -114,53 +109,50 @@ var gBlocklistManager = {
       if (listmanager) {
         listmanager.forceUpdates(trackingTable);
       }
     }
 
     window.close();
   },
 
-  _loadBlockLists() {
+  async _loadBlockLists() {
     this._blockLists = [];
 
     // Load blocklists into a table.
     let branch = Services.prefs.getBranch(LISTS_PREF_BRANCH);
     let itemArray = branch.getChildList("");
     for (let itemName of itemArray) {
       try {
-        this._createOrUpdateBlockList(itemName);
+        let list = await this._createBlockList(itemName);
+        this._blockLists.push(list);
       } catch (e) {
         // Ignore bogus or missing list name.
         continue;
       }
     }
 
     this._updateTree();
   },
 
-  _createOrUpdateBlockList(itemName) {
+  async _createBlockList(id) {
     let branch = Services.prefs.getBranch(LISTS_PREF_BRANCH);
-    let key = branch.getCharPref(itemName);
-    let value = this._bundle.getString(key);
+    let l10nKey = branch.getCharPref(id);
+    let [listName, description] = await document.l10n.formatValues([
+      [`blocklist-item-${l10nKey}-name`],
+      [`blocklist-item-${l10nKey}-desc`],
+    ]);
+    let name = await document.l10n.formatValue(
+      "blocklist-item-list-template", {listName, description});
 
-    let suffix = itemName.slice(itemName.lastIndexOf("."));
-    let id = itemName.replace(suffix, "");
-    let list = this._blockLists.find(el => el.id === id);
-    if (!list) {
-      list = { id };
-      this._blockLists.push(list);
-    }
-    list.selected = this._getActiveList() === id;
-
-    // Get the property name from the suffix (e.g. ".name" -> "name").
-    let prop = suffix.slice(1);
-    list[prop] = value;
-
-    return list;
+    return {
+      id,
+      name,
+      selected: this._getActiveList() === id,
+    };
   },
 
   _updateTree() {
     this._tree = document.getElementById("blocklistsTree");
     this._view._rowCount = this._blockLists.length;
     this._tree.view = this._view;
   },
 
--- a/browser/components/preferences/blocklists.xul
+++ b/browser/components/preferences/blocklists.xul
@@ -19,19 +19,16 @@
 
   <link rel="localization" href="branding/brand.ftl"/>
   <link rel="localization" href="browser/preferences/blocklists.ftl"/>
   <script type="application/javascript" src="chrome://global/content/l10n.js"></script>
 
   <script src="chrome://global/content/treeUtils.js"/>
   <script src="chrome://browser/content/preferences/blocklists.js"/>
 
-  <stringbundle id="bundlePreferences"
-                src="chrome://browser/locale/preferences/preferences.properties"/>
-
   <keyset>
     <key data-l10n-id="blocklist-close-key" modifiers="accel" oncommand="window.close();"/>
   </keyset>
 
   <vbox class="contentPane largeDialogContainer" flex="1">
     <description id="blocklistsText" data-l10n-id="blocklist-desc" control="url"/>
     <separator class="thin"/>
     <tree id="blocklistsTree" flex="1" style="height: 18em;"
--- a/browser/locales/en-US/browser/preferences/blocklists.ftl
+++ b/browser/locales/en-US/browser/preferences/blocklists.ftl
@@ -15,8 +15,22 @@ blocklist-treehead-list =
 
 blocklist-button-cancel =
     .label = Cancel
     .accesskey = C
 
 blocklist-button-ok =
     .label = Save Changes
     .accesskey = S
+
+# This template constructs the name of the block list in the block lists dialog.
+# It combines the list name and description.
+# e.g. "Standard (Recommended). This list does a pretty good job."
+#
+# Variables:
+#   $listName {string, "Standard (Recommended)."} - List name.
+#   $description {string, "This list does a pretty good job."} - Description of the list.
+blocklist-item-list-template = { $listName } { $description }
+
+blocklist-item-moz-std-name = Disconnect.me basic protection (Recommended).
+blocklist-item-moz-std-desc = Allows some trackers so websites function properly.
+blocklist-item-moz-full-name = Disconnect.me strict protection.
+blocklist-item-moz-full-desc = Blocks known trackers. Some websites may not function properly.
--- a/browser/locales/en-US/chrome/browser/preferences/preferences.properties
+++ b/browser/locales/en-US/chrome/browser/preferences/preferences.properties
@@ -13,33 +13,16 @@ phishBeforeText=Selecting this option wi
 
 labelDefaultFont=Default (%S)
 labelDefaultFontUnnamed=Default
 
 veryLargeMinimumFontTitle=Large minimum font size
 veryLargeMinimumFontWarning=You have selected a very large minimum font size (more than 24 pixels). This may make it difficult or impossible to use some important configuration pages like this one.
 acceptVeryLargeMinimumFont=Keep my changes anyway
 
-#### Block List Manager
-
-# LOCALIZATION NOTE (mozNameTemplate): This template constructs the name of the
-# block list in the block lists dialog. It combines the list name and
-# description.
-#   e.g. mozNameTemplate : "Standard (Recommended). This list does a pretty good job."
-#   %1$S = list name (fooName), %2$S = list descriptive text (fooDesc)
-mozNameTemplate=%1$S %2$S
-# LOCALIZATION NOTE (mozstdName, etc.): These labels appear in the tracking
-# protection block lists dialog, mozNameTemplate is used to create the final
-# string. Note that in the future these two strings (name, desc) could be
-# displayed on two different lines.
-mozstdName=Disconnect.me basic protection (Recommended).
-mozstdDesc=Allows some trackers so websites function properly.
-mozfullName=Disconnect.me strict protection.
-mozfullDesc2=Blocks known trackers. Some websites may not function properly.
-
 #### Master Password
 
 pw_change2empty_in_fips_mode=You are currently in FIPS mode. FIPS requires a non-empty Master Password.
 pw_change_failed_title=Password Change Failed
 
 #### Fonts
 
 # LOCALIZATION NOTE: The string represents a localized locale name
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -5407,20 +5407,18 @@ pref("browser.safebrowsing.reportPhishUR
 pref("browser.safebrowsing.provider.mozilla.pver", "2.2");
 pref("browser.safebrowsing.provider.mozilla.lists", "base-track-digest256,mozstd-trackwhite-digest256,content-track-digest256,mozplugin-block-digest256,mozplugin2-block-digest256,block-flash-digest256,except-flash-digest256,allow-flashallow-digest256,except-flashallow-digest256,block-flashsubdoc-digest256,except-flashsubdoc-digest256,except-flashinfobar-digest256,ads-track-digest256,social-track-digest256,analytics-track-digest256");
 pref("browser.safebrowsing.provider.mozilla.updateURL", "https://shavar.services.mozilla.com/downloads?client=SAFEBROWSING_ID&appver=%MAJOR_VERSION%&pver=2.2");
 pref("browser.safebrowsing.provider.mozilla.gethashURL", "https://shavar.services.mozilla.com/gethash?client=SAFEBROWSING_ID&appver=%MAJOR_VERSION%&pver=2.2");
 // Set to a date in the past to force immediate download in new profiles.
 pref("browser.safebrowsing.provider.mozilla.nextupdatetime", "1");
 // Block lists for tracking protection. The name values will be used as the keys
 // to lookup the localized name in preferences.properties.
-pref("browser.safebrowsing.provider.mozilla.lists.base.name", "mozstdName");
-pref("browser.safebrowsing.provider.mozilla.lists.base.description", "mozstdDesc");
-pref("browser.safebrowsing.provider.mozilla.lists.content.name", "mozfullName");
-pref("browser.safebrowsing.provider.mozilla.lists.content.description", "mozfullDesc2");
+pref("browser.safebrowsing.provider.mozilla.lists.base", "moz-std");
+pref("browser.safebrowsing.provider.mozilla.lists.content", "moz-full");
 
 // The table and global pref for blocking plugin content
 pref("browser.safebrowsing.blockedURIs.enabled", true);
 pref("urlclassifier.blockedTable", "test-block-simple,mozplugin-block-digest256");
 
 // Flash blocking tables
 pref("urlclassifier.flashAllowTable", "allow-flashallow-digest256");
 pref("urlclassifier.flashAllowExceptTable", "except-flashallow-digest256");