Bug 1364047 - Pull WebConsoleUtils.l10n into its own module;r=Honza

MozReview-Commit-ID: LI5Hrs33CVS

--HG--
extra : rebase_source : 5da9d9ac8acf90f2446d1068589f1a4d314c0695
This commit is contained in:
Brian Grinstead 2017-05-17 14:07:03 -07:00
Родитель 7e085a93c6
Коммит 4897fac06f
17 изменённых файлов: 86 добавлений и 93 удалений

Просмотреть файл

@ -19,12 +19,11 @@ loader.lazyRequireGetter(this, "ObjectClient", "devtools/shared/client/main", tr
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 = "devtools/client/locales/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 l10n = require("devtools/client/webconsole/webconsole-l10n");
const nodeConstants = require("devtools/shared/dom-node-constants");
const {PluralForm} = require("devtools/shared/plural-form");

Просмотреть файл

@ -22,8 +22,7 @@ loader.lazyRequireGetter(this, "DebuggerClient", "devtools/shared/client/main",
loader.lazyRequireGetter(this, "showDoorhanger", "devtools/client/shared/doorhanger", true);
loader.lazyRequireGetter(this, "viewSource", "devtools/client/shared/view-source");
const STRINGS_URI = "devtools/client/locales/webconsole.properties";
var l10n = new WebConsoleUtils.L10n(STRINGS_URI);
const l10n = require("devtools/client/webconsole/webconsole-l10n");
const BROWSER_CONSOLE_WINDOW_FEATURES = "chrome,titlebar,toolbar,centerscreen,resizable,dialog=no";

Просмотреть файл

@ -27,8 +27,7 @@ loader.lazyImporter(this, "VariablesView", "resource://devtools/client/shared/wi
loader.lazyImporter(this, "VariablesViewController", "resource://devtools/client/shared/widgets/VariablesViewController.jsm");
loader.lazyRequireGetter(this, "gDevTools", "devtools/client/framework/devtools", true);
const STRINGS_URI = "devtools/client/locales/webconsole.properties";
var l10n = new WebConsoleUtils.L10n(STRINGS_URI);
const l10n = require("devtools/client/webconsole/webconsole-l10n");
// Constants used for defining the direction of JSTerm input history navigation.
const HISTORY_BACK = -1;

Просмотреть файл

@ -19,8 +19,9 @@ DevToolsModules(
'panel.js',
'utils.js',
'webconsole-connection-proxy.js',
'webconsole-l10n.js',
'webconsole.js',
)
with Files('**'):
BUG_COMPONENT = ('Firefox', 'Developer Tools: Console')
with Files('**'):
BUG_COMPONENT = ('Firefox', 'Developer Tools: Console')

Просмотреть файл

@ -99,8 +99,7 @@ describe("ConsoleAPICall component:", () => {
serviceContainer,
timestampsVisible: true,
}));
const L10n = require("devtools/client/webconsole/new-console-output/test/fixtures/L10n");
const { timestampString } = new L10n();
const { timestampString } = require("devtools/client/webconsole/webconsole-l10n");
expect(wrapper.find(".timestamp").text()).toBe(timestampString(message.timeStamp));
});

Просмотреть файл

@ -97,8 +97,7 @@ describe("EvaluationResult component:", () => {
message,
timestampsVisible: true,
}));
const L10n = require("devtools/client/webconsole/new-console-output/test/fixtures/L10n");
const { timestampString } = new L10n();
const { timestampString } = require("devtools/client/webconsole/webconsole-l10n");
expect(wrapper.find(".timestamp").text()).toBe(timestampString(message.timeStamp));
});

Просмотреть файл

@ -29,8 +29,7 @@ describe("NetworkEventMessage component:", () => {
serviceContainer,
timestampsVisible: true,
}));
const L10n = require("devtools/client/webconsole/new-console-output/test/fixtures/L10n");
const { timestampString } = new L10n();
const { timestampString } = require("devtools/client/webconsole/webconsole-l10n");
expect(wrapper.find(".timestamp").text()).toBe(timestampString(message.timeStamp));
expect(wrapper.find(".message-body .method").text()).toBe("GET");

Просмотреть файл

@ -32,8 +32,7 @@ describe("PageError component:", () => {
serviceContainer,
timestampsVisible: true,
}));
const L10n = require("devtools/client/webconsole/new-console-output/test/fixtures/L10n");
const { timestampString } = new L10n();
const { timestampString } = require("devtools/client/webconsole/webconsole-l10n");
expect(wrapper.find(".timestamp").text()).toBe(timestampString(message.timeStamp));

Просмотреть файл

