01.
<html>
02.
<head>
03.
<title>Google 翻訳</title>
04.
<meta http-equiv=
"content-type"
content=
"text/html; charset=UTF-8"
>
05.
<style type=
"text/css"
>
06.
body {
07.
font-family:
"MS Pゴシック"
;
08.
font-size: 14px;
09.
}
10.
</style>
11.
<script type=
"text/javascript"
src=
"http://www.google.com/jsapi"
></script>
12.
<script type=
"text/javascript"
>
13.
14.
var
parentwin = external.menuArguments;
15.
var
doc = parentwin.document;
16.
var
sel = doc.selection;
17.
var
rng = sel.createRange();
18.
var
text = rng.text;
19.
var
lang;
20.
21.
google.load(
"language"
,
"1"
);
22.
23.
function
initialize() {
24.
google.language.detect(text,
function
(result) {
25.
if
(!result.error && result.language) {
26.
lang = result.language;
27.
if
( result.language ==
"ja"
) {
28.
google.language.translate(text, result.language,
"en"
,
29.
function
(result) {
30.
var
translated = document.getElementById(
"translation"
);
31.
if
(result.translation) {
32.
translated.innerHTML = result.translation;
33.
try
{
34.
document.getElementById(
"type"
).innerHTML =
"日本語 => 英語"
;
35.
}
catch
(e){}
36.
}
37.
});
38.
}
39.
if
( result.language !=
"ja"
) {
40.
google.language.translate(text, result.language,
"ja"
,
41.
function
(result) {
42.
var
translated = document.getElementById(
"translation"
);
43.
if
(result.translation) {
44.
translated.innerHTML = (result.translation).replace(/。/mg,
"。<br><br>"
);
45.
try
{
46.
document.getElementById(
"type"
).innerHTML = lang +
" => 日本語"
;
47.
}
catch
(e){}
48.
}
49.
});
50.
}
51.
}
52.
else
{
53.
var
translated = document.getElementById(
"translation"
);
54.
translated.innerHTML = result.error;
55.
}
56.
});
57.
}
58.
59.
google.setOnLoadCallback(initialize);
60.
61.
</script>
62.
</head>
63.
<body style=
'padding:20px;'
>
64.
<H5 id=
"type"
>言語変換タイプ自動決定</H5>
65.
<div id=
"translation"
><b>Google AJAX Language API で翻訳中です。しばらくお待ち下さい....</b>
66.
<br>( ※ あまり長い文章は結果が表示されない場合があります )</div>
67.
</body>
68.
</html>