#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.
>
> 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.

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:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019393f635db-9185a3d9-fadf-43dd-a88b-83b5ebcb131b-000000%40eu-central-1.amazonses.com.

Reply via email to