Welcome Guest, Not a member yet? Register   Sign In
setLocale not working as I intended?
#5

(This post was last modified: 03-04-2022, 03:32 AM by Mano.)

(03-03-2022, 06:12 PM)kenjis Wrote: It is wired, because
Code:
Language::setLocale()
is a just setter.
https://github.com/codeigniter4/CodeIgni...ge.php#L70

Sorry I don't understand your answer. It means it is not working as a global variable?
should I set it in every controller?

ok, it seems I've found the solution.
At login or change password, I store the language variable ('it','en',etc...) into a session variable

PHP Code:
session()->set('user_language',$data['language']); 

then on BaseController.php i put this line:

PHP Code:
if (session()->get('user_language')){
    service('language')->setLocale(session()->get('user_language'));


now every page is correctly translated according to user selected language (that is stored into database user table and recovered at login). If session is not existing (i.e. user not logged in), pages are displayed with default language.
Reply


Messages In This Thread
setLocale not working as I intended? - by Mano - 03-03-2022, 10:20 AM
RE: setLocale not working as I intended? - by Mano - 03-04-2022, 03:12 AM



Theme © iAndrew 2016 - Forum software by © MyBB