i have a code uses google-translate and jquery.cookie to translate all page to other language:
$(document).ready(function () {
var googTrans = $.cookie('googtrans');
if (googTrans === '/es/en') { //Paint specific flag
var src = $('.lang-change img').attr('src').replace('flag_en.png', 'flag_es.gif');
$('.lang-change img').attr('src', src);
$('#lang-change-en').attr('id', 'lang-change-es');
}
$(".lang-change").on("click",function(){
if (googTrans == '/es/en') { //If language is english return to spanish
$.removeCookie('googtrans',{path:'', domain: 'domain.es'});
$.removeCookie('googtrans',{path:'', domain: '.domain.es'});
location.reload();
}else{ //Convert to english
$.cookie('googtrans','/es/en',{path:''});
location.reload();
}
});
});
//Google provides this function
function googleTranslateElementInit() {
new google.translate.TranslateElement({
pageLanguage: 'es',
includedLanguages: 'en',
layout: google.translate.TranslateElement.InlineLayout.SIMPLE,
autoDisplay: false
}, 'google_translate_element');
}
googtrans cookie set me as a session:
i cant delete this cookie and return to my original language
I use this code witouth jquery.cookie and it works:
Only loads Google Translate if cookie have been set