Skip to content

Instantly share code, notes, and snippets.

Created Mar 6, 2010
Embed
What would you like to do?
// 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