[Django] #36642: makemessages provides invalid locale suggestions when attempting to format the locale string

5 views
Skip to first unread message

Django

unread,
Oct 6, 2025, 2:24:16 PMOct 6
to django-...@googlegroups.com
#36642: makemessages provides invalid locale suggestions when attempting to format
the locale string
--------------------------+-----------------------------------------
Reporter: ontowhee | Type: Uncategorized
Status: new | Component: Uncategorized
Version: 5.2 | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------+-----------------------------------------
This bug is reported by the forum user "hfl" in
https://forum.djangoproject.com/t/invalid-locale-zh-hans-did-you-mean-zh-
hans/42829.

When an invalid locale is provided, makemessages will provide a suggested
valid locale. However, some locales are displayed with incorrect
capitalizations, because there is an attempt to parse and capitalize a
territory component in [lines
431-438](https://github.com/django/django/blob/main/django/core/management/commands/makemessages.py#L431-L438).
Not all locales contain a territory component.

The example from the forum post is,

{{{
$ python manage.py makemessages zh-hans
invalid locale zh-hans, did you mean zh_HAns?
}}}

where `zh-hans` is an invalid input, and the suggested locale `zh_HAns` is
also invalid. The correct suggestion should be `zh_Hans`.

I'm not familiar with translations, but I wonder if it would help to use a
dictionary lookup of the locales (with the keys as the locales in all
lowercase, and the values the actual locale with correct casing), instead
of relying on regular expressions to validate the locale in
`is_valid_locale()` and to format the locale.
--
Ticket URL: <https://code.djangoproject.com/ticket/36642>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 6, 2025, 2:27:43 PMOct 6
to django-...@googlegroups.com
#36642: makemessages provides invalid locale suggestions when attempting to format
the locale string
-------------------------------------+-------------------------------------
Reporter: ontowhee | Owner: ontowhee
Type: Uncategorized | Status: assigned
Component: | Version: 5.2
Internationalization |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by ontowhee):

* component: Uncategorized => Internationalization
* owner: (none) => ontowhee
* status: new => assigned

Comment:

If this ticket is accepted, it would be a good "quick win" ticket for
Djangonaut Space. I'm assigning it to myself it that's ok.
--
Ticket URL: <https://code.djangoproject.com/ticket/36642#comment:1>

Django

unread,
Oct 7, 2025, 10:16:11 PMOct 7
to django-...@googlegroups.com
#36642: makemessages provides invalid locale suggestions when attempting to format
the locale string
--------------------------------------+------------------------------------
Reporter: ontowhee | Owner: ontowhee
Type: Bug | Status: assigned
Component: Internationalization | Version: 5.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Natalia Bidart):

* stage: Unreviewed => Accepted
* type: Uncategorized => Bug

Comment:

Hello Lilian! Thank you for your ticket. I think there is definitely room
for improvement here, so I'm accepting the ticket on that basis.

A few notes on when I tried to reproduce:
* The command execution needs the `--locale` (or `-l`) param, otherwise I
wasn't able to reproduce. So:
{{{
$ python manage.py makemessages --locale zh-hans
invalid locale zh-hans, did you mean zh_HAns?
}}}
* Using `zh_HAns` did not return any error for me, instead it generated a
`locale/zh_HAns/LC_MESSAGES/django.po` file with the correct content.
* But surprisingly, I also typoed the command and ran `python manage.py
makemessages -l zh_HAns?` and it also generated a
`locale/zh_HAns\?/LC_MESSAGES/django.po` with the correct content!
--
Ticket URL: <https://code.djangoproject.com/ticket/36642#comment:2>

Django

unread,
Oct 8, 2025, 9:32:04 AM (14 days ago) Oct 8
to django-...@googlegroups.com
#36642: makemessages provides invalid locale suggestions when attempting to format
the locale string
-------------------------------------+-------------------------------------
Reporter: ontowhee | Owner: Stephen
| kihuni
Type: Bug | Status: assigned
Component: | Version: 5.2
Internationalization |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Stephen kihuni):

* owner: ontowhee => Stephen kihuni

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

Django

unread,
Oct 20, 2025, 2:33:35 AM (2 days ago) Oct 20
to django-...@googlegroups.com
#36642: makemessages provides invalid locale suggestions when attempting to format
the locale string
-------------------------------------+-------------------------------------
Reporter: ontowhee | Owner: Stephen
| kihuni
Type: Bug | Status: assigned
Component: | Version: 5.2
Internationalization |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Manish Tiwari):

I want to work on this issue, if it's not assigned can I start working on
this??
--
Ticket URL: <https://code.djangoproject.com/ticket/36642#comment:4>

Django

unread,
Oct 20, 2025, 2:45:10 AM (2 days ago) Oct 20
to django-...@googlegroups.com
#36642: makemessages provides invalid locale suggestions when attempting to format
the locale string
-------------------------------------+-------------------------------------
Reporter: ontowhee | Owner: Stephen
| kihuni
Type: Bug | Status: assigned
Component: | Version: 5.2
Internationalization |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by ontowhee):

Replying to [comment:4 Manish Tiwari]:
> I want to work on this issue, if it's not assigned can I start working
on this??

Thanks for your interest in contributing! However, this ticket is assigned
and currently being worked on. Please find another ticket.
--
Ticket URL: <https://code.djangoproject.com/ticket/36642#comment:5>
Reply all
Reply to author
Forward
0 new messages