Detecting selected language
-
I am currently using this approach to determine the selected language:
How to detect current selected language? | GTranslate Help Center
/*
* If original language is selected, then the value of current_language
* will be empty. Otherwise, it will contain the current selected
* language code.
*
*/
var current_language = gt_get_cookie('googtrans').split('/').pop();
// W3 Schools: https://www.w3schools.com/js/js_cookies.asp
function gt_get_cookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}It works fine. But the problem is that I must use F5 to reload the page after the user changes the language. Otherwise the cookie doesn’t reflect the new setting.
This is not a hardship. But, I have a drop-down language selector at the top right on the site, available on all pages. Is it not possible to extract the value from there? This way my tawk.to form will function properly (at-least for English and Italian).
The page I need help with: [log in to see the link]
The topic ‘Detecting selected language’ is closed to new replies.