Welcome Guest, Not a member yet? Register   Sign In
setLocale() doesn't change the language set by browser
#10

(07-27-2024, 06:53 PM)kenjis Wrote: @eelisland I think you can move the following code to Event pre_system.
https://codeigniter.com/user_guide/exten...ent-points

PHP Code:
        if (session()->has('locale'))
        {
            // Set site language to session locale value
            service('language')->setLocale(session('locale'));
        }
        else
        {
            // Save locale to session
            session()->set('locale'service('language')->getLocale());
        

@kenjis Thank you, just tested it and it works.

I realise, i have this in my app/Config/Events.php to maintain locale when user logout.

PHP Code:
/*
 * --------------------------------------------------------------------
 * Auth logout
 * --------------------------------------------------------------------
 * Maintain locale variable in session after logout 
 */
Events::on('logout', function ()
{
 
    session()->set('locale'service('language')->getLocale());
}); 
Reply


Messages In This Thread
RE: setLocale() doesn't change the language set by browser - by eelisland - 07-28-2024, 03:14 AM



Theme © iAndrew 2016 - Forum software by © MyBB