I have figured out how to pass the page data to the API for the translating however the response back code to put it in place is failing. The javascript code for this is as follows:
<script type="text/javascript">
onload = function () {
var from = "en"
var to = document.getElementById('hdnLanguage').value;
var text = document.getElementsByTagName("html")[0].innerHTML;
var accessToken = document.getElementById('hdnAccessCode').value;
var s = document.createElement("script");
s.src = "http://api.microsofttranslator.com/V2/Ajax.svc/Translate" +
"?appId=Bearer " + encodeURIComponent(accessToken) +
"&from=" + encodeURIComponent(from) +
"&to=" + encodeURIComponent(to) +
"&text=" + encodeURIComponent(text) +
"&contentType=text/html" +
"&oncomplete=myTranslation";
//var p = document.getElementsByTagName('head')[0]; p.insertBefore(s, p.firstChild);
// document.body.appendChild(s);
}
function myTranslation(response) {
var element = document.getElementsByTagName("head")[0];
var r = response;
element.innerHTML = r;
}
</script>
I am passing from the server the access token and the language I want to translate the page to. This is being done in a site.master page so to try to automatically translate the page on page load from the client side. The row element.innerHTML
= r; fails. Someone told me that you can not do that to the head tag. Which seems obvious since the code failed there. I also looked at the code that widget was using and that did not seem to see the same results. Can any of you
guru's out know how to place the whole page return back to the page without changing the ViewState of the page?
Searches seem to be pointing me to the same pages. If anyone has already done this if you could either point me to sample code for a whole page translation using the API and not the widget I would appreciate it.
Any help is appreciated really.