Google AJAX Language API
『Google AJAX Language API』を使ったサンプル。
- into
type="text/javascript" src="http://www.google.com/jsapi"></script>
<script
type="text/javascript">
google.load('language','1');
google.setOnLoadCallback(function (){
var languageList = document.getElementById('languageList');
for (var language in google.language.Languages) {
var languageOption = new Option(language, google.language.Languages[language]);
languageList.options[languageList.options.length] = languageOption;
}
});
function translate() {
var sourceText = document.getElementById('sourceText').value;
google.language.detect(sourceText, function(detectResult) {
if (detectResult.error) {
alert('Error:' + error.message);
return;
}
var languageList = document.getElementById('languageList');
targetLanguage = languageList.options[languageList.selectedIndex].value;
google.language.translate(
sourceText,
detectResult.language,
targetLanguage,
function(result) {
if (result.error) {
alert('Error:' + result.message);
return;
}
document.getElementById('destinationText').value = result.translation;
});
});
}
</script>
<div>
<dl>
<dd><textarea id="sourceText" cols="40" rows="8"></textarea></dd>
<dt><input type="submit" value="Translate" onclick="translate()"> into <select id="languageList"></select></dt>
<dd><textarea id="destinationText" cols="40" rows="8"></textarea></dd>
</dl>
</div>
ディスカッション
コメント一覧
まだ、コメントがありません