Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The following javascript is used for google translate api v.2.

JavaScript
  <body>
    <div id="sourceText">Hello World</div>
    <div id="translation"></div>
    <script>
      function translateText(response)
	  {
			document.getElementById("translation").innerHTML += "<br>" + response.data.translations[0].trnslatedText;
      }
    </script>
    <script>
      var newScript = document.createElement('script');
      newScript.type = 'text/javascript';
      var sourceText = escape(document.getElementById("sourceText").innerHTML);
      // WARNING: be aware that YOUR-API-KEY inside html is viewable by all your users.
      // Restrict your key to designated domains or use a proxy to hide your key
      // to avoid misuage by other party.
      var source = 'https://www.googleapis.com/language/translate/v2?key=Here-MyappKey&source=en&target=gu&callback=translateText&q=' + sourceText;
	  
      newScript.src = source;

      // When we add this script to the head, the request is sent off.
      document.getElementsByTagName('head')[0].appendChild(newScript);
    </script>
  </body>
</html>

i am getting error as follows:
'data.translations is null or not an object.'
pls give me the suggetion for my prblm.
Posted
Updated 2-Dec-13 0:21am
v2
Comments
Richard MacCutchan 2-Dec-13 6:21am    
Find out why that reference is not valid.
Nayan-Dabhi 2-Dec-13 13:05pm    
Richard MacCutchan :
i know the little bit solution for my problem is that i read documentation of the google translate api V.2 is that paid service.
so firstly i have to paid for this service then i can use this api.
Nayan-Dabhi 2-Dec-13 13:08pm    
so that's why the json object "data" is not send me on the browser.
i could not getting the result for my javascript code...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900