@ -14,9 +14,7 @@ Services.scriptloader.loadSubScript(
"chrome://mochitests/content/browser/devtools/client/framework/test/shared-head.js",
this);
var {Utils: WebConsoleUtils} = require("devtools/client/webconsole/utils");
const WEBCONSOLE_STRINGS_URI = "devtools/client/locales/webconsole.properties";
var WCUL10n = new WebConsoleUtils.L10n(WEBCONSOLE_STRINGS_URI);
var WCUL10n = require("devtools/client/webconsole/webconsole-l10n");
Services.prefs.setBoolPref("devtools.webconsole.new-frontend-enabled", true);
registerCleanupFunction(function* () {

Просмотреть файл

@ -27,8 +27,6 @@ requireHacker.global_hook("default", path => {
// Some modules depend on Chrome APIs which don't work in mocha. When such a module
// is required, replace it with a mock version.
switch (path) {
case "devtools/client/webconsole/utils":
return `module.exports = require("devtools/client/webconsole/new-console-output/test/fixtures/WebConsoleUtils")`;
case "devtools/shared/l10n":
return `module.exports = require("devtools/client/webconsole/new-console-output/test/fixtures/LocalizationHelper")`;
case "devtools/shared/plural-form":

Просмотреть файл

@ -6,9 +6,7 @@
"use strict";
const WebConsoleUtils = require("devtools/client/webconsole/utils").Utils;
const STRINGS_URI = "devtools/client/locales/webconsole.properties";
const l10n = new WebConsoleUtils.L10n(STRINGS_URI);
const l10n = require("devtools/client/webconsole/webconsole-l10n");
const {
MESSAGE_SOURCE,

Просмотреть файл

@ -37,8 +37,7 @@ const SEVERITY_LOG = 3;
// The indent of a console group in pixels.
const GROUP_INDENT = 12;
const WEBCONSOLE_STRINGS_URI = "devtools/client/locales/webconsole.properties";
var WCUL10n = new WebConsoleUtils.L10n(WEBCONSOLE_STRINGS_URI);
var WCUL10n = require("devtools/client/webconsole/webconsole-l10n");
const DOCS_GA_PARAMS = "?utm_source=mozilla" +
"&utm_medium=firefox-console-errors" +

Просмотреть файл

@ -8,7 +8,6 @@
const {Cc, Ci} = require("chrome");
const Services = require("Services");
const {LocalizationHelper} = require("devtools/shared/l10n");
// Match the function name from the result of toString() or toSource().
//
@ -285,65 +284,3 @@ var WebConsoleUtils = {
exports.Utils = WebConsoleUtils;
// Localization
WebConsoleUtils.L10n = function (bundleURI) {
this._helper = new LocalizationHelper(bundleURI);
};
WebConsoleUtils.L10n.prototype = {
/**
* 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.
*/
timestampString: function (milliseconds) {
let d = new Date(milliseconds ? milliseconds : null);
let hours = d.getHours(), minutes = d.getMinutes();
let seconds = d.getSeconds();
milliseconds = d.getMilliseconds();
let parameters = [hours, minutes, seconds, milliseconds];
return this.getFormatStr("timestampFormat", parameters);
},
/**
* 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) {
try {
return this._helper.getStr(name);
} catch (ex) {
console.error("Failed to get string: " + name);
throw ex;
}
},
/**
* 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) {
try {
return this._helper.getFormatStr(name, ...array);
} catch (ex) {
console.error("Failed to format string: " + name);
throw ex;
}
},
};

Просмотреть файл

@ -10,8 +10,7 @@ const {Utils: WebConsoleUtils} = require("devtools/client/webconsole/utils");
const defer = require("devtools/shared/defer");
const Services = require("Services");
const STRINGS_URI = "devtools/client/locales/webconsole.properties";
var l10n = new WebConsoleUtils.L10n(STRINGS_URI);
const l10n = require("devtools/client/webconsole/webconsole-l10n");
const PREF_CONNECTION_TIMEOUT = "devtools.debugger.remote-timeout";
// Web Console connection proxy

Просмотреть файл

@ -0,0 +1,70 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* 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 {LocalizationHelper} = require("devtools/shared/l10n");
const helper = new LocalizationHelper("devtools/client/locales/webconsole.properties");
const l10n = {
/**
* 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.
*/
timestampString: function (milliseconds) {
let d = new Date(milliseconds ? milliseconds : null);
let hours = d.getHours(), minutes = d.getMinutes();
let seconds = d.getSeconds();
milliseconds = d.getMilliseconds();
let parameters = [hours, minutes, seconds, milliseconds];
return l10n.getFormatStr("timestampFormat", parameters);
},
/**
* 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) {
try {
return helper.getStr(name);
} catch (ex) {
console.error("Failed to get string: " + name);
throw ex;
}
},
/**
* 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) {
try {
return helper.getFormatStr(name, ...array);
} catch (ex) {
console.error("Failed to format string: " + name);
throw ex;
}
},
};
module.exports = l10n;

Просмотреть файл

@ -38,8 +38,7 @@ loader.lazyRequireGetter(this, "ZoomKeys", "devtools/client/shared/zoom-keys");
loader.lazyRequireGetter(this, "WebConsoleConnectionProxy", "devtools/client/webconsole/webconsole-connection-proxy", true);
const {PluralForm} = require("devtools/shared/plural-form");
const STRINGS_URI = "devtools/client/locales/webconsole.properties";
var l10n = new WebConsoleUtils.L10n(STRINGS_URI);
const l10n = require("devtools/client/webconsole/webconsole-l10n");
const XHTML_NS = "http://www.w3.org/1999/xhtml";

Просмотреть файл

@ -49,6 +49,7 @@ webpackConfig.resolve = {
"devtools/client/webconsole/utils": path.join(__dirname, "new-console-output/test/fixtures/WebConsoleUtils"),
"devtools/client/webconsole/new-console-output": path.join(__dirname, "new-console-output"),
"devtools/client/webconsole/webconsole-connection-proxy": path.join(__dirname, "webconsole-connection-proxy"),
"devtools/client/webconsole/webconsole-l10n": path.join(__dirname, "webconsole-l10n"),
"react": path.join(__dirname, "node_modules/react"),
"devtools/client/shared/vendor/immutable": "immutable",