<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google AJAX Language API - Hello World</title>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("language", "1");
function initialize(str) {
var text = document.getElementById("text").value;
google.language.detect(text, function(result) {
if (!result.error && result.language) {
google.language.translate(text, result.language, str,
function(result) {
var translated = document.getElementById("translation");
if (result.translation) {
translated.innerHTML = result.translation;
}
});
}
});
}
google.setOnLoadCallback(initialize);
</script>
</head>
<body>
<input type="text" name="text" value="你好,很高興見到你。"/>
<input type="button" value="汉译英" onclick="javascript:initialize('en')"/>
<input type="button" value="英译汉" onclick="javascript:initialize('zh')"/>
<div id="translation"></div>
</body>
</html>
没有评论:
发表评论