Opened 5 weeks ago

Last modified 3 weeks ago

#36642 assigned Bug

makemessages provides invalid locale suggestions when attempting to format the locale string

Reported by: ontowhee Owned by: Stephen kihuni
Component: Internationalization Version: 5.2
Severity: Normal Keywords:
Cc: ontowhee Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

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.

Change History (6)

comment:1 by ontowhee, 5 weeks ago

Component: UncategorizedInternationalization
Owner: set to ontowhee
Status: newassigned

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.

comment:2 by Natalia Bidart, 5 weeks ago

Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

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!

comment:3 by Stephen kihuni, 5 weeks ago

Owner: changed from ontowhee to Stephen kihuni

comment:4 by Manish Tiwari, 3 weeks ago

I want to work on this issue, if it's not assigned can I start working on this??

in reply to:  4 comment:5 by ontowhee, 3 weeks ago

Replying to 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.

comment:6 by Jacob Walls, 3 weeks ago

Has patch: set
Patch needs improvement: set
Note: See TracTickets for help on using tickets.
Back to Top