Skip to content

Instantly share code, notes, and snippets.

@dsauerbrun
Last active August 27, 2015 20:52
Show Gist options
  • Save dsauerbrun/cdd8ae68fe50900b37e5 to your computer and use it in GitHub Desktop.
Save dsauerbrun/cdd8ae68fe50900b37e5 to your computer and use it in GitHub Desktop.
function bingTranslate(message,originLang,destLang,accessToken){
Promise.try(function(){
accessToken.then(function(bingToken){
options = {
headers:{
'Authorization': "Bearer "+bingToken
}
};
queryString="text="+encodeURIComponent(message)+"&from="+originLang+"&to="+destLang+"&contentType=text%2Fplain";
return bhttp.get("http://api.microsofttranslator.com/V2/Http.svc/Translate?"+queryString,options)
}).then(function(data){
return xml.parseBuffer(data.body).childs[0];
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment