Closed yura-f closed 8 years ago
I believe you should be able to do:
var myCurrentLang = lang.currentLang;
It always shows 'en'. Even if the cookie saved another language.
<script type="text/javascript">
// Create language switcher instance
var lang = new Lang();
lang.dynamic('es', 'js/langpack/es.json');
lang.init({
defaultLang: 'en'
});
console.log(lang.currentLang); //always 'en'
</script>
Hmm, it could be because you are effectively checking before the library has had a chance to read the cookie... can you place your console.log line at the end of the body tag? That way it wont execute until the code in the head tag has. If that doesn't fix it the other way would be to just read the cookie yourself. Since the cookie plugin is already loaded you can take advantage of that to get the cookie value.
Did it read cookies.
console.log ("langCookie =" + Cookies.get ('langCookie')); //current lang
The variant with end 'body' prints always 'en'.
Thank you!
Fantastic, glad I could help.
Hi! I want select menu item with current language. As the page loads to learn the current language?
Thank you!