Created
October 30, 2010 13:48
-
-
Save think49/655307 to your computer and use it in GitHub Desktop.
はじめての Google AJAX Language API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="ja"> | |
<head> | |
<meta charset="UTF-8" /> | |
<title>はじめての Google AJAX Language API</title> | |
<script src="http://www.google.com/jsapi"></script> | |
<script src="./javascript-xpath-latest-cmp.js"></script> | |
<script src="./ExtXPathEvaluator.js"></script> | |
<script> | |
google.load('language', '1'); | |
google.setOnLoadCallback(function () { | |
var doc, evaluator; | |
doc = document; | |
evaluator = new ExtXPathEvaluator; | |
evaluator.evaluate(doc, 'descendant::text()[normalize-space(.)]', doc.body).forEach(function (textNode) { | |
var textValue; | |
textValue = textNode.nodeValue; | |
google.language.detect(textValue, function (result) { | |
if (!result.error && result.language) { | |
google.language.translate(textValue, result.language, 'en', function (result) { | |
if (result.translation) { | |
textNode.nodeValue = result.translation; | |
} | |
}); | |
} | |
}); | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<h1>はじめての Google AJAX Language API</h1> | |
<h2>作成にあたって</h2> | |
<p>このサンプルコードは <a href="http://code.google.com/intl/ja/apis/ajaxlanguage/documentation/#HelloWorld">デベロッパー ガイド - Google AJAX Language API - Google Code</a> と <a href="http://gist.github.com/653491">gist: 653491 - (ExtXPathEvaluator.js) - GitHub</a> をベースにして作りました。</p> | |
<h2 id="Sample">サンプルテキスト</h2> | |
<p>こんにちは、世界!</p> | |
<p>こんにちは、世界!</p> | |
<p>こんにちは、世界!</p> | |
<p>こんにちは、世界!</p> | |
<h2 id="ReferenceURL">参考URL</h2> | |
<dl> | |
<dt id="Google">Google</dt> | |
<dd> | |
<ul> | |
<li><a href="http://code.google.com/intl/ja/apis/ajaxlanguage/documentation/#HelloWorld">はじめての Google AJAX Language API - Google Code</a></li> | |
</ul> | |
</dd> | |
<dt id="Others">その他</dt> | |
<dd> | |
<ul> | |
<li><a href="http://okwave.jp/qa/q6284674.html">google翻訳apiで、#TEXTを翻訳する。 | OKWave</a></li> | |
</ul> | |
</dd> | |
</dl> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Google AJAX Language API に加えて、2つのJavaScriptライブラリを利用しています。
はじめての Google AJAX Language API - Google Code
http://code.google.com/intl/ja/apis/ajaxlanguage/documentation/#HelloWorld
gist: 653491 - (ExtXPathEvaluator.js) - GitHub
http://gist.github.com/653491
JavaScript-XPath – CodeRepos::Share – Trac
http://coderepos.org/share/wiki/JavaScript-XPath
下記URLにサンプルがあります。(いずれ消すかもしれません)
はじめての Google AJAX Language API
http://vird2002.s8.xrea.com/javascript/google_ajax_language_api_hello_world.html
OKWave で回答しました。
google翻訳apiで、#TEXTを翻訳する。 | OKWave
http://okwave.jp/qa/q6284674.html