Friday, 13 April 2012

Jquery language translation utility for blogspot Translate

Surely you already know to add Google Translate - very useful for sites that have traffic from many different countries. Gadgets that I was going to introduce below is based on Google's Translate tool, but in combination with jQuery:

 Cool? The entire site has been translated into other languages ​​without having to open a new tab on browser content. Moreover, language has been translated automatically into the next visit.

To add this gadget to your blog, create a widget HTML / javascript new paste the following code:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script src="http://jquery-translate.googlecode.com/files/jquery.translate-1.3.9.min.js" type="text/javascript"></script>
<script type='text/javascript'>//<![CDATA[
jQuery.cookie=function(key,value,options){if(arguments.length>1&&(value===null||typeof value!=="object")){options=jQuery.extend({},options);if(value===null){options.expires=-1;}
if(typeof options.expires==='number'){var days=options.expires,t=options.expires=new Date();t.setDate(t.getDate()+days);}
return(document.cookie=[encodeURIComponent(key),'=',options.raw?String(value):encodeURIComponent(String(value)),options.expires?'; expires='+options.expires.toUTCString():'',options.path?'; path='+options.path:'',options.domain?'; domain='+options.domain:'',options.secure?'; secure':''].join(''));}
options=value||{};var result,decode=options.raw?function(s){return s;}:decodeURIComponent;return(result=new RegExp('(?:^|; )'+encodeURIComponent(key)+'=([^;]*)').exec(document.cookie))?decode(result[1]):null;};
var date=new Date();date.setTime(date.getTime()+(86400*360));$(function(){if($.cookie('lang')=='EN'){lanEN();}
if($.cookie('lang')=='VI'){lanVN();}
if($.cookie('lang')=='ES'){lanES();}
if($.cookie('lang')=='FR'){lanFR();}})
function lanVN(){$('body').translate('vietnamese');$.cookie('lang','VN',{path:'/',expires:date});}
function lanEN(){$('body').translate('english');$.cookie('lang','EN',{path:'/',expires:date});}
function lanES(){$('body').translate('Spanish');$.cookie('lang','ES',{path:'/',expires:date});}
function lanFR(){$('body').translate('French');$.cookie('lang','FR',{path:'/',expires:date});}
//]]></script>
<a href="javascript:void(0)" onclick="lanES()" title="Espanol"><img style="margin-right:5px" alt="Spanish" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8BCWHtuWwM4lEsCJR5N1TIkzeMNPjI-NPAviwjYkQxLs5vR3JhqfKDazSD_2hV2aUYo17e2C0R87Y7VvNw5mAKlYlNxwoTaKaV_OiVacSgCKQcO2beypulpSCn4zm789YrQ3Amfv9CTE/s1600/spanish.png" /></a><a href="javascript:void(0)" onclick="lanEN()" title="English"><img style="margin-right:5px" alt="English" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEid1j7BJ6jXxxgrBNdenejQtk8mea4I686MCSq5mJsBE8IcovIK_Wevsk5GhurgZRrg8AxZ29-w1VNU5tMMH0ydg5yAtPjpkkp7zb30vPFxiWM30jHkKNFvySE5ZcZG5hZRVNdA2ekIeUk/s1600/english.png" /></a><a href="javascript:void(0)" onclick="lanFR()" title="French"><img style="margin-right:5px" alt="French" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFM9xbAvYLgfgd6vobRXV73YmGu0ysWNi6v43RHNxbgIrGTjO-j6Ww9qNimEWKPBjNCZS1EJ7ha2zu50oWf-chMbQdzdmkbq9CjrGJs2PYhyphenhyphenF12zwc1xYwjaDAKxZSbIsE_H7RKC86GkE/s1600/french.png" /></a><a href="javascript:void(0)" onclick="lanVN()" title="Vietnamese"><img alt="Vietnamese" src="http://lh5.ggpht.com/_rVQLxDFDz0A/TJXxIw-AcOI/AAAAAAAAGqQ/6wL1yekmQls/Vietnam.png" /></a>
 You can add in some other languages ​​that Google supports by changing the red line:
 <a href="javascript:void(0)" onclick="lanVN()" title="Vietnamese"><img alt="Vietnamese" src="image.png" /></a>

No comments:

Post a Comment