Opened 4 years ago
Closed 4 years ago
#32479 closed Bug (fixed)
LocaleMiddleware not recognising properly zh-Hant-HK from the accept-language header
Reported by: | Marco Passeri | Owned by: | Cup0fCoffee |
---|---|---|---|
Component: | Internationalization | Version: | 2.2 |
Severity: | Normal | Keywords: | translation, internationalization, locale middleware |
Cc: | Claude Paroz | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
If both zh-hans
and zh-hant
are in settings.LANGUAGES
(and in this order) the LocaleMiddleware is choosing the first one instead of the second as would be expected. The actual faulty code seems to be in django.utils.translation.trans_real.get_supported_language_variant
.
Change History (8)
comment:1 by , 4 years ago
Cc: | added |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 4 years ago
Hi, I thought of different solutions, and it seems to me like the one proposed by Mariusz Felisiak is the most appropriate, so I've added a PR, in case the proposed solution gets accepted.
My only concern is should the match be case sensitive or not? I.e. should zh-hant-HK
and zh-hant-hk
match to zh-Hant-HK
? I think, the current implementation will not match them.
comment:3 by , 4 years ago
Has patch: | set |
---|---|
Owner: | changed from | to
Status: | new → assigned |
comment:4 by , 4 years ago
As posted on the PR, I'd like to explore the automatic fallback in such cases. If anyone beats me with this, feel free…
comment:5 by , 4 years ago
Needs tests: | set |
---|
comment:6 by , 4 years ago
Patch needs improvement: | set |
---|
comment:7 by , 4 years ago
Needs tests: | unset |
---|---|
Patch needs improvement: | unset |
Triage Stage: | Accepted → Ready for checkin |
Thanks for this ticket, as far as I'm aware
zh-Hant-HK
is a valid language tag (see Language Subtag Registry), we should probably addzh-Hant-HK
and others to fallbacks:zh-hans
:zh-Hans-CN
,zh-Hans-HK
,zh-Hans-MO
,zh-Hans-SG
,zh-Hans-TW
,zh-hant
:zh-Hant-CN
,zh-Hant-HK
,zh-Hant-MO
,zh-Hant-SG
,zh-Hant-TW
.What do you think Claude?