baidu
互联网 54BQ.com
10-03
05

在网站上加上翻译当前页成英语链接的代码


  
大家都知道谷歌翻译非常好用。可以把一大段话或者这个网页进行翻译。
而谷歌翻译页面的地址往往是这样的:
http://translate.googleusercontent.com/translate_c?hl=zh-CN&sl=zh-CN&tl=en&u=http://www.54bq.com/boke/article/shmshz/227.htm&rurl=translate.google.com&usg=ALkJrhgo8djd0k6-nWl2-0osZzRWAYtrOw



其中
hl是谷歌翻译的页面语言,一般填入中文或者与tl一致即可
sl是源网页是什么语言 中文 zh-CN
tl是翻译成什么语言   英语 en
u是原网页完整地址包括http
rurl
usg是跟用户电脑有关的认证KEY


谷歌翻译支持的语言有

sq 阿尔巴尼亚语    ar 阿拉伯语    ga 爱尔兰语    et 爱沙尼亚语    be 白俄罗斯语
bg 保加利亚语    is 冰岛语    pl 波兰语    fa 波斯语    af 布尔文(南非荷兰语)    da 丹麦语    de 德语    ru 俄语
fr 法语    tl 菲律宾语    fi 芬兰语    ht 海地克里奥尔语 ALPHA    ko 韩语    nl 荷兰语    gl 加利西亚语
ca 加泰罗尼亚语    cs 捷克语    hr 克罗地亚语    lv 拉脱维亚语    lt 立陶宛语    ro 罗马尼亚语
mt 马耳他语    ms 马来语    mk 马其顿语    no 挪威语    pt 葡萄牙语    ja 日语    sv 瑞典语    
sr 塞尔维亚语    sk 斯洛伐克语    sl 斯洛文尼亚语    sw 斯瓦希里语    th 泰语
tr 土耳其语    cy 威尔士语    uk 乌克兰语    es 西班牙语    iw 希伯来语    el 希腊语    hu 匈牙利语
it 意大利语    yi 意第绪语    hi 印地语    id 印尼语en 英语    vi 越南语    zh-TW 中文(繁体)    zh-CN 中文(简体)


比如我们打算添加将当前页翻译成法语的链接
那么链接应该是
http://translate.googleusercontent.com/translate_c?hl=zh-CN&sl=zh-CN&tl=fr&u=http://www.54bq.com/boke/article/shmshz/227.htm&rurl=translate.google.com
其中usg可以不标明

然后将此链接使用JavaScript输出:
<script type=text/javascript>  
document.write("<a href=http://translate.googleusercontent.com/translate_c?hl=zh-CN&sl=zh-CN&tl=en&u=http://"+location.hostname+location.pathname+location.search+" target=_blank>english</a>")
</script>  


怎么样还不错吧,本功能还可以扩展至下列菜单,这样就可以自由选择翻译的目标语言!

如果打算加入多种目标语种也可以使用这段代码:



