Developer’s Guide – Google AJAX Language API – Google Code


 

With the AJAX Language API, you can translate and detect the language of blocks of text within a webpage using only Javascript.

The “Hello, World” of the Google AJAX Language API

The easiest way to start learning about this API is to see a simple example. The following example will detect the language of the given text and then translate it to English.

<html>
  <head>
    <script type="text/javascript" src="http://www.google.com/jsapi"></script>
    <script type="text/javascript">

    google.load("language", "1");

    function initialize() {
      var text = document.getElementById("text").innerHTML;
      google.language.detect(text, function(result) {
        if (!result.error && result.language) {
          google.language.translate(text, result.language, "en",
                                    function(result) {
            var translated = document.getElementById("translation");
            if (result.translation) {
              translated.innerHTML = result.translation;
            }
          });
        }
      });
    }
    google.setOnLoadCallback(initialize);

    </script>
  </head>
  <body>
    <div id="text">你好,很高興見到你。</div>
    <div id="translation"></div>
  </body>
</html>

You can view this example here to edit and play around with it.

Via Developer’s Guide – Google AJAX Language API – Google Code

Advertisements

One thought on “Developer’s Guide – Google AJAX Language API – Google Code

  1. Hi
    I am working in Asp.Net 2.0 and C#.
    I want convert language English to Hindi using google api. I am facing problem .Plz tell me how to use google api in C#.
    It is working fine with JS for single string but create problem with string array.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s