Click here to Skip to main content
13,141,354 members (88,614 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi guys I have code for translator google api but the translate only when i'm enter text in scurce code,but i want to translate any text by button please who know write me)

    <title>Translate API Example</title>
    <textarea rows="4" cols="50" id="sourceText" >
    Welcome in my site
  <textarea rows="4" cols="50" id="translation" >
<input name="send" type="button"  onClick="newScrip" value="translate">
function translateText(response) {
  document.getElementById("translation").textContent += "" +[0].translatedText;
      var newScript = document.createElement('script');
      newScript.type = 'text/javascript';
      var sourceText = escape(document.getElementById("sourceText").textContent);
      // 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 send = ' Key&source=en&target=iw&callback=translateText&q=translate+is+fast' + sourceText;
      newScript.src = send;
      // When we add this script to the head, the request is sent off.

[Edit]Code block added[/Edit]
Posted 28-Dec-12 1:44am
Updated 28-Dec-12 1:58am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I notice you have not set the key in this line:
var send = ' Key&source=en&target=iw&callback=translateText&q=translate+is+fast' + sourceText;

The Google translate API is no longer free:[^] so you'll need to register (to get a key I assume).

As for the rest of the code, I don't know whether it will work or not. You will have more luck on Google developer groups as they'll have one dedicated to the translate api.
markohack 28-Dec-12 8:59am
I have a key and it work but i want translated entry text,HOW?

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.170915.1 | Last Updated 28 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100