Description
PHP Version
8.3
CodeIgniter4 Version
4.5.5
CodeIgniter4 Installation Method
Manual (zip or tar.gz)
Which operating systems have you tested for this bug?
Linux
Which server did you use?
apache
Database
No response
What happened?
public string $defaultLocale = 'en-US';
public bool $negotiateLocale = true;
public array $supportedLocales = ['en-US','en-GB'];
why like this ? Because i want to show different content for United Kingdom vs United States
Steps to Reproduce
to reproduce you must place UK first instead of the US
The app does not have {locale} specific routes
in your view just put it should always be equal to the $Request->getLocale()
In my Language Folder
I have them in separate folders en-US and en-GB
In the request header i have this
accept-language: en-US,en-GB;q=0.9,en;q=0.8,ro;q=0.7
and if i switch to English - United Kingdom the accept-language changes to this
accept-language:en-GB;en-US;q=0.9,en;q=0.8,ro;q=0.7
Expected Output
When i have the United Kingdom version as my default i should see
when i get the Locale from the Request the en-GB version instead of the en-US
echo $Request->getLocale(); always output en-US in both cases
it should return the en-GB version !
The problem is why is this happening is because of this file
https://github.com/codeigniter4/CodeIgniter4/blob/develop/system/HTTP/Negotiate.php#L181
There is a loop over the Supported languages and the first two are both english from my SupportedLocales so it returns only the first Locale matched and not the exact matched one.
I have test this it only works when i change the order from the
App Config
public array $supportedLocales = ['en-US','en-GB']; always shows the US page even if you have the default language en-GB
public array $supportedLocales = ['en-GB','en-US']; always shows the GB page even if you have the default language en-US.
Anything else?
No response