Opened 5 weeks ago

Last modified 5 weeks ago

#35973 closed Bug

makemessages: is_valid_locale regex fails to validate locales with numeric region codes — at Version 3

Reported by: Juan Pablo Mallarino Owned by:
Component: Internationalization Version: 4.2
Severity: Normal Keywords: makemessages, i18n
Cc: Juan Pablo Mallarino 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 (last modified by Juan Pablo Mallarino)

The is_valid_locale function in the makemessages management command uses a regular expression that doesn't account for locales with numeric region codes, such as es_419. The current regex only allows uppercase letters after the underscore. This excludes valid locale codes that use numbers in the region subtag.

This can cause issues when trying to generate message files for these locales. For example, running makemessages with es_419 will not generate the expected message files, potentially leading to missing translations.

Proposed Solution

Modify the regular expression in is_valid_locale to include numeric characters in the region subtag validation. The suggested change is:

From:

r"^[a-z]+_[A-Z].*$"

To:

r"^[a-z]+_[A-Z0-9].*$"

This change would allow the validation of locales while still maintaining the expected format for other locale codes. This simple modification would ensure broader compatibility and avoid unexpected behavior when working with valid locales containing numeric region codes.

Change History (3)

comment:1 by Juan Pablo Mallarino, 5 weeks ago

Description: modified (diff)

comment:2 by Juan Pablo Mallarino, 5 weeks ago

Description: modified (diff)

This is the PR that introduced the validating function: https://github.com/django/django/pull/15521 and the issue https://code.djangoproject.com/ticket/33565

comment:3 by Juan Pablo Mallarino, 5 weeks ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top