![]() |
I'm trying to change the language of my app.
I've tried inside the BaseController in the initController method in several ways PHP Code: $lingua = session('lingua'); or PHP Code: $lingua = session('lingua'); PHP Code: $lingua = session('lingua'); If I try to print these variables on the screen I receive: echo session('language'); returns "en" echo config('App')->defaultLocale; returns "en" echo $this->request->getLocale(); return 'it' If I manually change the value of public string $defaultLocale to 'en' or 'it' everything works and I see the app in the desired language What should I do to be able to change the language dynamically? I don't need the URL changed.
I am using the following code:
In the top navigation, I have a dropdown menu: Code: <ul aria-labelledby="dropdownSubMenu1" class="dropdown-menu border-0 shadow"> I have a controller in a folder language with the following code to set the language: PHP Code: public function set_language() This changes the language without changing the url.
(03-13-2024, 08:35 AM)JustJohnQ Wrote: I am using the following code: I don't see where you set the value of the app language, I only see a setting of a session value that I already have, my problem is that I can't change the language or I can't change the defaultLocale value, if I I do it by hand works correctly but I can't modify it from code, i.e. based on the value of session('lang'). I don't use the URL like /home/en, I don't need it, I just need to be able to change the language of everything
Sorry,
My answer was incomplete. The default language is set in the initController function in the BaseController: PHP Code: $session = \Config\Services::session(); Hope this helps
(03-13-2024, 09:00 AM)JustJohnQ Wrote: Sorry, Thanks, I think I solved it |
Welcome Guest, Not a member yet? Register Sign In |