Skip to content

Instantly share code, notes, and snippets.

@mklabs
Created December 28, 2010 06:31
Show Gist options
  • Select an option

  • Save mklabs/756961 to your computer and use it in GitHub Desktop.

Select an option

Save mklabs/756961 to your computer and use it in GitHub Desktop.
Some DOM centric code to easily provide a raw translation using REST Google Translate API.
$.each($('#main').find('.content article').find('p, li, :header'), function(i, p){
var p = $(p);
var html = $(p).html();
$.getJSON('https://www.googleapis.com/language/translate/v2?key=AIzaSyCzfAwza3eYYFg2ketfePOAVznG4Oz0CXM&q='+html+'&source=fr&target=en&callback=?', function(results){
console.log(results);
p.html(results.data.translations[0].translatedText);
});
});
$.each($('#main').find('.content div.wikistyle').find('p, li, :header'), function(i, p){
var p = $(p);
var html = $(p).html();
$.getJSON('https://www.googleapis.com/language/translate/v2?key=key&q='+html+'&source=fr&target=en&callback=?', function(results){
console.log(results);
p.html(results.data.translations[0].translatedText);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment