![]() |
Why doesn't $request->getLocale() return the correct locale any more (since v.4.3)? - 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: Why doesn't $request->getLocale() return the correct locale any more (since v.4.3)? (/showthread.php?tid=88355) |
Why doesn't $request->getLocale() return the correct locale any more (since v.4.3)? - gosocial2 - 08-27-2023 I noticed that the last time $request->getLocale() returned the correct locale based on the URI was with CI_VERSION 4.2.x How I use it: PHP Code: class BaseController extends Controller app/Config/App.php : PHP Code: class App extends BaseConfig The routes: PHP Code: $routes->get('/', 'Home::index'); Expected behavior: When in a URL like http://localhost:8080/fr/cp/countries, $currentLocale in the view equals "fr". In CodeIgniter 4.2.5: $currentLocale gets set as "fr" In CodeIgniter 4.3.x: $currentLocale gets set as "en" probably what's set as the default locale in app/Config/App.php (i.e. on a page in French, locale is returned as English) Why? And how to get "fr" from http://localhost:8080/fr/... now in CI 4.3.x and 4.4.x? RE: Why doesn't $request->getLocale() return the correct locale any more (since v.4.3)? - kenjis - 08-27-2023 In 4.4, I cannot reproduce. Code: diff --git a/app/Config/App.php b/app/Config/App.php Code: diff --git a/app/Config/Routes.php b/app/Config/Routes.php Code: diff --git a/app/Controllers/BaseController.php b/app/Controllers/BaseController.php Code: diff --git a/app/Controllers/Home.php b/app/Controllers/Home.php Navigate to http://localhost:8080/fr/cp , I see "fr". RE: Why doesn't $request->getLocale() return the correct locale any more (since v.4.3)? - kenjis - 08-27-2023 I checked v4.3.8, and I cannot reproduce it. I also see "fr". RE: Why doesn't $request->getLocale() return the correct locale any more (since v.4.3)? - InsiteFX - 08-27-2023 I'm using IncludeBeers Create a Multilingual Website and it is working fine here with CodeIgniter 4.4.0. Creating a multilingual website with CodeIgniter 4 (part 1) Creating a multilingual website with CodeIgniter 4 (part 2) RE: Why doesn't $request->getLocale() return the correct locale any more (since v.4.3)? - gosocial2 - 08-30-2023 Sorry, but the problem persists. I not only tried all the steps in the documentation, but also the tutorial above. Working app based on CI 4.2.x is at https://ccpdemo2.ozar.net - it can be tested by selecting a language from the dropdown in the right hand side of the top navbar. When all the code in this app is copied over to CI 4.3.x, it breaks and language selection menu always takes the user to an English page. May I request, those who assert no such problem exists, describe all the steps to reproduce a working solution testing also with the Safari browser? Can't do withouts: The URLs to be tested need to be created using routes that will reside in the below route groups. PHP Code: $routes->group('{locale}/cp', [], function($routes) { PHP Code: $routes->group('{locale}/admin', [], function($routes) { |