[Django] #32479: LocaleMiddleware not recognising properly zh-Hant-HK from the accept-language header

9 views
Skip to first unread message

Django

unread,
Feb 23, 2021, 2:20:08 PM2/23/21
to django-...@googlegroups.com
#32479: LocaleMiddleware not recognising properly zh-Hant-HK from the accept-
language header
-------------------------------------+-------------------------------------
Reporter: mpasseri | Owner: nobody
Type: Bug | Status: new
Component: | Version: 2.2
Internationalization | Keywords: translation,
Severity: Normal | internationalization, locale
Triage Stage: | middleware
Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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}}}.

--
Ticket URL: <https://code.djangoproject.com/ticket/32479>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 24, 2021, 1:59:01 AM2/24/21
to django-...@googlegroups.com
#32479: LocaleMiddleware not recognising properly zh-Hant-HK from the accept-
language header
-------------------------------------+-------------------------------------
Reporter: Marco Passeri | Owner: nobody

Type: Bug | Status: new
Component: | Version: 2.2
Internationalization |
Severity: Normal | Resolution:
Keywords: translation, | Triage Stage: Accepted
internationalization, locale |
middleware |

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* cc: Claude Paroz (added)
* stage: Unreviewed => Accepted


Comment:

Thanks for this ticket, as far as I'm aware `zh-Hant-HK` is a valid
language tag (see [http://www.iana.org/assignments/language-subtag-
registry/language-subtag-registry Language Subtag Registry]), we should
probably add `zh-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?

--
Ticket URL: <https://code.djangoproject.com/ticket/32479#comment:1>

Django

unread,
Apr 29, 2021, 6:49:31 PM4/29/21
to django-...@googlegroups.com
#32479: LocaleMiddleware not recognising properly zh-Hant-HK from the accept-
language header
-------------------------------------+-------------------------------------
Reporter: Marco Passeri | Owner: nobody

Type: Bug | Status: new
Component: | Version: 2.2
Internationalization |
Severity: Normal | Resolution:
Keywords: translation, | Triage Stage: Accepted
internationalization, locale |
middleware |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Cup0fCoffee):

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
[https://github.com/django/django/pull/14334 PR], in case the proposed
solutions 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.

--
Ticket URL: <https://code.djangoproject.com/ticket/32479#comment:2>

Django

unread,
Apr 30, 2021, 1:35:15 AM4/30/21
to django-...@googlegroups.com
#32479: LocaleMiddleware not recognising properly zh-Hant-HK from the accept-
language header
-------------------------------------+-------------------------------------
Reporter: Marco Passeri | Owner:
| Cup0fCoffee
Type: Bug | Status: assigned

Component: | Version: 2.2
Internationalization |
Severity: Normal | Resolution:
Keywords: translation, | Triage Stage: Accepted
internationalization, locale |
middleware |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* owner: nobody => Cup0fCoffee
* status: new => assigned
* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/32479#comment:3>

Django

unread,
Apr 30, 2021, 2:50:50 AM4/30/21
to django-...@googlegroups.com
#32479: LocaleMiddleware not recognising properly zh-Hant-HK from the accept-
language header
-------------------------------------+-------------------------------------
Reporter: Marco Passeri | Owner:
| Cup0fCoffee
Type: Bug | Status: assigned
Component: | Version: 2.2
Internationalization |
Severity: Normal | Resolution:
Keywords: translation, | Triage Stage: Accepted
internationalization, locale |
middleware |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Claude Paroz):

As posted on the PR, I'd like to explore the automatic fallback in such
cases. If anyone beats me with this, feel free…

--
Ticket URL: <https://code.djangoproject.com/ticket/32479#comment:4>

Django

unread,
Apr 30, 2021, 3:05:31 AM4/30/21
to django-...@googlegroups.com
#32479: LocaleMiddleware not recognising properly zh-Hant-HK from the accept-
language header
-------------------------------------+-------------------------------------
Reporter: Marco Passeri | Owner:
| Cup0fCoffee
Type: Bug | Status: assigned
Component: | Version: 2.2
Internationalization |
Severity: Normal | Resolution:
Keywords: translation, | Triage Stage: Accepted
internationalization, locale |
middleware |
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_tests: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/32479#comment:5>

Django

unread,
May 1, 2021, 5:55:57 AM5/1/21
to django-...@googlegroups.com
#32479: LocaleMiddleware not recognising properly zh-Hant-HK from the accept-
language header
-------------------------------------+-------------------------------------
Reporter: Marco Passeri | Owner:
| Cup0fCoffee
Type: Bug | Status: assigned
Component: | Version: 2.2
Internationalization |
Severity: Normal | Resolution:
Keywords: translation, | Triage Stage: Accepted
internationalization, locale |
middleware |
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Claude Paroz):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/32479#comment:6>

Django

unread,
May 4, 2021, 4:32:44 AM5/4/21
to django-...@googlegroups.com
#32479: LocaleMiddleware not recognising properly zh-Hant-HK from the accept-
language header
-------------------------------------+-------------------------------------
Reporter: Marco Passeri | Owner:
| Cup0fCoffee
Type: Bug | Status: assigned
Component: | Version: 2.2
Internationalization |
Severity: Normal | Resolution:
Keywords: translation, | Triage Stage: Ready for
internationalization, locale | checkin
middleware |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 1 => 0
* needs_tests: 1 => 0
* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/32479#comment:7>

Django

unread,
May 5, 2021, 4:30:47 AM5/5/21
to django-...@googlegroups.com
#32479: LocaleMiddleware not recognising properly zh-Hant-HK from the accept-
language header
-------------------------------------+-------------------------------------
Reporter: Marco Passeri | Owner:
| Cup0fCoffee
Type: Bug | Status: closed
Component: | Version: 2.2
Internationalization |
Severity: Normal | Resolution: fixed

Keywords: translation, | Triage Stage: Ready for
internationalization, locale | checkin
middleware |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"06fd4df41afb5aa1d681b853c3c08d8c688ca3a5" 06fd4df4]:
{{{
#!CommitTicketReference repository=""
revision="06fd4df41afb5aa1d681b853c3c08d8c688ca3a5"
Fixed #32479 -- Added fallbacks to subsequent language codes in
translations.

Thanks Claude Paroz and Nick Pope for reviews.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32479#comment:8>

Reply all
Reply to author
Forward
0 new messages