﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
36642	makemessages provides invalid locale suggestions when attempting to format the locale string	ontowhee	Stephen kihuni	"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."	Bug	assigned	Internationalization	5.2	Normal			ontowhee	Accepted	1	0	0	1	0	0
