Skip to content

Commit

Permalink
Fixed #35973 -- Improved makemessages locale validation to handle num…
Browse files Browse the repository at this point in the history
…eric region codes.
  • Loading branch information
Juan Pablo Mallarino authored and sarahboyce committed Dec 9, 2024
1 parent d345e5b commit 08feaae
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion django/core/management/commands/makemessages.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def check_programs(*programs):


def is_valid_locale(locale):
return re.match(r"^[a-z]+$", locale) or re.match(r"^[a-z]+_[A-Z].*$", locale)
return re.match(r"^[a-z]+$", locale) or re.match(r"^[a-z]+_[A-Z0-9].*$", locale)


@total_ordering
Expand Down
9 changes: 9 additions & 0 deletions tests/i18n/test_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,15 @@ def test_valid_locale_with_country(self):
self.assertIn("processing locale en_GB", out.getvalue())
self.assertIs(Path("locale/en_GB/LC_MESSAGES/django.po").exists(), True)

def test_valid_locale_with_numeric_region_code(self):
out = StringIO()
management.call_command(
"makemessages", locale=["ar_002"], stdout=out, verbosity=1
)
self.assertNotIn("invalid locale ar_002", out.getvalue())
self.assertIn("processing locale ar_002", out.getvalue())
self.assertIs(Path("locale/ar_002/LC_MESSAGES/django.po").exists(), True)

def test_valid_locale_tachelhit_latin_morocco(self):
out = StringIO()
management.call_command(
Expand Down

0 comments on commit 08feaae

Please sign in to comment.