-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: Matching Locale with Negotiate Locale does not work in some cases as expected #9256
Comments
The problem here is that we want a loose comparison for locales most of the time. Setting the last variable to Should we make that configurable? Is it worth creating another config file/property? Personally, I'm not convinced, although I would like to hear other people's opinions. The instant solution would be to extend the Anyway, not really a bug, maybe a missing feature. |
Hello, For example, if I create a page in French at /fr/mypage (/{locale}/mypage) I'm not sure if this issue is related? Thanks. |
@ALTITUDE-DEV-FR No, I don't think so. Please make sure you have updated the |
So any update on this, because from my POV the negotiate locale does not do what it says "Once this is enabled, the system will automatically negotiate the correct language based upon an array of locales that you have defined in $supportLocales. If no match is found between the languages that you support, and the requested language, the first item in $supportedLocales will be used. In the following example, the en locale would be used if no match is found:" It just does not do that So it appears that it does not find en-GB but it find en-US Entering from en-GB returns en-US because from the algorithm there who wrote that searches for the first segment of the string "en" so it matches then returns the first from the array, even thoug i have exact match on en-GB still returns en-US how come this is not a bug |
As I explained in my first post:
The intention here was quite clear if you look at the current implementation - locale subtypes are matched to a broad type. The examples in the user guide also fit into this scenario. Feel free to send a PR with improvements. |
Well i have managed to get it working but i don't know man how to PR ! can i just put the code here and you manage it ?
with this it returns the exact match if exist despite the order of SupportedLocales array "loose comparison my ass" getBestMatch execution time: 4.0054321289062E-5 seconds |
No, sorry - this is not how open-source works. You may find this helpful: https://github.com/codeigniter4/CodeIgniter4/blob/develop/contributing/pull_request.md However, I don’t think we will accept changes that reinvent the wheel and duplicate methods we already have. |
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?
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
The text was updated successfully, but these errors were encountered: