Bug 1295610 - Migrate devtools/client/framework to use l10n.js instead of Services.string;r=tromey

MozReview-Commit-ID: BwcfFPf85hu

--HG--
extra : rebase_source : 6408bd173b694bfa6df72fb8452a0cb406132f45
This commit is contained in:
Julian Descottes 2016-08-19 20:02:15 +02:00
Родитель a07c10bd7b
Коммит 80a3b3ed70
13 изменённых файлов: 76 добавлений и 118 удалений

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

@ -8,14 +8,8 @@ const {Cc, Ci, Cu} = require("chrome");
const Services = require("Services");
const defer = require("devtools/shared/defer");
function l10n(name) {
const bundle = Services.strings.createBundle("chrome://devtools/locale/toolbox.properties");
try {
return bundle.GetStringFromName(name);
} catch (e) {
throw new Error("Failed loading l10n string: " + name);
}
}
const {LocalizationHelper} = require("devtools/shared/l10n");
const L10N = new LocalizationHelper("devtools/locale/toolbox.properties");
function handleThreadState(toolbox, event, packet) {
// Suppress interrupted events by default because the thread is
@ -78,7 +72,7 @@ function attachThread(toolbox) {
if (res.error === "wrongOrder") {
const box = toolbox.getNotificationBox();
box.appendNotification(
l10n("toolbox.resumeOrderWarning"),
L10N.getStr("toolbox.resumeOrderWarning"),
"wrong-resume-order",
"",
box.PRIORITY_WARNING_HIGH

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

@ -12,8 +12,8 @@
* - devtools/client/definitions for tool-specifics entries
*/
const Services = require("Services");
const MenuStrings = Services.strings.createBundle("chrome://devtools/locale/menus.properties");
const {LocalizationHelper} = require("devtools/shared/l10n");
const MENUS_L10N = new LocalizationHelper("devtools/locale/menus.properties");
loader.lazyRequireGetter(this, "gDevTools", "devtools/client/framework/devtools", true);
loader.lazyRequireGetter(this, "gDevToolsBrowser", "devtools/client/framework/devtools-browser", true);
@ -23,7 +23,7 @@ loader.lazyRequireGetter(this, "gDevToolsBrowser", "devtools/client/framework/de
const FragmentsCache = new Map();
function l10n(key) {
return MenuStrings.GetStringFromName(key);
return MENUS_L10N.getStr(key);
}
/**

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

@ -8,21 +8,18 @@
var Cu = Components.utils;
var {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
var {XPCOMUtils} = require("resource://gre/modules/XPCOMUtils.jsm");
var Services = require("Services");
var {gDevTools} = require("devtools/client/framework/devtools");
var {TargetFactory} = require("devtools/client/framework/target");
var {Toolbox} = require("devtools/client/framework/toolbox");
var {DebuggerClient} = require("devtools/shared/client/main");
var {Task} = require("devtools/shared/task");
var {LocalizationHelper} = require("devtools/shared/l10n");
var L10N = new LocalizationHelper("devtools/locale/connection-screen.properties");
var gClient;
var gConnectionTimeout;
XPCOMUtils.defineLazyGetter(window, "l10n", function () {
return Services.strings.createBundle("chrome://devtools/locale/connection-screen.properties");
});
/**
* Once DOM is ready, we prefil the host/port inputs with
* pref-stored values.
@ -134,7 +131,7 @@ var onConnectionReady = Task.async(function* ([aType, aTraits]) {
openToolbox(globals, true, "webconsole", false);
}
};
a.title = a.textContent = window.l10n.GetStringFromName("mainProcess");
a.title = a.textContent = L10N.getStr("mainProcess");
a.className = "remote-process";
a.href = "#";
gParent.appendChild(a);

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

@ -30,7 +30,8 @@ loader.lazyRequireGetter(this, "BrowserMenus", "devtools/client/framework/browse
loader.lazyImporter(this, "CustomizableUI", "resource:///modules/CustomizableUI.jsm");
loader.lazyImporter(this, "AppConstants", "resource://gre/modules/AppConstants.jsm");
const bundle = Services.strings.createBundle("chrome://devtools/locale/toolbox.properties");
const {LocalizationHelper} = require("devtools/shared/l10n");
const L10N = new LocalizationHelper("devtools/locale/toolbox.properties");
const TABS_OPEN_PEAK_HISTOGRAM = "DEVTOOLS_TABS_OPEN_PEAK_LINEAR";
const TABS_OPEN_AVG_HISTOGRAM = "DEVTOOLS_TABS_OPEN_AVERAGE_LINEAR";
@ -244,7 +245,7 @@ var gDevToolsBrowser = exports.gDevToolsBrowser = {
// Do nothing if there is only one process, the parent process.
let contentProcesses = response.processes.filter(p => (!p.parent));
if (contentProcesses.length < 1) {
let msg = bundle.GetStringFromName("toolbox.noContentProcess.message");
let msg = L10N.getStr("toolbox.noContentProcess.message");
Services.prompt.alert(null, "", msg);
deferred.reject("No content processes available.");
return;

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

@ -4,12 +4,14 @@
"use strict";
var {XPCOMUtils} = require("resource://gre/modules/XPCOMUtils.jsm");
var Services = require("Services");
var {Task} = require("devtools/shared/task");
var EventEmitter = require("devtools/shared/event-emitter");
var Telemetry = require("devtools/client/shared/telemetry");
const {LocalizationHelper} = require("devtools/shared/l10n");
const L10N = new LocalizationHelper("devtools/locale/toolbox.properties");
const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
/**
@ -130,7 +132,8 @@ ToolSidebar.prototype = {
this._allTabsBtn.setAttribute("top", "0");
this._allTabsBtn.setAttribute("width", "15");
this._allTabsBtn.setAttribute("type", "menu");
this._allTabsBtn.setAttribute("tooltiptext", l10n("sidebar.showAllTabs.tooltip"));
this._allTabsBtn.setAttribute("tooltiptext",
L10N.getStr("sidebar.showAllTabs.tooltip"));
this._allTabsBtn.setAttribute("hidden", "true");
allTabsContainer.appendChild(this._allTabsBtn);
@ -587,19 +590,3 @@ ToolSidebar.prototype = {
this._toolPanel = null;
})
};
XPCOMUtils.defineLazyGetter(this, "l10n", function () {
let bundle = Services.strings.createBundle("chrome://devtools/locale/toolbox.properties");
let l10n = function (aName, ...aArgs) {
try {
if (aArgs.length == 0) {
return bundle.GetStringFromName(aName);
} else {
return bundle.formatStringFromName(aName, aArgs, aArgs.length);
}
} catch (ex) {
console.log("Error reading '" + aName + "'");
}
};
return l10n;
});

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

@ -10,8 +10,9 @@
const URL = "data:text/html;charset=utf8,test page";
var {Toolbox} = require("devtools/client/framework/toolbox");
var strings = Services.strings.createBundle(
"chrome://devtools/locale/toolbox.properties");
const {LocalizationHelper} = require("devtools/shared/l10n");
const L10N = new LocalizationHelper("devtools/locale/toolbox.properties");
function getZoomValue() {
return parseFloat(Services.prefs.getCharPref("devtools.toolbox.zoomValue"));
@ -39,7 +40,7 @@ add_task(function* () {
});
function zoomWithKey(toolbox, key) {
let shortcut = strings.GetStringFromName(key);
let shortcut = L10N.getStr(key);
if (!shortcut) {
info("Key was empty, skipping zoomWithKey");
return;

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

@ -11,8 +11,9 @@
const URL = "data:text/html;charset=utf8,test page for toolbox switching";
var {Toolbox} = require("devtools/client/framework/toolbox");
var strings = Services.strings.createBundle(
"chrome://devtools/locale/toolbox.properties");
const {LocalizationHelper} = require("devtools/shared/l10n");
const L10N = new LocalizationHelper("devtools/locale/toolbox.properties");
add_task(function* () {
info("Create a test tab and open the toolbox");
@ -20,7 +21,7 @@ add_task(function* () {
let target = TargetFactory.forTab(tab);
let toolbox = yield gDevTools.showToolbox(target, "webconsole");
let shortcut = strings.GetStringFromName("toolbox.toggleHost.key");
let shortcut = L10N.getStr("toolbox.toggleHost.key");
let {SIDE, BOTTOM, WINDOW} = Toolbox.HostType;
checkHostType(toolbox, BOTTOM, SIDE);

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

@ -10,8 +10,8 @@
// and toggles appropriate things in the toolbox.
var doc = null, toolbox = null, panelWin = null, modifiedPrefs = [];
var strings = Services.strings.createBundle(
"chrome://devtools/locale/toolbox.properties");
const {LocalizationHelper} = require("devtools/shared/l10n");
const L10N = new LocalizationHelper("devtools/locale/toolbox.properties");
add_task(function* () {
const URL = "data:text/html;charset=utf8,test for dynamically registering " +
@ -60,18 +60,18 @@ function* testOptionsShortcut() {
yield toolbox.selectTool("webconsole");
is(toolbox.currentToolId, "webconsole", "webconsole is selected");
synthesizeKeyShortcut(strings.GetStringFromName("toolbox.options.key"));
synthesizeKeyShortcut(L10N.getStr("toolbox.options.key"));
is(toolbox.currentToolId, "options", "Toolbox selected via shortcut key (1)");
synthesizeKeyShortcut(strings.GetStringFromName("toolbox.options.key"));
synthesizeKeyShortcut(L10N.getStr("toolbox.options.key"));
is(toolbox.currentToolId, "webconsole", "webconsole is selected (1)");
yield toolbox.selectTool("webconsole");
is(toolbox.currentToolId, "webconsole", "webconsole is selected");
synthesizeKeyShortcut(strings.GetStringFromName("toolbox.help.key"));
synthesizeKeyShortcut(L10N.getStr("toolbox.help.key"));
is(toolbox.currentToolId, "options", "Toolbox selected via shortcut key (2)");
synthesizeKeyShortcut(strings.GetStringFromName("toolbox.options.key"));
synthesizeKeyShortcut(L10N.getStr("toolbox.options.key"));
is(toolbox.currentToolId, "webconsole", "webconsole is reselected (2)");
synthesizeKeyShortcut(strings.GetStringFromName("toolbox.help.key"));
synthesizeKeyShortcut(L10N.getStr("toolbox.help.key"));
is(toolbox.currentToolId, "options", "Toolbox selected via shortcut key (2)");
}

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

@ -3,11 +3,14 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
requestLongerTimeout(2);
var {Toolbox} = require("devtools/client/framework/toolbox");
var strings = Services.strings.createBundle(
"chrome://devtools/locale/toolbox.properties");
const {LocalizationHelper} = require("devtools/shared/l10n");
const L10N = new LocalizationHelper("devtools/locale/toolbox.properties");
add_task(function* () {
let tab = yield addTab("about:blank");
@ -18,10 +21,9 @@ add_task(function* () {
.filter(def => def.isTargetSupported(target))
.map(def => def.id);
let toolbox = yield gDevTools.showToolbox(target, toolIDs[0],
Toolbox.HostType.BOTTOM);
let nextShortcut = strings.GetStringFromName("toolbox.nextTool.key")
let prevShortcut = strings.GetStringFromName("toolbox.previousTool.key")
let toolbox = yield gDevTools.showToolbox(target, toolIDs[0], Toolbox.HostType.BOTTOM);
let nextShortcut = L10N.getStr("toolbox.nextTool.key");
let prevShortcut = L10N.getStr("toolbox.previousTool.key");
// Iterate over all tools, starting from options to netmonitor, in normal
// order.

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

@ -10,8 +10,9 @@ const TEST_URL = "data:text/html;charset=utf-8," +
"<body><h1>Testing reload from devtools</h1></body></html>";
var {Toolbox} = require("devtools/client/framework/toolbox");
var strings = Services.strings.createBundle(
"chrome://devtools/locale/toolbox.properties");
const {LocalizationHelper} = require("devtools/shared/l10n");
const L10N = new LocalizationHelper("devtools/locale/toolbox.properties");
var target, toolbox, description, reloadsSent, toolIDs;
@ -83,7 +84,7 @@ function testReload(shortcut, docked, toolID, callback) {
description = docked + " devtools with tool " + toolID + ", shortcut #" + shortcut;
info("Testing reload in " + description);
synthesizeKeyShortcut(strings.GetStringFromName(shortcut), toolbox.win);
synthesizeKeyShortcut(L10N.getStr(shortcut), toolbox.win);
reloadsSent++;
}

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

@ -3,13 +3,12 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
var modifiers = {
accelKey: true
};
"use strict";
var toolbox;
var strings = Services.strings.createBundle(
"chrome://devtools/locale/toolbox.properties");
const {LocalizationHelper} = require("devtools/shared/l10n");
const L10N = new LocalizationHelper("devtools/locale/toolbox.properties");
function test() {
addTab("about:blank").then(openToolbox);
@ -48,7 +47,7 @@ function testZoomLevel(type, times, expected) {
function sendZoomKey(shortcut, times) {
for (let i = 0; i < times; i++) {
synthesizeKeyShortcut(strings.GetStringFromName(shortcut));
synthesizeKeyShortcut(L10N.getStr(shortcut));
}
}
@ -61,7 +60,7 @@ function tidyUp() {
toolbox.destroy().then(function () {
gBrowser.removeCurrentTab();
toolbox = modifiers = null;
toolbox = null;
finish();
});
}

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

@ -8,26 +8,13 @@
const Services = require("Services");
const defer = require("devtools/shared/defer");
const {XPCOMUtils} = require("resource://gre/modules/XPCOMUtils.jsm");
const {Task} = require("devtools/shared/task");
const {gDevTools} = require("devtools/client/framework/devtools");
exports.OptionsPanel = OptionsPanel;
const {LocalizationHelper} = require("devtools/shared/l10n");
const L10N = new LocalizationHelper("devtools/locale/toolbox.properties");
XPCOMUtils.defineLazyGetter(this, "l10n", function () {
let bundle = Services.strings.createBundle("chrome://devtools/locale/toolbox.properties");
let l10n = function (name, ...aArgs) {
try {
if (aArgs.length == 0) {
return bundle.GetStringFromName(name);
}
return bundle.formatStringFromName(name, aArgs, aArgs.length);
} catch (ex) {
console.log("Error reading '" + name + "'");
}
};
return l10n;
});
exports.OptionsPanel = OptionsPanel;
function GetPref(name) {
let type = Services.prefs.getPrefType(name);
@ -220,8 +207,8 @@ OptionsPanel.prototype = {
checkboxSpanLabel.textContent = tool.label;
} else {
atleastOneToolNotSupported = true;
checkboxSpanLabel.textContent = l10n(
"options.toolNotSupportedMarker", tool.label);
checkboxSpanLabel.textContent =
L10N.getFormatStr("options.toolNotSupportedMarker", tool.label);
checkboxInput.setAttribute("data-unsupported", "true");
checkboxInput.setAttribute("disabled", "true");
}

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

@ -32,21 +32,9 @@ const { KeyCodes } = require("devtools/client/shared/keycodes");
const { BrowserLoader } =
Cu.import("resource://devtools/client/shared/browser-loader.js", {});
loader.lazyGetter(this, "toolboxStrings", () => {
const properties = "chrome://devtools/locale/toolbox.properties";
const bundle = Services.strings.createBundle(properties);
return (name, ...args) => {
try {
if (!args.length) {
return bundle.GetStringFromName(name);
}
return bundle.formatStringFromName(name, args, args.length);
} catch (ex) {
console.log("Error reading '" + name + "'");
return null;
}
};
});
const {LocalizationHelper} = require("devtools/shared/l10n");
const L10N = new LocalizationHelper("devtools/locale/toolbox.properties");
loader.lazyRequireGetter(this, "CommandUtils",
"devtools/client/shared/developer-toolbar", true);
loader.lazyRequireGetter(this, "getHighlighterUtils",
@ -386,7 +374,7 @@ Toolbox.prototype = {
useOnlyShared: true
}).require;
iframe.setAttribute("aria-label", toolboxStrings("toolbox.label"));
iframe.setAttribute("aria-label", L10N.getStr("toolbox.label"));
let domHelper = new DOMHelpers(iframe.contentWindow);
domHelper.onceDOMReady(() => {
domReady.resolve();
@ -545,8 +533,8 @@ Toolbox.prototype = {
// Prevent the opening of bookmarks window on toolbox.options.key
event.preventDefault();
};
shortcuts.on(toolboxStrings("toolbox.options.key"), selectOptions);
shortcuts.on(toolboxStrings("toolbox.help.key"), selectOptions);
shortcuts.on(L10N.getStr("toolbox.options.key"), selectOptions);
shortcuts.on(L10N.getStr("toolbox.help.key"), selectOptions);
},
_splitConsoleOnKeypress: function (e) {
@ -591,7 +579,7 @@ Toolbox.prototype = {
["forceReload", true],
["forceReload2", true]
].forEach(([id, force]) => {
let key = toolboxStrings("toolbox." + id + ".key");
let key = L10N.getStr("toolbox." + id + ".key");
shortcuts.on(key, (name, event) => {
this.reloadTarget(force);
@ -602,13 +590,13 @@ Toolbox.prototype = {
},
_addHostListeners: function (shortcuts) {
shortcuts.on(toolboxStrings("toolbox.nextTool.key"),
shortcuts.on(L10N.getStr("toolbox.nextTool.key"),
this.selectNextTool.bind(this));
shortcuts.on(toolboxStrings("toolbox.previousTool.key"),
shortcuts.on(L10N.getStr("toolbox.previousTool.key"),
this.selectPreviousTool.bind(this));
shortcuts.on(toolboxStrings("toolbox.minimize.key"),
shortcuts.on(L10N.getStr("toolbox.minimize.key"),
this._toggleMinimizeMode.bind(this));
shortcuts.on(toolboxStrings("toolbox.toggleHost.key"),
shortcuts.on(L10N.getStr("toolbox.toggleHost.key"),
(name, event) => {
this.switchToPreviousHost();
event.preventDefault();
@ -703,7 +691,7 @@ Toolbox.prototype = {
let key = doc.createElement("key");
key.id = "key_browserconsole";
key.setAttribute("key", toolboxStrings("browserConsoleCmd.commandkey"));
key.setAttribute("key", L10N.getStr("browserConsoleCmd.commandkey"));
key.setAttribute("modifiers", "accel,shift");
// needed. See bug 371900
key.setAttribute("oncommand", "void(0)");
@ -807,7 +795,7 @@ Toolbox.prototype = {
let button = this.doc.createElementNS(HTML_NS, "button");
button.id = "toolbox-dock-" + position;
button.className = "toolbox-dock-button devtools-button";
button.setAttribute("title", toolboxStrings("toolboxDockButtons." +
button.setAttribute("title", L10N.getStr("toolboxDockButtons." +
position + ".tooltip"));
button.addEventListener("click", () => {
this.switchHost(position);
@ -818,7 +806,7 @@ Toolbox.prototype = {
},
_getMinimizeButtonShortcutTooltip: function () {
let str = toolboxStrings("toolbox.minimize.key");
let str = L10N.getStr("toolbox.minimize.key");
let key = KeyShortcuts.parseElectronKey(this.win, str);
return "(" + KeyShortcuts.stringify(key) + ")";
},
@ -828,7 +816,7 @@ Toolbox.prototype = {
btn.className = "minimized";
btn.setAttribute("title",
toolboxStrings("toolboxDockButtons.bottom.maximize") + " " +
L10N.getStr("toolboxDockButtons.bottom.maximize") + " " +
this._getMinimizeButtonShortcutTooltip());
},
@ -837,7 +825,7 @@ Toolbox.prototype = {
btn.className = "maximized";
btn.setAttribute("title",
toolboxStrings("toolboxDockButtons.bottom.minimize") + " " +
L10N.getStr("toolboxDockButtons.bottom.minimize") + " " +
this._getMinimizeButtonShortcutTooltip());
},
@ -985,7 +973,7 @@ Toolbox.prototype = {
this._pickerButton = this.doc.createElementNS(HTML_NS, "button");
this._pickerButton.id = "command-button-pick";
this._pickerButton.className = "command-button command-button-invertable devtools-button";
this._pickerButton.setAttribute("title", toolboxStrings("pickButton.tooltip"));
this._pickerButton.setAttribute("title", L10N.getStr("pickButton.tooltip"));
this._pickerButton.setAttribute("hidden", "true");
let container = this.doc.querySelector("#toolbox-picker-container");
@ -1577,10 +1565,10 @@ Toolbox.prototype = {
_refreshHostTitle: function () {
let title;
if (this.target.name && this.target.name != this.target.url) {
title = toolboxStrings("toolbox.titleTemplate2",
this.target.name, this.target.url);
title = L10N.getFormatStr("toolbox.titleTemplate2", this.target.name,
this.target.url);
} else {
title = toolboxStrings("toolbox.titleTemplate1", this.target.url);
title = L10N.getFormatStr("toolbox.titleTemplate1", this.target.url);
}
this._host.setTitle(title);
},
@ -1588,7 +1576,7 @@ Toolbox.prototype = {
// Returns an instance of the preference actor
get _preferenceFront() {
return this.target.root.then(rootForm => {
return new getPreferenceFront(this.target.client, rootForm);
return new L10N.getFormatStr(this.target.client, rootForm);
});
},