Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

internationalized mix-master.

  • Loading branch information...
commit c762b9edd9c0d08df6ea87f7e9f967afb9a90940 1 parent 88873b3
@toolness toolness authored
Showing with 38 additions and 21 deletions.
  1. +17 −0 src/locale/en-US.js
  2. +20 −21 src/mix-master.js
  3. +1 −0  test/unit/mix-master.js
View
17 src/locale/en-US.js
@@ -18,3 +18,20 @@ jQuery.localization.extend("en-US", "hack-recording-playback", {
"success": 'Hack rebusted!',
"failure": 'Hack rebusting failed. Perhaps the page changed since the hack was first busted?'
});
+
+jQuery.localization.extend("en-US", "command-manager", {
+ "executed": "Busted",
+ "undid": 'Unbusted',
+ "redid": 'Rebusted',
+ "cannot-undo-html": '<span>Nothing left to undo!</span>',
+ "cannot-redo-html": '<span>Nothing left to redo!</span>'
+});
+
+jQuery.localization.extend("en-US", "mix-master", {
+ "too-big-to-change": "Changing that would be a bad idea.",
+ "too-big-to-remix-html": "<div>That <code>&lt;${tagName}&gt;</code> element is too big for me to remix. Try selecting a smaller one!</div>",
+ "deletion": "deletion",
+ "replacement": "replacement",
+ "compose-a-replacement": "Compose A Replacement",
+ "replacement-instructions-html": "<span>When you're done composing your replacement HTML, press the <strong>Ok</strong> button.</span>"
+});
View
41 src/mix-master.js
@@ -4,10 +4,11 @@
var $ = jQuery;
var GLOBAL_RECORDING_VAR = 'webxrayRecording';
- function CommandManager(hud, focused) {
+ function CommandManager(hud, focused, locale) {
var undoStack = [];
var redoStack = [];
var transitionEffects = TransitionEffectManager();
+ var l10n = locale.scope('command-manager');
function updateStatus(verb, command) {
var span = $('<span></span>');
@@ -37,21 +38,21 @@
redoStack.splice(0);
transitionEffects.observe(command);
command.execute();
- updateStatus('Busted', command);
+ updateStatus(l10n('executed'), command);
},
undo: function() {
if (undoStack.length) {
focused.unfocus();
- updateStatus('Unbusted', internalUndo());
+ updateStatus(l10n('undid'), internalUndo());
} else
- $(hud.overlay).html('<span>Nothing left to undo!</span>');
+ $(hud.overlay).html(l10n('cannot-undo-html'));
},
redo: function() {
if (redoStack.length) {
focused.unfocus();
- updateStatus('Rebusted', internalRedo());
+ updateStatus(l10n('redid'), internalRedo());
} else
- $(hud.overlay).html('<span>Nothing left to redo!</span>');
+ $(hud.overlay).html(l10n('cannot-redo-html'));
},
getRecording: function() {
var recording = [];
@@ -210,8 +211,10 @@
function MixMaster(options) {
var focused = options.focusedOverlay;
- var commandManager = CommandManager(options.hud, focused);
-
+ var locale = options.locale || jQuery.locale;
+ var commandManager = CommandManager(options.hud, focused, locale);
+ var l10n = locale.scope('mix-master');
+
var self = {
transitionEffects: commandManager.transitionEffects,
undo: function() { commandManager.undo(); },
@@ -276,7 +279,7 @@
var elementToDelete = focused.getPrimaryElement();
if (elementToDelete) {
if ($(elementToDelete).is('html, body')) {
- var msg = "Deleting that would be a bad idea."
+ var msg = l10n('too-big-to-change');
jQuery.transparentMessage($('<div></div>').text(msg));
return;
}
@@ -285,7 +288,7 @@
// since it allows us to place a "bookmark" in the DOM
// that can easily be undone if the user wishes.
var placeholder = $('<span class="webxray-deleted"></span>');
- commandManager.run(ReplaceWithCmd('deletion', elementToDelete,
+ commandManager.run(ReplaceWithCmd(l10n('deletion'), elementToDelete,
placeholder));
}
},
@@ -301,7 +304,7 @@
replaceElement: function(elementToReplace, html) {
var newContent = self.htmlToJQuery(html);
commandManager.transitionEffects.disableDuring(function() {
- commandManager.run(ReplaceWithCmd('replacement',
+ commandManager.run(ReplaceWithCmd(l10n('replacement'),
elementToReplace,
newContent));
});
@@ -360,7 +363,7 @@
var focusedHTML = $(focusedElement).outerHtml();
if ($(focusedElement).is('html, body')) {
- var msg = "Changing that would be a bad idea."
+ var msg = l10n("too-big-to-change");
jQuery.transparentMessage($('<div></div>').text(msg));
return;
}
@@ -368,11 +371,9 @@
if (focusedHTML.length == 0 ||
focusedHTML.length > MAX_HTML_LENGTH) {
var tagName = focusedElement.nodeName.toLowerCase();
- var msg = $("<div>That " +
- "<code>&lt;" + tagName + "&gt;</code> element " +
- "is too big for me to remix. Try selecting " +
- "a smaller one!</div>");
- jQuery.transparentMessage(msg);
+ var msg = l10n("too-big-to-remix-html").replace("${tagName}",
+ tagName);
+ jQuery.transparentMessage($(msg));
return;
}
@@ -408,10 +409,8 @@
element: focusedElement,
onLoad: function(dialog) {
dialog.iframe.get(0).contentWindow.postMessage(JSON.stringify({
- title: "Compose A Replacement",
- instructions: "<span>When you're done composing your " +
- "replacement HTML, press the " +
- "<strong>Ok</strong> button.",
+ title: l10n("compose-a-replacement"),
+ instructions: l10n("replacement-instructions-html"),
startHTML: startHTML,
baseURI: document.location.href
}), "*");
View
1  test/unit/mix-master.js
@@ -11,6 +11,7 @@ test("jQuery.mixMaster()", function() {
focused.set(domNode);
var mixMaster = $.mixMaster({
+ locale: jQuery.localization.createLocale(["en-US"]),
hud: hud,
focusedOverlay: focused
});
Please sign in to comment.
Something went wrong with that request. Please try again.