![]() |
Change language dynamically CI 4.4.6 - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: Change language dynamically CI 4.4.6 (/showthread.php?tid=90404) |
Change language dynamically CI 4.4.6 - serialkiller - 03-13-2024 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. RE: Change language dynamically CI 4.4.6 - JustJohnQ - 03-13-2024 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. RE: Change language dynamically CI 4.4.6 - serialkiller - 03-13-2024 (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 RE: Change language dynamically CI 4.4.6 - JustJohnQ - 03-13-2024 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 RE: Change language dynamically CI 4.4.6 - serialkiller - 03-14-2024 (03-13-2024, 09:00 AM)JustJohnQ Wrote: Sorry, Thanks, I think I solved it |