Problem/Motivation
When the language detection is configured to follow the order of
- User's selected language
- Language from URL
and the site default language matches the language configured by the user, the detection will ignore the first negotiation step.
This is because LanguageNegotiationUser::getLangcode()
will return NULL due to the conditional statement in the method:
if (!empty($preferred_langcode) && $preferred_langcode != $default_langcode && isset($languages[$preferred_langcode])) {
(see $preferred_langcode != $default_langcode
).
Which prevents the site builder from using a different language to be detected for authenticated vs anonymous users.
Proposed resolution
Remove the check against preferred and default langcodes from the plugin.
Comment | File | Size | Author |
---|---|---|---|
#14 | user_language-2726505-14.patch | 1.11 KB | Matt_five |
#3 | user_language-2726505-3.patch | 1.03 KB | snufkin |
Comments
Comment #2
snufkin CreditAttribution: snufkin at Acquia commentedComment #3
snufkin CreditAttribution: snufkin at Acquia commentedComment #5
yoruvo CreditAttribution: yoruvo commentedI have just applied the above patch and it fixed the following problem for me:
I consider this a fairly critical bugfix, so I've bumped up the priority and changed the status to "reviewed".
Comment #6
catchPatch looks fine, but we should have test coverage for this.
Comment #8
Matt_five CreditAttribution: Matt_five commentedI get the same problem. The patch of @snufkin at #3 work for me.
I support to remove
$preferred_langcode != $default_langcode
because it destroy the order of language detection. It is very odd to return NULL when user prefer language (valid value e.g. en, fr) is equal to default language (e.g. en, fr).Then, I study the test coverage.
LanguageUILanguageNegotiationTest
fail at followings:---------------------------------------------------------------------------------------------
1. "Set preferred langcode for user to NULL." at line #230-243
2. "Set preferred langcode for user to unknown language." at line #245-258
The above test case enable the "User's selected language", and expected
LanguageNegotiationUser::getLangcode()
returnNull
.Here is the code of the patch#3.
The function
getPreferredLangcode()
do have a fall back option. Please check the manual.8.2.x User.php User::getPreferredLangcode($fallback_to_default = TRUE)
After applying the patch #3,
LanguageNegotiationUser::getLangcode()
return default value (e.g. en) other than it's own value (null or unknow-value).I would like to stop the fallback action by
With this supplement, the return of the Language detection of "User's prefer language" would be totally independent to other detection method. It can ensure "User's prefer language" return valid value OR language Negotiation go into next detection method if user's prefer language is invalid.
Please check the updated patch.
Comment #9
Matt_five CreditAttribution: Matt_five commentedPlease find the updated patch.
Comment #10
Matt_five CreditAttribution: Matt_five commentedComment #12
Matt_five CreditAttribution: Matt_five commentedPlease find the updated patch.
Comment #14
Matt_five CreditAttribution: Matt_five commentedPlease find the updated patch.
Comment #15
Matt_five CreditAttribution: Matt_five commentedComment #19
yoruvo CreditAttribution: yoruvo commentedPatch #14 continues to work like a charm on several production sites.
Comment #20
alexpottWe still need an automated test for this bugfix, as @catch said in #6
Comment #22
axroth CreditAttribution: axroth commentedI propose to close this as the patch seems -somehow- to be contained in 8.6.3 already?!
Comment #23
achtonThe problem described in this issue was solved independently in another issue: #2907546: User's language preference is not applied! and commited on 2018-09-11 so that it was included in 8.6.2.
The fix was the exact same as in this issue, except that it included tests as well.
So yes, this issue can be closed (presumably as a duplicate of the other).
Comment #29
smustgrave CreditAttribution: smustgrave at Mobomo commentedThis came up as a daily target for the bugsmash initiative
As pointed out in #23 this is a duplicate as the fix was committed in another issue. I will move over credit to that issue for
Matt_five
snufkin
For the patches they submitted.