Bug 1295609 - Migrate devtools/client/webconsole to use l10n.js instead of Services.string;r=bgrins draft
authorJulian Descottes <jdescottes@mozilla.com>
Fri, 19 Aug 2016 20:31:50 +0200
changeset 405313 289b85f59aa30224394e4dfff4a3135ffd343514
parent 405286 5e61f2092459237433e5734d616565fc3ea7ef14
child 529430 62d96425355d44f266c2070ac9e1737cef2d57c4
push id27479
push userjdescottes@mozilla.com
push dateThu, 25 Aug 2016 10:42:59 +0000
reviewersbgrins
bugs1295609
milestone51.0a1
Bug 1295609 - Migrate devtools/client/webconsole to use l10n.js instead of Services.string;r=bgrins MozReview-Commit-ID: 65AyxZ68GHt
devtools/client/webconsole/console-output.js
devtools/client/webconsole/hudservice.js
devtools/client/webconsole/jsterm.js
devtools/client/webconsole/net/main.js
devtools/client/webconsole/new-console-output/utils/messages.js
devtools/client/webconsole/test/head.js
devtools/client/webconsole/utils.js
devtools/client/webconsole/webconsole.js
--- a/devtools/client/webconsole/console-output.js
+++ b/devtools/client/webconsole/console-output.js
@@ -15,17 +15,17 @@ loader.lazyImporter(this, "PluralForm", 
 loader.lazyRequireGetter(this, "promise");
 loader.lazyRequireGetter(this, "gDevTools", "devtools/client/framework/devtools", true);
 loader.lazyRequireGetter(this, "TableWidget", "devtools/client/shared/widgets/TableWidget", true);
 loader.lazyRequireGetter(this, "ObjectClient", "devtools/shared/client/main", true);
 
 const { extend } = require("sdk/core/heritage");
 const XHTML_NS = "http://www.w3.org/1999/xhtml";
 const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
-const STRINGS_URI = "chrome://devtools/locale/webconsole.properties";
+const STRINGS_URI = "devtools/locale/webconsole.properties";
 
 const WebConsoleUtils = require("devtools/client/webconsole/utils").Utils;
 const { getSourceNames } = require("devtools/client/shared/source-utils");
 const {Task} = require("devtools/shared/task");
 const l10n = new WebConsoleUtils.L10n(STRINGS_URI);
 const nodeConstants = require("devtools/shared/dom-node-constants");
 
 const MAX_STRING_GRIP_LENGTH = 36;
--- a/devtools/client/webconsole/hudservice.js
+++ b/devtools/client/webconsole/hudservice.js
@@ -17,17 +17,17 @@ var Services = require("Services");
 loader.lazyRequireGetter(this, "Telemetry", "devtools/client/shared/telemetry");
 loader.lazyRequireGetter(this, "WebConsoleFrame", "devtools/client/webconsole/webconsole", true);
 loader.lazyRequireGetter(this, "gDevTools", "devtools/client/framework/devtools", true);
 loader.lazyRequireGetter(this, "DebuggerServer", "devtools/server/main", true);
 loader.lazyRequireGetter(this, "DebuggerClient", "devtools/shared/client/main", true);
 loader.lazyRequireGetter(this, "showDoorhanger", "devtools/client/shared/doorhanger", true);
 loader.lazyRequireGetter(this, "viewSource", "devtools/client/shared/view-source");
 
-const STRINGS_URI = "chrome://devtools/locale/webconsole.properties";
+const STRINGS_URI = "devtools/locale/webconsole.properties";
 var l10n = new WebConsoleUtils.L10n(STRINGS_URI);
 
 const BROWSER_CONSOLE_WINDOW_FEATURES = "chrome,titlebar,toolbar,centerscreen,resizable,dialog=no";
 
 // The preference prefix for all of the Browser Console filters.
 const BROWSER_CONSOLE_FILTER_PREFS_PREFIX = "devtools.browserconsole.filter.";
 
 var gHudId = 0;
--- a/devtools/client/webconsole/jsterm.js
+++ b/devtools/client/webconsole/jsterm.js
@@ -22,17 +22,17 @@ loader.lazyRequireGetter(this, "ToolSide
 loader.lazyRequireGetter(this, "Messages", "devtools/client/webconsole/console-output", true);
 loader.lazyRequireGetter(this, "asyncStorage", "devtools/shared/async-storage");
 loader.lazyRequireGetter(this, "EnvironmentClient", "devtools/shared/client/main", true);
 loader.lazyRequireGetter(this, "ObjectClient", "devtools/shared/client/main", true);
 loader.lazyImporter(this, "VariablesView", "resource://devtools/client/shared/widgets/VariablesView.jsm");
 loader.lazyImporter(this, "VariablesViewController", "resource://devtools/client/shared/widgets/VariablesViewController.jsm");
 loader.lazyRequireGetter(this, "gDevTools", "devtools/client/framework/devtools", true);
 
-const STRINGS_URI = "chrome://devtools/locale/webconsole.properties";
+const STRINGS_URI = "devtools/locale/webconsole.properties";
 var l10n = new WebConsoleUtils.L10n(STRINGS_URI);
 
 // Constants used for defining the direction of JSTerm input history navigation.
 const HISTORY_BACK = -1;
 const HISTORY_FORWARD = 1;
 
 const XHTML_NS = "http://www.w3.org/1999/xhtml";
 
--- a/devtools/client/webconsole/net/main.js
+++ b/devtools/client/webconsole/net/main.js
@@ -14,19 +14,18 @@ const rootUrl = "resource://devtools/cli
 const require = BrowserLoader({
   baseURI: rootUrl,
   window: this}).require;
 
 const NetRequest = require("./net-request");
 const { loadSheet } = require("sdk/stylesheet/utils");
 
 // Localization
-const { Services } = Cu.import("resource://gre/modules/Services.jsm", {});
-var networkStrings = Services.strings.createBundle(
-  "chrome://devtools/locale/netmonitor.properties");
+const {LocalizationHelper} = require("devtools/client/shared/l10n");
+const L10N = new LocalizationHelper("devtools/locale/netmonitor.properties");
 
 // Stylesheets
 var styleSheets = [
   "resource://devtools/client/jsonview/css/toolbar.css",
   "resource://devtools/client/shared/components/tree/tree-view.css",
   "resource://devtools/client/shared/components/reps/reps.css",
   "resource://devtools/client/webconsole/net/net-request.css",
   "resource://devtools/client/webconsole/net/components/size-limit.css",
@@ -50,17 +49,17 @@ styleSheets.forEach(url => {
 //   let localizedString = Locale.$STR('string-key');
 //
 // Resources:
 // http://l20n.org/
 // https://github.com/yahoo/react-intl
 this.Locale = {
   $STR: key => {
     try {
-      return networkStrings.GetStringFromName(key);
+      return L10N.getStr(key);
     } catch (err) {
       console.error(key + ": " + err);
     }
   }
 };
 
 // List of NetRequest instances represents the state.
 // As soon as Redux is in place it should be maintained using a reducer.
--- a/devtools/client/webconsole/new-console-output/utils/messages.js
+++ b/devtools/client/webconsole/new-console-output/utils/messages.js
@@ -2,17 +2,17 @@
 /* vim: set ft=javascript ts=2 et sw=2 tw=80: */
 /* 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/. */
 
 "use strict";
 
 const WebConsoleUtils = require("devtools/client/webconsole/utils").Utils;
-const STRINGS_URI = "chrome://devtools/locale/webconsole.properties";
+const STRINGS_URI = "devtools/locale/webconsole.properties";
 const l10n = new WebConsoleUtils.L10n(STRINGS_URI);
 
 const {
   MESSAGE_SOURCE,
   MESSAGE_TYPE,
   MESSAGE_LEVEL,
 } = require("../constants");
 const { ConsoleMessage } = require("../types");
--- a/devtools/client/webconsole/test/head.js
+++ b/devtools/client/webconsole/test/head.js
@@ -32,18 +32,17 @@ const CATEGORY_SERVER = 7;
 const SEVERITY_ERROR = 0;
 const SEVERITY_WARNING = 1;
 const SEVERITY_INFO = 2;
 const SEVERITY_LOG = 3;
 
 // The indent of a console group in pixels.
 const GROUP_INDENT = 12;
 
-const WEBCONSOLE_STRINGS_URI = "chrome://devtools/locale/" +
-                               "webconsole.properties";
+const WEBCONSOLE_STRINGS_URI = "devtools/locale/webconsole.properties";
 var WCUL10n = new WebConsoleUtils.L10n(WEBCONSOLE_STRINGS_URI);
 
 const DOCS_GA_PARAMS = "?utm_source=mozilla" +
                        "&utm_medium=firefox-console-errors" +
                        "&utm_campaign=default";
 
 flags.testing = true;
 
--- a/devtools/client/webconsole/utils.js
+++ b/devtools/client/webconsole/utils.js
@@ -3,16 +3,17 @@
 /* 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/. */
 
 "use strict";
 
 const {Cc, Ci, Cu, components} = require("chrome");
 const Services = require("Services");
+const {LocalizationHelper} = require("devtools/client/shared/l10n");
 
 // Match the function name from the result of toString() or toSource().
 //
 // Examples:
 // (function foobar(a, b) { ...
 // function foobar2(a) { ...
 // function() { ...
 const REGEX_MATCH_FUNCTION_NAME = /^\(?function\s+([^(\s]+)\s*\(/;
@@ -330,29 +331,20 @@ var WebConsoleUtils = {
 
 exports.Utils = WebConsoleUtils;
 
 // ////////////////////////////////////////////////////////////////////////
 // Localization
 // ////////////////////////////////////////////////////////////////////////
 
 WebConsoleUtils.L10n = function (bundleURI) {
-  this._bundleUri = bundleURI;
+  this._helper = new LocalizationHelper(bundleURI);
 };
 
 WebConsoleUtils.L10n.prototype = {
-  _stringBundle: null,
-
-  get stringBundle() {
-    if (!this._stringBundle) {
-      this._stringBundle = Services.strings.createBundle(this._bundleUri);
-    }
-    return this._stringBundle;
-  },
-
   /**
    * Generates a formatted timestamp string for displaying in console messages.
    *
    * @param integer [milliseconds]
    *        Optional, allows you to specify the timestamp in milliseconds since
    *        the UNIX epoch.
    * @return string
    *         The timestamp formatted for display.
@@ -370,41 +362,36 @@ WebConsoleUtils.L10n.prototype = {
    * Retrieve a localized string.
    *
    * @param string name
    *        The string name you want from the Web Console string bundle.
    * @return string
    *         The localized string.
    */
   getStr: function (name) {
-    let result;
     try {
-      result = this.stringBundle.GetStringFromName(name);
+      return this._helper.getStr(name);
     } catch (ex) {
       console.error("Failed to get string: " + name);
       throw ex;
     }
-    return result;
   },
 
   /**
    * Retrieve a localized string formatted with values coming from the given
    * array.
    *
    * @param string name
    *        The string name you want from the Web Console string bundle.
    * @param array array
    *        The array of values you want in the formatted string.
    * @return string
    *         The formatted local string.
    */
   getFormatStr: function (name, array) {
-    let result;
     try {
-      result = this.stringBundle.formatStringFromName(name, array,
-                                                      array.length);
+      return this._helper.getFormatStr(name, ...array);
     } catch (ex) {
       console.error("Failed to format string: " + name);
       throw ex;
     }
-    return result;
   },
 };
--- a/devtools/client/webconsole/webconsole.js
+++ b/devtools/client/webconsole/webconsole.js
@@ -34,17 +34,17 @@ loader.lazyRequireGetter(this, "JSTerm",
 loader.lazyRequireGetter(this, "gSequenceId", "devtools/client/webconsole/jsterm", true);
 loader.lazyImporter(this, "VariablesView", "resource://devtools/client/shared/widgets/VariablesView.jsm");
 loader.lazyImporter(this, "VariablesViewController", "resource://devtools/client/shared/widgets/VariablesViewController.jsm");
 loader.lazyRequireGetter(this, "gDevTools", "devtools/client/framework/devtools", true);
 loader.lazyImporter(this, "PluralForm", "resource://gre/modules/PluralForm.jsm");
 loader.lazyRequireGetter(this, "KeyShortcuts", "devtools/client/shared/key-shortcuts", true);
 loader.lazyRequireGetter(this, "ZoomKeys", "devtools/client/shared/zoom-keys");
 
-const STRINGS_URI = "chrome://devtools/locale/webconsole.properties";
+const STRINGS_URI = "devtools/locale/webconsole.properties";
 var l10n = new WebConsoleUtils.L10n(STRINGS_URI);
 
 const XHTML_NS = "http://www.w3.org/1999/xhtml";
 
 const MIXED_CONTENT_LEARN_MORE = "https://developer.mozilla.org/docs/Web/Security/Mixed_content";
 
 const IGNORED_SOURCE_URLS = ["debugger eval code"];