Skip to content

Instantly share code, notes, and snippets.

Created March 6, 2010 08:31
Show Gist options
  • Save anonymous/dc8ee85d6b763c30ac58 to your computer and use it in GitHub Desktop.
Save anonymous/dc8ee85d6b763c30ac58 to your computer and use it in GitHub Desktop.
// import libraries
jetpack.future.import("menu");
jetpack.future.import("selection");
// create a new menu item
jetpack.menu.context.page.add({
label: "TranslateIt!",
command: function() { TranslateIt(); }
});
// do translate
function TranslateIt() {
var url = 'http://ajax.googleapis.com/ajax/services/language/translate?v=1.0'
+ '&langpair=|zh-TW'
+ '&q=' + escape(jetpack.selection.text);
$.getJSON(url, function(result) {
if (result.responseStatus == 200) {
jetpack.notifications.show(result.responseData.translatedText);
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment