Welcome Guest, Not a member yet? Register   Sign In
setlocale() seems to do nothing
#1

(This post was last modified: 04-28-2023, 02:24 PM by sjender.)

Hello,
I want to give my users the option to change their locale (only for their account).
I read the locale can be set by using `$this->request->setLocale('nl');`.
But this still prints 'en'.
PHP Code:
        $this->request->setLocale('nl');
        echo $this->request->getLocale();
       
//output: en 

And still the english language files are used.
Is there a way I can dynamicly change the locale (without using the locale in the url) ?
Reply
#2

You need to set $supportedLocales:
https://github.com/codeigniter4/CodeIgni...pp.php#L99
Reply
#3

Updated the docs.
See https://codeigniter4.github.io/CodeIgnit...ent-locale
Reply
#4

Thanks, that partially did the trick.
Now the getLocale() prints 'nl' instead of 'en'.
Ik have placed '$this->request->setLocale('nl)' on top of my controller method.
But still the english language files are loaded...

If I change the $defaultLocale in Config/App.php it does switch to the NL language files.
Reply
#5

You need to run $this->request->setLocale('nl') before calling lang().

Or set locale on Language:
PHP Code:
$language Services::language();
$language->setLocale('nl'); 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB