javascript - How detect actual language of webpage translated via Google translate? -


i need detect translated language , ideally make class maybe body. after via class edit css of webpage. have no problem solutions jquery or pure javascript. need because different languages has different length of words , can make me problem design. need solved

.language_cz .some_class{   font-size: 14px; } .language_en .some_class{   font-size: 16px; } 

i make translate via https://gtranslate.io/. pure google translate.

code of translate is:

   <div class="obal_mutace"> <span class="aktualni_mutace">cz</span> <div class="blok_mutace_in">             <a href="#" onclick="dogtranslate('cs|cs');return false;" title="czech" class="gflag nturl"><span data-id="cz" class="polozka_mutace_in">cz</span></a>   <a href="#" onclick="dogtranslate('cs|en');return false;" title="english" class="gflag nturl"><span data-id="en" class="polozka_mutace_in">en</span></a>   <a href="#" onclick="dogtranslate('cs|de');return false;" title="german" class="gflag nturl"><span data-id="de" class="polozka_mutace_in">de</span></a>   <a href="#" onclick="dogtranslate('cs|ru');return false;" title="russian" class="gflag nturl"><span data-id="ru" class="polozka_mutace_in">ru</span></a>   <a href="#" onclick="dogtranslate('cs|fr');return false;" title="french" class="gflag nturl"><span data-id="fr" class="polozka_mutace_in">fr</span></a>   <a href="#" onclick="dogtranslate('cs|it');return false;" title="italian" class="gflag nturl"><span data-id="it" class="polozka_mutace_in">it</span></a>   <a href="#" onclick="dogtranslate('cs|pt');return false;" title="portuguese" class="gflag nturl"><span data-id="pt" class="polozka_mutace_in">pt</span></a>   <a href="#" onclick="dogtranslate('cs|es');return false;" title="spanish" class="gflag nturl"><span data-id="es" class="polozka_mutace_in">es</span></a>   <div id="google_translate_element2"></div>   <script type="text/javascript" src="funkce/transl_init.js?v=1.0.1"></script>   <script type="text/javascript" src="http://translate.google.com/translate_a/element.js?cb=googletranslateelementinit2"></script> </div> 

in "transl_init.js" have:

function googletranslateelementinit2() {new google.translate.translateelement({pagelanguage: 'cs',autodisplay: false}, 'google_translate_element2');}  /* <![cdata[ */ eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseint(c/a)))+((c=c%a)>35?string.fromcharcode(c+29):c.tostring(36))};if(!''.replace(/^/,string)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new regexp('\\b'+e(c)+'\\b','g'),k[c]);return p}('6 7(a,b){n{4(2.9){3 c=2.9("o");c.p(b,f,f);a.q(c)}g{3 c=2.r();a.s(\'t\'+b,c)}}u(e){}}6 h(a){4(a.8)a=a.8;4(a==\'\')v;3 b=a.w(\'|\')[1];3 c;3 d=2.x(\'y\');z(3 i=0;i<d.5;i++)4(d[i].a==\'b-c-d\')c=d[i];4(2.j(\'k\')==e||2.j(\'k\').l.5==0||c.5==0||c.l.5==0){f(6(){h(a)},g)}g{c.8=b;7(c,\'m\');7(c,\'m\')}}',43,43,'||document|var|if|length|function|gtranslatefireevent|value|createevent||||||true|else|dogtranslate||getelementbyid|google_translate_element2|innerhtml|change|try|htmlevents|initevent|dispatchevent|createeventobject|fireevent|on|catch|return|split|getelementsbytagname|select|for|classname|goog|te|combo|null|settimeout|500'.split('|'),0,{})) /* ]]> */ 

i used on webpage project http://www.kalimera-recko.cz/. used google translate in head of web on left search input.

if understand question correct want style page according used language.

on page set language attribute on html tag.

<html class="js" style="height: 100%;" lang="cs"> 

so can address in css this:

html[lang="cs"] .some_class 

[edit]__________________

a cookie set "googtrans" value /cs/en if translated englisch , te value /cs/de if translated german. can find out value of cookie javascript or jquery

document.cookie 

it returns string need search "googtrans" value.

you can language this:

var cookie = document.cookie; var position = cookie.indexof("googtrans"); var language = cookie.substring(position+10, position + 16); 

this code can optimized if search end of value ';' instead of using fixed numbers. need.

you may should use try/catch , see if cookie exists because doesn't exist original language.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -