Google AJAX Language API

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>

相关文章:

1、让 Google 在您的 AMP 网站上放置展示广告
https://www.onexin.net/google-adsense-amp/

2、如何让搜索引擎抓取AJAX内容?
https://www.onexin.net/how-to-get-search-engines-to-crawl-ajax-content/

3、谷歌向OEM厂商提供Android最大漏洞补丁
https://www.onexin.net/google-android-to-oem-manufacturers-to-provide-maximum-patches/

4、Installing the Google PHP SDK on Linux
https://www.onexin.net/installing-the-google-php-sdk-on-linux/

5、Google字典不能用了怎麼辦?
https://www.onexin.net/google-dictionary-can-not-be-how-to-do/

转载请注明出处:https://www.onexin.net/google-ajax-language-api/

Leave a Reply

Your email address will not be published. Required fields are marked *