title: Google API - Translate a string into EN language :(
body: <p>I am trying to make a simple web based application which will translate a non-english (non-EN) string into English (EN) language. For this I am using Google's Translation API (v1- JS).</p>
  
  <p>At first I am detecting the language provided in a div tag (note that page encoding is set to UTF-8).</p>
  
  <p>Then I am trying to translate the text if it is in non EN language and then it is to be displayed just below the detected language tag.</p>
  
  <p>I am able to obtain the language detected but the translation never happens! :(</p>
  
  <p>Any help would be much appreciated..</p>
  
  <p>Here's the code:</p>
  
  <pre><code> &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;
  &lt;title&gt;Insert title here&lt;/title&gt;
  
  &lt;script
      src="http://www.google.com/jsapi?key=mykeyfrxwexdfwezfdhfxcewx" type="text/javascript"&gt;&lt;/script&gt;
  
  &lt;script type="text/javascript"&gt;
      /*
       *  How to detect the language of text.
       */
  
  
      google.load("language", "1");
  
      function initialize() {
          var content = document.getElementById('content');
          // Setting the text in the div.
          content.innerHTML = '&lt;div id="text"&gt;Hola, me alegro mucho de verte.&lt;\/div&gt;&lt;div id="detected"&gt;&lt;\/div&gt;&lt;div id="transtext"/&gt;';
  
          // Grabbing the text to translate
          var text = document.getElementById("text").innerHTML;
  
          // Detect the language of the text.
          google.language.detect(text, function(result) {
              var detected = document.getElementById("detected");
              // If there wasn't an error in the request
              if (!result.error) {
                  var langCode = result.language;
                  var langName;
  
                  // Loop through the languages enum so that we can find the actual name of the language.
                  // Learn about the languages enum here:
                  // http://code.google.com/apis/ajaxlanguage/documentation/reference.html#LangNameArray
                  for ( var i in google.language.Languages) {
                      var thisLangCode = google.language.Languages[i];
                      if (thisLangCode == langCode) {
                          // find the language code, store the language name.
                          langName = i;
                          break;
                      }
                  }
  
                  // See the detected language.
                  detected.innerHTML = 'Detected: "' + result.language
                          + '" - aka "' + langName + '"';
              }
          });
  
          google.language.translate(text, 'es', 'en', function(result) {
              var translated = document.getElementById("transtext");
              if (result.transtext) {
                  translated.innerHTML = result.transtext;
              }
          });
  
      }
      google.setOnLoadCallback(initialize);
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body style="font-family: Arial; border: 0 none;"&gt;
      &lt;div id="content"&gt;Loading...&lt;/div&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>