Opened 3 years ago

Closed 3 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 Mariusz Felisiak, 3 years ago

Cc: Claude Paroz added
Triage Stage: UnreviewedAccepted

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 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?

comment:2 by Cup0fCoffee, 3 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.

Last edited 3 years ago by Cup0fCoffee (previous) (diff)

comment:3 by Mariusz Felisiak, 3 years ago

Has patch: set
Owner: changed from nobody to Cup0fCoffee
Status: newassigned

comment:4 by Claude Paroz, 3 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 Mariusz Felisiak, 3 years ago

Needs tests: set

comment:6 by Claude Paroz, 3 years ago

Patch needs improvement: set

comment:7 by Mariusz Felisiak, 3 years ago

Needs tests: unset
Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:8 by Mariusz Felisiak <felisiak.mariusz@…>, 3 years ago

Resolution: fixed
Status: assignedclosed

In 06fd4df4:

Fixed #32479 -- Added fallbacks to subsequent language codes in translations.

Thanks Claude Paroz and Nick Pope for reviews.

Note: See TracTickets for help on using tickets.
Back to Top