简明现代魔法 -> 信息化工具 -> 使用Google Translate实现网站的多国语言
使用Google Translate实现网站的多国语言
2010-06-09
Google Translate可以用来翻译网站,这样你的每一个页面都可以翻译成别国的语言了。
程序演示如下:
代码很简单:
<script language="javascript">
document.write('<a href="http://translate.google.com/translate?sl=en&hl=zh-CN&u=' + document.URL+ '" title="Chinese"><img width=24 height=16 alt="Translate this page to Chinese" src="images/cn.gif" border="0"></a> ');
document.write('<a href="http://translate.google.com/translate?sl=en&hl=en&u=' + document.URL+ '" title="English"><img width=24 height=16 alt="Translate this page to English" src="images/en.gif" border="0"></a> ');
document.write('<a href="http://translate.google.com/translate?sl=en&hl=de&u=' + document.URL+ '" title="German"><img width=24 height=16 alt="Translate this page to German" src="images/de.gif" border="0"></a> ');
document.write('<a href="http://translate.google.com/translate?sl=en&hl=fr&u=' + document.URL+ '" title="French"><img width=24 height=16 alt="Translate this page to French" src="images/fr.gif" border="0"></a> ');
document.write('<a href="http://translate.google.com/translate?sl=en&hl=it&u=' + document.URL+ '" title="Italian"><img width=24 height=16 alt="Translate this page to Italian" src="images/it.gif" border="0"></a> ');
document.write('<a href="http://translate.google.com/translate?sl=en&hl=es&u=' + document.URL+ '" title="Spanish"><img width=24 height=16 alt="Translate this page to Spanish" src="images/es.gif" border="0"></a> ');
document.write('<a href="http://translate.google.com/translate?sl=en&hl=pt&u=' + document.URL+ '" title="Portuguese"><img width=24 height=16 alt="Translate this page to Portuguese" src="images/pt.gif" border="0"></a> ');
document.write('<a href="http://translate.google.com/translate?sl=en&hl=ru&u=' + document.URL+ '" title="Russian"><img width=24 height=16 alt="Translate this page to Russian" src="images/ru.gif" border="0"></a> ');
</script>
其中sl是指源语言,hl是指目标语言。设定好这两个参数就可以了。document.URL可以自动获取当前需要翻译页面的URL。
世界上虽然很多国家但是常用的语言也就那么几个,因为大多被殖民过了,所以我们不要翻译很多。下面我把常用的各国语言的在GOOGLE上的翻译连接上的缩写给大家罗列一些。
zh-CN简体中文,zh-TW繁体中文,en英文,fr法国语,de德语,pt葡萄牙语,it意大利语,es西班牙语,ru俄语
这些就是基本长用的了如果你想翻译更多语言可以到http://www.google.com/language_tools?hl=zh-CN 去查一下各国语言的google缩写。
我自己实验中,把中文翻译成其他语言或者把其他语言翻译成中文都不好使,几乎都是乱码,所以这个可能只适用于E文网站。
