-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Matching browser language only matches exact subtypes if browser specifies one #2513
Comments
I need to look at this because the whole point of that LanguageNegotiator class is to negotiate the closest match to the requested language. And by that account, it would match |
Thanks! |
Did a test of this.. Using the mutlilang-site skeleton package (untouched as it provides a variety of languages), then setting my browser to I also tested a different default language by making Perhaps its browser related? If you are using IE, can you try Chrome instead to see if it makes a difference? |
@ricardo118 Did you run into this, too? |
@mahagr @rhukster indeed i have several reports of this. Like Cherry mentions its the subparts that are no longer functional. Thing like es-ca wont get detected. I've also noticed some inconsistencies regarding capitalization. if you have for example pt-BR and the browser sends pt-br, it was not always matching properly. |
Following situation: Website has languages
en
andde
. Matching with browser language doesn't work as one would naively expect: I always got the default language.The reason this is the case is because the browser was sending
de-AT
on one test device anden-us
on the other, and neither matched with plainde
orat
.Looking at the code in
vendor/willdurand/negotiation/src/Negotiation/LanguageNegotiator.php
I see that this can never work in a sensible way unless the browser sends onlyen
/de
, because the logic seems to be: Base-part match is only ignored if browser sent*
, sub-part match is only ignored if browser sent nothing.In order for this to work, we would need to create a multitude of languages matching all compatible subtypes:
de-de
,de-at
,de-ch
,en-us
,en-uk
, ... which is not feasible.In my mind, it should also ignore the sub-part match if the page language option doesn't have one (and the base part matches), maybe with a lower priority then a language option with actually matching sub-part. Then it would work with
en
andde
as well as withde
(matching all ofde-de
,de-at
,de-ch
), if we wanted, for example.I solved my immediate issue by a patch in the
LanguageNegotiator.php
, but I didn't create a pull request for that one because I wanted to have it discussed - maybe there is a better way I'm overlooking?The text was updated successfully, but these errors were encountered: