mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 11:55:49 +00:00
Bug 868433: make widgets use localization strings. r=mconley
This commit is contained in:
parent
308c0cb0e4
commit
571f89e221
@ -15,6 +15,10 @@ XPCOMUtils.defineLazyModuleGetter(this, "CustomizableWidgets",
|
||||
"resource:///modules/CustomizableWidgets.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "DeferredTask",
|
||||
"resource://gre/modules/DeferredTask.jsm");
|
||||
XPCOMUtils.defineLazyGetter(this, "gWidgetsBundle", function() {
|
||||
const kUrl = "chrome://browser/locale/customizableui/customizableWidgets.properties";
|
||||
return Services.strings.createBundle(kUrl);
|
||||
});
|
||||
|
||||
const kNSXUL = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
||||
|
||||
@ -727,11 +731,12 @@ let CustomizableUIInternal = {
|
||||
node.setAttribute("disabled", true);
|
||||
}
|
||||
node.setAttribute("removable", aWidget.removable);
|
||||
node.setAttribute("label", aWidget.name);
|
||||
node.setAttribute("tooltiptext", aWidget.description);
|
||||
node.setAttribute("label", this.getLocalizedProperty(aWidget, "label"));
|
||||
node.setAttribute("tooltiptext", this.getLocalizedProperty(aWidget, "tooltiptext"));
|
||||
//XXXunf Need to hook this up to a <key> element or something.
|
||||
if (aWidget.shortcut) {
|
||||
node.setAttribute("acceltext", aWidget.shortcut);
|
||||
let shortcut = this.getLocalizedProperty(aWidget, "shortcut");
|
||||
if (shortcut) {
|
||||
node.setAttribute("acceltext", shortcut);
|
||||
}
|
||||
node.setAttribute("class", "toolbarbutton-1 chromeclass-toolbar-additional");
|
||||
|
||||
@ -769,6 +774,30 @@ let CustomizableUIInternal = {
|
||||
return node;
|
||||
},
|
||||
|
||||
getLocalizedProperty: function(aWidget, aProp, aFormatArgs, aDef) {
|
||||
if (typeof aWidget == "string") {
|
||||
aWidget = gPalette.get(aWidget);
|
||||
}
|
||||
if (!aWidget) {
|
||||
throw new Error("getLocalizedProperty was passed a non-widget to work with.");
|
||||
}
|
||||
if (typeof aWidget[aProp] == "string") {
|
||||
return aWidget[aProp];
|
||||
}
|
||||
let def = aDef || "";
|
||||
let name = aWidget.id + "." + aProp;
|
||||
try {
|
||||
if (Array.isArray(aFormatArgs) && aFormatArgs.length) {
|
||||
return gWidgetsBundle.formatStringFromName(name, aFormatArgs,
|
||||
aFormatArgs.length) || def;
|
||||
}
|
||||
return gWidgetsBundle.GetStringFromName(name) || def;
|
||||
} catch(ex) {
|
||||
ERROR("Could not localize property '" + name + "'.");
|
||||
}
|
||||
return def;
|
||||
},
|
||||
|
||||
handleWidgetClick: function(aWidget, aNode, aEvent) {
|
||||
LOG("handleWidgetClick");
|
||||
|
||||
@ -1257,15 +1286,17 @@ let CustomizableUIInternal = {
|
||||
return null;
|
||||
}
|
||||
|
||||
const kReqStringProps = ["id", "name"];
|
||||
const kReqStringProps = ["id"];
|
||||
for (let prop of kReqStringProps) {
|
||||
if (typeof aData[prop] != "string") {
|
||||
ERROR("Missing required property '" + prop + "' in normalizeWidget: "
|
||||
+ aData.id);
|
||||
return null;
|
||||
}
|
||||
widget[prop] = aData[prop];
|
||||
}
|
||||
|
||||
const kOptStringProps = ["description", "shortcut"];
|
||||
const kOptStringProps = ["name", "tooltiptext", "shortcut"];
|
||||
for (let prop of kOptStringProps) {
|
||||
if (typeof aData[prop] == "string") {
|
||||
widget[prop] = aData[prop];
|
||||
@ -1687,6 +1718,10 @@ this.CustomizableUI = {
|
||||
},
|
||||
get inDefaultState() {
|
||||
return CustomizableUIInternal.inDefaultState;
|
||||
},
|
||||
getLocalizedProperty: function(aWidget, aProp, aFormatArgs, aDef) {
|
||||
return CustomizableUIInternal.getLocalizedProperty(aWidget, aProp,
|
||||
aFormatArgs, aDef);
|
||||
}
|
||||
};
|
||||
Object.freeze(this.CustomizableUI);
|
||||
|
@ -25,6 +25,8 @@ function setAttributes(aNode, aAttrs) {
|
||||
if (aNode.hasAttribute(name))
|
||||
aNode.removeAttribute(name);
|
||||
} else {
|
||||
if (name == "label" || name == "tooltiptext")
|
||||
value = CustomizableUI.getLocalizedProperty(aAttrs, name);
|
||||
aNode.setAttribute(name, value);
|
||||
}
|
||||
}
|
||||
@ -34,8 +36,6 @@ const CustomizableWidgets = [{
|
||||
id: "history-panelmenu",
|
||||
type: "view",
|
||||
viewId: "PanelUI-history",
|
||||
name: "History...",
|
||||
description: "History",
|
||||
removable: true,
|
||||
defaultArea: CustomizableUI.AREA_PANEL,
|
||||
allowedAreas: [CustomizableUI.AREA_PANEL, CustomizableUI.AREA_NAVBAR],
|
||||
@ -104,8 +104,6 @@ const CustomizableWidgets = [{
|
||||
}
|
||||
}, {
|
||||
id: "privatebrowsing-button",
|
||||
name: "Private Browsing\u2026",
|
||||
description: "Open a new Private Browsing window",
|
||||
removable: true,
|
||||
defaultArea: CustomizableUI.AREA_PANEL,
|
||||
allowedAreas: [CustomizableUI.AREA_PANEL],
|
||||
@ -124,9 +122,6 @@ const CustomizableWidgets = [{
|
||||
}
|
||||
}, {
|
||||
id: "save-page-button",
|
||||
name: "Save Page",
|
||||
shortcut: "Ctrl+S",
|
||||
description: "Save this page",
|
||||
removable: true,
|
||||
defaultArea: CustomizableUI.AREA_PANEL,
|
||||
allowedAreas: [CustomizableUI.AREA_PANEL],
|
||||
@ -145,9 +140,6 @@ const CustomizableWidgets = [{
|
||||
}
|
||||
}, {
|
||||
id: "find-button",
|
||||
name: "Find",
|
||||
shortcut: "Ctrl+F",
|
||||
description: "Find in this page",
|
||||
removable: true,
|
||||
defaultArea: CustomizableUI.AREA_PANEL,
|
||||
allowedAreas: [CustomizableUI.AREA_PANEL],
|
||||
@ -166,9 +158,6 @@ const CustomizableWidgets = [{
|
||||
}
|
||||
}, {
|
||||
id: "open-file-button",
|
||||
name: "Open File",
|
||||
shortcut: "Ctrl+O",
|
||||
description: "Open file",
|
||||
removable: true,
|
||||
defaultArea: CustomizableUI.AREA_PANEL,
|
||||
allowedAreas: [CustomizableUI.AREA_PANEL],
|
||||
@ -187,9 +176,6 @@ const CustomizableWidgets = [{
|
||||
}
|
||||
}, {
|
||||
id: "developer-button",
|
||||
name: "Developer",
|
||||
shortcut: "Shift+F11",
|
||||
description: "Toggle Developer Tools",
|
||||
removable: true,
|
||||
defaultArea: CustomizableUI.AREA_PANEL,
|
||||
allowedAreas: [CustomizableUI.AREA_PANEL],
|
||||
@ -208,9 +194,6 @@ const CustomizableWidgets = [{
|
||||
}
|
||||
}, {
|
||||
id: "add-ons-button",
|
||||
name: "Add-ons",
|
||||
shortcut: "Ctrl+Shift+A",
|
||||
description: "Add-ons Manager",
|
||||
removable: true,
|
||||
defaultArea: CustomizableUI.AREA_PANEL,
|
||||
allowedAreas: [CustomizableUI.AREA_PANEL],
|
||||
@ -229,9 +212,6 @@ const CustomizableWidgets = [{
|
||||
}
|
||||
}, {
|
||||
id: "preferences-button",
|
||||
name: "Preferences",
|
||||
shortcut: "Ctrl+Shift+O",
|
||||
description: "Preferences\u2026",
|
||||
removable: true,
|
||||
defaultArea: CustomizableUI.AREA_PANEL,
|
||||
allowedAreas: [CustomizableUI.AREA_PANEL],
|
||||
@ -250,7 +230,6 @@ const CustomizableWidgets = [{
|
||||
}
|
||||
}, {
|
||||
id: "zoom-controls",
|
||||
name: "Zoom Controls",
|
||||
type: "custom",
|
||||
removable: true,
|
||||
defaultArea: CustomizableUI.AREA_PANEL,
|
||||
@ -266,23 +245,23 @@ const CustomizableWidgets = [{
|
||||
command: "cmd_fullZoomReduce",
|
||||
flex: flex,
|
||||
class: cls,
|
||||
label: "Zoom out",
|
||||
tooltiptext: "Zoom out"
|
||||
label: true,
|
||||
tooltiptext: true
|
||||
}, {
|
||||
id: "zoom-reset-button",
|
||||
noautoclose: noautoclose,
|
||||
command: "cmd_fullZoomReset",
|
||||
flex: flex,
|
||||
class: cls,
|
||||
tooltiptext: "Reset Zoom"
|
||||
tooltiptext: true
|
||||
}, {
|
||||
id: "zoom-in-button",
|
||||
noautoclose: noautoclose,
|
||||
command: "cmd_fullZoomEnlarge",
|
||||
flex: flex,
|
||||
class: cls,
|
||||
label: "Zoom in",
|
||||
tooltiptext: "Zoom in"
|
||||
label: true,
|
||||
tooltiptext: true
|
||||
}];
|
||||
|
||||
let node = aDocument.createElementNS(kNSXUL, "toolbaritem");
|
||||
@ -302,8 +281,9 @@ const CustomizableWidgets = [{
|
||||
let zoomResetButton = node.childNodes[1];
|
||||
let window = aDocument.defaultView;
|
||||
function updateZoomResetButton() {
|
||||
zoomResetButton.setAttribute("label", window.gNavigatorBundle
|
||||
.getFormattedString("zoomReset.label", [Math.floor(window.ZoomManager.zoom * 100)]));
|
||||
zoomResetButton.setAttribute("label", CustomizableUI.getLocalizedProperty(
|
||||
buttons[1], "label", [Math.floor(window.ZoomManager.zoom * 100)]
|
||||
));
|
||||
};
|
||||
|
||||
// Register ourselves with the service so we know when the zoom prefs change.
|
||||
@ -375,7 +355,6 @@ const CustomizableWidgets = [{
|
||||
}
|
||||
}, {
|
||||
id: "edit-controls",
|
||||
name: "Edit Controls",
|
||||
type: "custom",
|
||||
removable: true,
|
||||
defaultArea: CustomizableUI.AREA_PANEL,
|
||||
@ -389,22 +368,22 @@ const CustomizableWidgets = [{
|
||||
command: "cmd_cut",
|
||||
flex: flex,
|
||||
class: cls,
|
||||
label: "Cut",
|
||||
tooltiptext: "Cut"
|
||||
label: true,
|
||||
tooltiptext: true
|
||||
}, {
|
||||
id: "copy-button",
|
||||
command: "cmd_copy",
|
||||
flex: flex,
|
||||
class: cls,
|
||||
label: "Copy",
|
||||
tooltiptext: "Copy"
|
||||
label: true,
|
||||
tooltiptext: true
|
||||
}, {
|
||||
id: "paste-button",
|
||||
command: "cmd_paste",
|
||||
flex: flex,
|
||||
class: cls,
|
||||
label: "Paste",
|
||||
tooltiptext: "Paste"
|
||||
label: true,
|
||||
tooltiptext: true
|
||||
}];
|
||||
|
||||
let node = aDocument.createElementNS(kNSXUL, "toolbaritem");
|
||||
|
@ -465,6 +465,3 @@ slowStartup.helpButton.label = Learn How to Speed It Up
|
||||
slowStartup.helpButton.accesskey = L
|
||||
slowStartup.disableNotificationButton.label = Don't Tell Me Again
|
||||
slowStartup.disableNotificationButton.accesskey = A
|
||||
|
||||
# LOCALIZATION NOTE(zoomReset.label): %S is the current zoom level.
|
||||
zoomReset.label = %S%%
|
||||
|
@ -0,0 +1,64 @@
|
||||
# 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/.
|
||||
|
||||
history-panelmenu.label = History
|
||||
# LOCALIZATION NOTE (history-panelmenu.tooltiptext): Use the unicode ellipsis char,
|
||||
# \u2026, or use "..." if \u2026 doesn't suit traditions in your locale.
|
||||
history-panelmenu.tooltiptext = History…
|
||||
|
||||
# LOCALIZATION NOTE (privatebrowsing-button.label): Use the unicode ellipsis char,
|
||||
# \u2026, or use "..." if \u2026 doesn't suit traditions in your locale.
|
||||
privatebrowsing-button.label = Private Browsing…
|
||||
privatebrowsing-button.tooltiptext = Open a new Private Browsing window
|
||||
|
||||
save-page-button.label = Save Page
|
||||
save-page-button.tooltiptext = Save this page
|
||||
save-page-button.shortcut = Ctrl+S
|
||||
|
||||
find-button.label = Find
|
||||
find-button.tooltiptext = Find in this page
|
||||
find-button.shortcut = Ctrl+F
|
||||
|
||||
open-file-button.label = Open File
|
||||
open-file-button.tooltiptext = Open file
|
||||
open-file-button.shortcut = Ctrl+O
|
||||
|
||||
developer-button.label = Developer
|
||||
developer-button.tooltiptext = Toggle Developer Tools
|
||||
developer-button.shortcut = Shift+F11
|
||||
|
||||
add-ons-button.label = Add-ons
|
||||
add-ons-button.tooltiptext = Add-ons Manager
|
||||
add-ons-button.shortcut = Ctrl+Shift+A
|
||||
|
||||
preferences-button.label = Preferences
|
||||
# LOCALIZATION NOTE (preferences-button.tooltiptext): Use the unicode ellipsis char,
|
||||
# \u2026, or use "..." if \u2026 doesn't suit traditions in your locale.
|
||||
preferences-button.tooltiptext = Preferences…
|
||||
preferences-button.shortcut = Ctrl+Shift+O
|
||||
|
||||
zoom-controls.label = Zoom Controls
|
||||
zoom-controls.tooltiptext = Zoom Controls
|
||||
|
||||
zoom-out-button.label = Zoom out
|
||||
zoom-out-button.tooltiptext = Zoom out
|
||||
|
||||
# LOCALIZATION NOTE(zoom-reset-button.label): %S is the current zoom level.
|
||||
zoom-reset-button.label = %S%%
|
||||
zoom-reset-button.tooltiptext = Reset zoom level
|
||||
|
||||
zoom-in-button.label = Zoom in
|
||||
zoom-in-button.tooltiptext = Zoom in
|
||||
|
||||
edit-controls.label = Edit Controls
|
||||
edit-controls.tooltiptext = Edit Controls
|
||||
|
||||
cut-button.label = Cut
|
||||
cut-button.tooltiptext = Cut
|
||||
|
||||
copy-button.label = Copy
|
||||
copy-button.tooltiptext = Copy
|
||||
|
||||
paste-button.label = Paste
|
||||
paste-button.tooltiptext = Paste
|
@ -22,6 +22,7 @@
|
||||
locale/browser/browser.dtd (%chrome/browser/browser.dtd)
|
||||
locale/browser/baseMenuOverlay.dtd (%chrome/browser/baseMenuOverlay.dtd)
|
||||
locale/browser/browser.properties (%chrome/browser/browser.properties)
|
||||
locale/browser/customizableui/customizableWidgets.properties (%chrome/browser/customizableui/customizableWidgets.properties)
|
||||
locale/browser/devtools/appcacheutils.properties (%chrome/browser/devtools/appcacheutils.properties)
|
||||
locale/browser/devtools/debugger.dtd (%chrome/browser/devtools/debugger.dtd)
|
||||
locale/browser/devtools/debugger.properties (%chrome/browser/devtools/debugger.properties)
|
||||
|
Loading…
Reference in New Issue
Block a user