<SCRIPT language=JavaScript>
<!--
document.writeln("<table style=\"text-align: left; width: 200px;\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">");
document.writeln("<tbody>");
document.writeln("<tr>");
document.writeln("<td><a target=\"_blank\" href=\"http://translate.googleusercontent.com/translate_c?hl=zh-CN&langpair=zh-CN%7Cfr&u="+location.hostname+location.pathname+location.search+"\"><img style=\"border: 0px solid ; width: 30px; height: 20px;\" alt=\"Fran?ais/French\" src=\"http://www.54bq.com/boke/images/lang/frenchflag.jpg\"></a></td>");
document.writeln("<td><a target=\"_blank\" href=\"http://translate.googleusercontent.com/translate_c?hl=zh-CN&langpair=zh-CN%7Cde&u="+location.hostname+location.pathname+location.search+"\"><img style=\"border: 0px solid ; width: 30px; height: 20px;\" alt=\"Deutsch/German\" src=\"http://www.54bq.com/boke/images/lang/germanflag.jpg\"></a></td>");
document.writeln("<td><a target=\"_blank\" href=\"http://translate.googleusercontent.com/translate_c?hl=zh-CN&langpair=zh-CN%7Cit&u="+location.hostname+location.pathname+location.search+"\"><img style=\"border: 0px solid ; width: 30px; height: 20px;\" alt=\"Italiano/Italian\" src=\"http://www.54bq.com/boke/images/lang/italianflag.jpg\"></a></td>");
document.writeln("<td><a target=\"_blank\" href=\"http://translate.googleusercontent.com/translate_c?hl=zh-CN&langpair=zh-CN%7Cnl&u="+location.hostname+location.pathname+location.search+"\"><img title=\"Netherlands/Dutch\" style=\"border: 0px solid ; width: 30px; height: 20px;\" alt=\"Netherlands/Dutch\" src=\"http://www.54bq.com/boke/images/lang/flag-netherlands.jpg\"></a></td>");
document.writeln("<td><a target=\"_blank\" href=\"http://translate.googleusercontent.com/translate_c?hl=zh-CN&langpair=zh-CN%7Ces&u="+location.hostname+location.pathname+location.search+"\"><img style=\"border: 0px solid ; width: 30px; height: 20px;\" alt=\"Espa?ol/Spanish\" src=\"http://www.54bq.com/boke/images/lang/spanishflag.jpg\"></a></td>");
document.writeln("<td>");
document.writeln("<a target=\"_blank\" href=\"http://translate.googleusercontent.com/translate_c?hl=zh-CN&langpair=zh-CN%7Cpt&u="+location.hostname+location.pathname+location.search+"\"><img style=\"border: 0px solid ; width: 30px; height: 20px;\" alt=\"Portugu?s/Portuguese\" src=\"http://www.54bq.com/boke/images/lang/portugeseglag.jpg\"></a></td>");
document.writeln("</tr>");
document.writeln("<tr>");
document.writeln("<td>");
document.writeln("<a target=\"_blank\" href=\"http://translate.googleusercontent.com/translate_c?hl=zh-CN&langpair=zh-CN%7Cko&u="+location.hostname+location.pathname+location.search+"\"><img");
document.writeln("<img style=\"border: 0px solid ; width: 30px; height: 20px;\" alt=\"한국어/Korean\" src=\"http://www.54bq.com/boke/images/lang/koreanflag.jpg\"></a>");
document.writeln("</td>");
document.writeln("<td>");
document.writeln("<a target=\"_blank\" href=\"http://translate.googleusercontent.com/translate_c?hl=zh-CN&langpair=zh-CN%7Czh-CN&u="+location.hostname+location.pathname+location.search+"\"><img");
document.writeln("<img style=\"border: 0px solid ; width: 30px; height: 20px;\" alt=\"中文(简体)/Chinese Simplified\" src=\"http://www.54bq.com/boke/images/lang/chineseflag.jpg\"></a>");
document.writeln("</td>");
document.writeln("<td>");
document.writeln("<a target=\"_blank\" href=\"http://translate.googleusercontent.com/translate_c?hl=zh-CN&langpair=zh-CN%7Cja&u="+location.hostname+location.pathname+location.search+"\"><img");
document.writeln("<img style=\"border: 0px solid ; width: 30px; height: 20px;\" alt=\"日本語/Japanese\" src=\"http://www.54bq.com/boke/images/lang/japanflag.jpg\"></a>");
document.writeln("</td>");
document.writeln("<td>");
document.writeln("<a target=\"_blank\" href=\"http://translate.googleusercontent.com/translate_c?hl=zh-CN&langpair=zh-CN%7Cel&u="+location.hostname+location.pathname+location.search+"\"><img style=\"border: 0px solid ; width: 30px; height: 20px;\" alt=\"Greek\" src=\"http://www.54bq.com/boke/images/lang/greekflag.gif\"></a></td>");
document.writeln("<td>");
document.writeln("<a target=\"_blank\" href=\"http://translate.googleusercontent.com/translate_c?hl=zh-CN&langpair=zh-CN%7Car&u="+location.hostname+location.pathname+location.search+"\"><img title=\"Arabic / UAE\" style=\"border: 0px solid ; width: 30px; height: 20px;\" alt=\"Arabic / UAE\" src=\"http://www.54bq.com/boke/images/lang/arabic_flag.jpg\"></a></td>");
document.writeln("<td><a target=\"_blank\" href=\"http://translate.googleusercontent.com/translate_c?hl=zh-CN&langpair=zh-CN%7Cru&u="+location.hostname+location.pathname+location.search+"\"><img title=\"Russia/Russian\" style=\"border: 0px solid ; width: 30px; height: 20px;\" alt=\"Russia/Russian\" src=\"http://www.54bq.com/boke/images/lang/russia.gif\"></a></td>");
document.writeln("</tr>");
document.writeln("</tbody>");
document.writeln("</table>");
//-->
</SCRIPT>



代码未作优化,请各博主根据自己喜号进行修改!
本文由双木杉子独家发布,转载请注明出处,谢谢!!
本文来自: 双木杉子个人网站(54bq.com) 详细出处参考:http://www.54bq.com/boke/article/shmshz/227.htm


[本日志由 shmshz 于 2010-03-05 07:14 PM 编辑]
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags:
相关日志:
评论: 0 | 引用: 0 | 查看次数: -
发表评论
昵 称:
邮 箱:
密 码: 游客发言不需要密码.
内 容:
验证码: 验证码
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.