查找了一些google Ajax API的资料,详见
http://code.google.com/apis/ajaxlanguage/documentation/
,还参照了别人的博客
http://www.cnblogs.com/bjpdj/archive/2008/04/30/1177161.html修改了一下
图片
Code
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TranslateUC.ascx.cs" Inherits="WebApp.TranslateUC" %>
<script type="text/javascript" src="http://www.google.com/jsapi" ></script>
<script type="text/javascript">
google.load("language",1);
google.setOnLoadCallback(submitChange);
function submitChange() {
var value = document.getElementById('source').value;
// var langpair = document.getElementById('langpair');
//var pair = langpair.options[langpair.selectedIndex].value.split('|');
//var src = pair[0];
//var dest = pair[1];
var src=document.getElementById("languageSrc").value;
var dest=document.getElementById("languageDest").value;
google.language.translate(value, src, dest, translateResult);
return false;
}
function translateResult(result) {
var resultBody = document.getElementById("results_body");
if (result.translation) {
resultBody.innerHTML = result.translation;
} else {
resultBody.innerHTML = '<span>Error Translating</span>';
}
}
</script>
<div>
Translate Tools<br />
<br />
<fieldset style="height: 175px; width: 270px;">
<legend>Enter text</legend>
<textarea id="source" style="height: 130px; width: 250px;"></textarea></fieldset>
<fieldset style="height:175px; width: 270px;">
<legend>Translate Result</legend>
<div id="results_body"
style="height: 130px; width: 250px;overflow:auto;">
</div></fieldset>
<br />
<select id="languageSrc">
<option value="zh-CN">Chinese (Simplified)</option>
<option value="en">English</option>
<option value="fr">French</option>
<option value="es">Spanish</option>
<option value="ru">Russian</option>
<option value="ar">Arabic</option>
<option value="de">German</option>
</select> >>
<select id="languageDest">
<option value="zh-CN">Chinese (Simplified)</option>
<option value="en">English</option>
<option value="fr">French</option>
<option value="es">Spanish</option>
<option value="ru">Russian</option>
<option value="ar">Arabic</option>
<option value="de">German</option>
</select>
<input id="translatebtn" type="button" value="Translate" onclick="submitChange();" />
</div>