Skip to content

Instantly share code, notes, and snippets.

@think49
Created October 30, 2010 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save think49/655307 to your computer and use it in GitHub Desktop.
Save think49/655307 to your computer and use it in GitHub Desktop.
はじめての Google AJAX Language API
<!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>
@think49
Copy link
Author

think49 commented Oct 30, 2010

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment