Post by ⓦ৹₪deⓡ on Jan 21, 2010 19:36:59 GMT -8
This code will add an option at the bottom of each post to translate the post from English, and only English, into another language:
Click on Translate will bring up a menu of the languages the post can be translated into:
The following languages are supported: afrikaans, albanian, arabic, belarusian, bulgarian, catalan, chinese, chinese_simplified, chinese_traditional, croatian, czech, danish, dutch, estonian, filipino, finnish, french, galician, german, greek, hebrew, hindi, hungarian, icelandic, indonesian, irish, italian, japanese, korean, latvian, lithuanian, macedonian, malay, maltese, norwegian, persian, polish, portuguese, romanian, russian, serbian, slovak, slovenian, spanish, swahili, swedish, tagalog, thai, turkish, ukrainian, vietnamese, welsh, yiddish
Here is the final result of the translation:
Translations are provided by Google. Place in Global Footers.
Click on Translate will bring up a menu of the languages the post can be translated into:
The following languages are supported: afrikaans, albanian, arabic, belarusian, bulgarian, catalan, chinese, chinese_simplified, chinese_traditional, croatian, czech, danish, dutch, estonian, filipino, finnish, french, galician, german, greek, hebrew, hindi, hungarian, icelandic, indonesian, irish, italian, japanese, korean, latvian, lithuanian, macedonian, malay, maltese, norwegian, persian, polish, portuguese, romanian, russian, serbian, slovak, slovenian, spanish, swahili, swedish, tagalog, thai, turkish, ukrainian, vietnamese, welsh, yiddish
Here is the final result of the translation:
Translations are provided by Google. Place in Global Footers.
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
//Translate Post v1.0
//Copyright 1-21-2010 by ~Wonder
//May not be reposted anywhere
//Put in Global Footer. Do not edit.
google.load("language", "1");
function translate(text,lang) {
google.language.translate(text, "en", lang,
function(result) {
if (result.translation) {
temp2=result.translation.split("|.|.|.|.|.|.|.|");
document.getElementById("translatediv"+temp2[0].replace(/^\s\s*/, '').replace(/\s\s*$/, '')).innerHTML=" "+temp2[1]+" ";
}
});
}
counter=0;
function getTextNodes(p,lang)
{
if(p.childNodes.length>0)
{
for(var i=0;i<p.childNodes.length;i++)
{
if(p.childNodes[i].nodeName=="#text" && p.childNodes[i].nodeValue.replace(/^\s\s*/, '').replace(/\s\s*$/, '').length>1)
{
temp=document.createElement("span");
temp3=p.childNodes[i].nodeValue;
temp.innerHTML=temp3;
temp.id="translatediv"+counter;
p.replaceChild(temp,p.childNodes[i]);
translate(counter+"|.|.|.|.|.|.|.|"+temp3,lang);
counter++;
}
else if(!p.childNodes[i].nodeName.match(/script/i))
{
getTextNodes(p.childNodes[i],lang);
}
}
}
}
function showLanguages(l)
{
l.style.display="none";
l.parentNode.getElementsByTagName("span")[0].style.display="";
}
function startTranslate(l)
{
l.parentNode.parentNode.style.display="none";
getTextNodes(l.parentNode.parentNode.parentNode.parentNode.parentNode. parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.rows[1].cells[0],l.parentNode.getElementsByTagName("select")[0].value);
temp4=document.createElement("center");
temp5=google.language.getBranding();
temp5.innerHTML=temp5.innerHTML.replace("powered by","translation powered by");
temp4.appendChild(temp5);
l.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode. parentNode.parentNode.parentNode.rows[1].cells[0].appendChild(temp4);
}
if(location.href.match(/action=(display|goto|viewprofile|pmview|recent|userrecentposts)/) || (location.href.match(/\.cgi$/) && document.title.match("Search Results")))
{
td=document.getElementsByTagName("td");
for(i=0;i<td.length;i++)
{
if(td[i].className.match("windowbg") && td[i].align=="left" && td[i].vAlign=="bottom")
{
a=td[i].getElementsByTagName("a");
for(j=0;j<a.length-1;j++)
{
if(a[j].innerHTML=="Link to Post" && a[j+1].innerHTML=="Back to Top")
{
a[j].parentNode.innerHTML='<div style="display:inline"><a href="#" onclick="showLanguages(this);return false;">Translate</a><span style="display:none"><SELECT><OPTION value=af selected>afrikaans</OPTION><OPTION value=sq>albanian</OPTION><OPTION value=ar>arabic</OPTION><OPTION value=be>belarusian</OPTION><OPTION value=bg>bulgarian</OPTION><OPTION value=ca>catalan</OPTION><OPTION value=zh>chinese</OPTION><OPTION value=zh-CN>chinese_simplified</OPTION><OPTION value=zh-TW>chinese_traditional</OPTION><OPTION value=hr>croatian</OPTION><OPTION value=cs>czech</OPTION><OPTION value=da>danish</OPTION><OPTION value=nl>dutch</OPTION><OPTION value=et>estonian</OPTION><OPTION value=tl>filipino</OPTION><OPTION value=fi>finnish</OPTION><OPTION value=fr>french</OPTION><OPTION value=gl>galician</OPTION><OPTION value=de>german</OPTION><OPTION value=el>greek</OPTION><OPTION value=iw>hebrew</OPTION><OPTION value=hi>hindi</OPTION><OPTION value=hu>hungarian</OPTION><OPTION value=is>icelandic</OPTION><OPTION value=id>indonesian</OPTION><OPTION value=ga>irish</OPTION><OPTION value=it>italian</OPTION><OPTION value=ja>japanese</OPTION><OPTION value=ko>korean</OPTION><OPTION value=lv>latvian</OPTION><OPTION value=lt>lithuanian</OPTION><OPTION value=mk>macedonian</OPTION><OPTION value=ms>malay</OPTION><OPTION value=mt>maltese</OPTION><OPTION value=no>norwegian</OPTION><OPTION value=fa>persian</OPTION><OPTION value=pl>polish</OPTION><OPTION value=pt-PT>portuguese</OPTION><OPTION value=ro>romanian</OPTION><OPTION value=ru>russian</OPTION><OPTION value=sr>serbian</OPTION><OPTION value=sk>slovak</OPTION><OPTION value=sl>slovenian</OPTION><OPTION value=es>spanish</OPTION><OPTION value=sw>swahili</OPTION><OPTION value=sv>swedish</OPTION><OPTION value=tl>tagalog</OPTION><OPTION value=th>thai</OPTION><OPTION value=tr>turkish</OPTION><OPTION value=uk>ukrainian</OPTION><OPTION value=vi>vietnamese</OPTION><OPTION value=cy>welsh</OPTION><OPTION value=yi>yiddish</OPTION></SELECT> <a href="#" onclick="startTranslate(this);return false;">Go</a></span>'+' - </div>'+a[j].parentNode.innerHTML;
j=a.length;
}
}
}
}
}
</script>