Of course Bogo remembers each user’s language preference. It’s stored in the usermeta database table.
Hey there and thanks for responding. I think I didn’t explain myself properly. I said user but I should have said visitor. I don’t plan on having registration open for my site so the usermeta db table wouldn’t be accessed for site visitors. I would just like to save the language choice so that when the visitor returns, the site would load previous selection. I wonder if this is only done by cookies.
Thanks
Bogo sets lang cookie that contains the locale code of the front page the visitor last accessed.
Ok that’s pretty awesome! So in theory I can have a one-time popup as a language selector with a checkbox to remember preference? would that be difficult to implement? not that familiar with cookie control through a form or if doable either.
edit: btw thanks a lot, I really appreciate the support!
-
This reply was modified 9 years, 1 month ago by
orangeworx.
In theory, yes. Setting the cookie is done in bogo_init() in bogo/bogo.php, looking into the function will be a help.
Hello,
This thread partially runs along the lines of a question I have.
Currently we have a fully UK English website, we wish to have a small selection of pages available in a German alternative.
In tests we’re running if the visitor first hits a UK Only page, then browses to a page that has a German version, chooses German via the switcher, then browses away to a different page that’s UK Only… then when they return to a page with the German option, they are not automatically shown the German page.
I assume, by how you described your cookie working, as soon as they hit a page where only UK version exists, then the cookie amends to UK local for future pages.
I guess one work-around would be to have a German duplicate of EVERY page, even if that supposed German page actually kept its English text. But a better solution would be that the cookie keeps track of the actual switcher choice the visitor makes.
I added some lines of code to save user language on the following cases:
yoursite.com/?lang=en
yoursite.com/en
I only needed to show the right language that I already translated with loco translate plugin. With some extra changes it could be possible to show automatically the right language for the page.
$lang = bogo_get_lang_from_url();
if ( $lang && $closest = bogo_get_closest_locale( $lang ) ) {
bogo_set_cookie(bogo_get_closest_locale( $lang ));
return $bogo_locale = $closest;
}
if(isset($_COOKIE['lang'])) {
$default_locale = $_COOKIE['lang'];
}
return $bogo_locale = $default_locale;
}
function bogo_set_cookie($locale) {
setcookie( 'lang', $locale, 0, '/' );
}