Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

[Django] #35973: makemessages: is_valid_locale regex fails to validate locales with numeric region codes

15 views
Skip to first unread message

Django

unread,
Dec 4, 2024, 3:50:30 PM12/4/24
to django-...@googlegroups.com
#35973: makemessages: is_valid_locale regex fails to validate locales with numeric
region codes
-------------------------------------+-------------------------------------
Reporter: Juan Pablo | Type:
Mallarino | Uncategorized
Status: new | Component:
| Internationalization
Version: 4.2 | Severity: Normal
Keywords: makemessages, i18n | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
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 r"^[a-z]+_[A-Z].*$" 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 like es_419 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.
--
Ticket URL: <https://code.djangoproject.com/ticket/35973>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 4, 2024, 3:57:24 PM12/4/24
to django-...@googlegroups.com
#35973: makemessages: is_valid_locale regex fails to validate locales with numeric
region codes
-------------------------------------+-------------------------------------
Reporter: Juan Pablo | Owner: (none)
Mallarino |
Type: Uncategorized | Status: new
Component: | Version: 4.2
Internationalization |
Severity: Normal | Resolution:
Keywords: makemessages, i18n | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Juan Pablo Mallarino:

Old description:

> 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 r"^[a-z]+_[A-Z].*$" 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 like es_419 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.

New description:

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.

--
--
Ticket URL: <https://code.djangoproject.com/ticket/35973#comment:1>

Django

unread,
Dec 4, 2024, 4:13:20 PM12/4/24
to django-...@googlegroups.com
#35973: makemessages: is_valid_locale regex fails to validate locales with numeric
region codes
-------------------------------------+-------------------------------------
Reporter: Juan Pablo | Owner: (none)
Mallarino |
Type: Uncategorized | Status: new
Component: | Version: 4.2
Internationalization |
Severity: Normal | Resolution:
Keywords: makemessages, i18n | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Old description:
Proposed Solution `hello how are you?`

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.

--
Comment (by Juan Pablo Mallarino):

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
--
Ticket URL: <https://code.djangoproject.com/ticket/35973#comment:2>

Django

unread,
Dec 4, 2024, 6:16:52 PM12/4/24
to django-...@googlegroups.com
#35973: makemessages: is_valid_locale regex fails to validate locales with numeric
region codes
-------------------------------------+-------------------------------------
Reporter: Juan Pablo | Owner: (none)
Mallarino |
Type: Uncategorized | Status: new
Component: | Version: 4.2
Internationalization |
Severity: Normal | Resolution:
Keywords: makemessages, i18n | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Juan Pablo Mallarino:

Old description:

> 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.
>
--
Ticket URL: <https://code.djangoproject.com/ticket/35973#comment:3>

Django

unread,
Dec 5, 2024, 4:47:25 AM12/5/24
to django-...@googlegroups.com
#35973: makemessages: is_valid_locale regex fails to validate locales with numeric
region codes
--------------------------------------+------------------------------------
Reporter: Juan Pablo Mallarino | Owner: (none)
Type: Bug | Status: new
Component: Internationalization | Version: 4.2
Severity: Normal | Resolution:
Keywords: makemessages, i18n | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Sarah Boyce):

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

Comment:

Support for regions was added in #33078 (see also test case like
`de-1996`)
The validation added in #33565 doesn't match this
--
Ticket URL: <https://code.djangoproject.com/ticket/35973#comment:4>

Django

unread,
Dec 5, 2024, 8:34:31 AM12/5/24
to django-...@googlegroups.com
#35973: makemessages: is_valid_locale regex fails to validate locales with numeric
region codes
--------------------------------------+------------------------------------
Reporter: Juan Pablo Mallarino | Owner: (none)
Type: Bug | Status: new
Component: Internationalization | Version: 4.2
Severity: Normal | Resolution:
Keywords: makemessages, i18n | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Juan Pablo Mallarino):

* has_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/35973#comment:5>

Django

unread,
Dec 5, 2024, 9:09:44 AM12/5/24
to django-...@googlegroups.com
#35973: makemessages: is_valid_locale regex fails to validate locales with numeric
region codes
-------------------------------------+-------------------------------------
Reporter: Juan Pablo | Owner: Juan
Mallarino | Pablo Mallarino
Type: Bug | Status: assigned
Component: | Version: 4.2
Internationalization |
Severity: Normal | Resolution:
Keywords: makemessages, i18n | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* owner: (none) => Juan Pablo Mallarino
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/35973#comment:6>

Django

unread,
Dec 6, 2024, 7:44:52 AM12/6/24
to django-...@googlegroups.com
#35973: makemessages: is_valid_locale regex fails to validate locales with numeric
region codes
-------------------------------------+-------------------------------------
Reporter: Juan Pablo | Owner: Juan
Mallarino | Pablo Mallarino
Type: Bug | Status: assigned
Component: | Version: 4.2
Internationalization |
Severity: Normal | Resolution:
Keywords: makemessages, i18n | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* stage: Accepted => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/35973#comment:7>

Django

unread,
Dec 7, 2024, 5:55:31 PM12/7/24
to django-...@googlegroups.com
#35973: makemessages: is_valid_locale regex fails to validate locales with numeric
region codes
-------------------------------------+-------------------------------------
Reporter: Juan Pablo | Owner: Juan
Mallarino | Pablo Mallarino
Type: Bug | Status: assigned
Component: | Version: 4.2
Internationalization |
Severity: Normal | Resolution:
Keywords: makemessages, i18n | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Juan Pablo Mallarino):

PR: https://github.com/django/django/pull/18888
--
Ticket URL: <https://code.djangoproject.com/ticket/35973#comment:8>

Django

unread,
Dec 9, 2024, 2:32:21 AM12/9/24
to django-...@googlegroups.com
#35973: makemessages: is_valid_locale regex fails to validate locales with numeric
region codes
-------------------------------------+-------------------------------------
Reporter: Juan Pablo | Owner: Juan
Mallarino | Pablo Mallarino
Type: Bug | Status: closed
Component: | Version: 4.2
Internationalization |
Severity: Normal | Resolution: fixed
Keywords: makemessages, i18n | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce <42296566+sarahboyce@…>):

* resolution: => fixed
* status: assigned => closed

Comment:

In [changeset:"08feaae5885f5719b8a7471b19f0d7e720b2137e" 08feaae]:
{{{#!CommitTicketReference repository=""
revision="08feaae5885f5719b8a7471b19f0d7e720b2137e"
Fixed #35973 -- Improved makemessages locale validation to handle numeric
region codes.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35973#comment:9>
Reply all
Reply to author
Forward
0 new messages