summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormanav014 <dpsman13016@gmail.com>2020-10-27 17:22:30 +0530
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-11-13 09:25:42 +0100
commitf63f3cdf0969c23fd0c05de0f4a2a1df0cd5112e (patch)
tree275b6970b40becf02d1fd13fa8dcf1b6fd3a0a5c
parent8ed024b9b9ca4491fcb17cb15b3b5f18a8f60ff8 (diff)
Fixed #29712 -- Made makemessages warn if locales have hyphens and skip them.
-rw-r--r--AUTHORS1
-rw-r--r--django/core/management/commands/makemessages.py8
-rw-r--r--docs/releases/3.2.txt4
-rw-r--r--tests/i18n/test_extraction.py14
4 files changed, 27 insertions, 0 deletions
diff --git a/AUTHORS b/AUTHORS
index 5f1ca7cceb..3dd968351b 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -564,6 +564,7 @@ answer newbie questions, and generally made Django that much better:
Mads Jensen <https://github.com/atombrella>
Makoto Tsuyuki <mtsuyuki@gmail.com>
Malcolm Tredinnick
+ Manav Agarwal <dpsman13016@gmail.com>
Manuel Saelices <msaelices@yaco.es>
Manuzhai
Marc Aymerich Gubern
diff --git a/django/core/management/commands/makemessages.py b/django/core/management/commands/makemessages.py
index 593381c2f4..7aa184b02d 100644
--- a/django/core/management/commands/makemessages.py
+++ b/django/core/management/commands/makemessages.py
@@ -383,6 +383,14 @@ class Command(BaseCommand):
# Build po files for each selected locale
for locale in locales:
+ if '-' in locale:
+ self.stdout.write(
+ 'invalid locale %s, did you mean %s?' % (
+ locale,
+ locale.replace('-', '_'),
+ ),
+ )
+ continue
if self.verbosity > 0:
self.stdout.write('processing locale %s' % locale)
for potfile in potfiles:
diff --git a/docs/releases/3.2.txt b/docs/releases/3.2.txt
index 0a12e2168c..83b717893e 100644
--- a/docs/releases/3.2.txt
+++ b/docs/releases/3.2.txt
@@ -600,6 +600,10 @@ Miscellaneous
* The password reset mechanism now invalidates tokens when the user email is
changed.
+* :djadmin:`makemessages` command no longer processes invalid locales specified
+ using :option:`makemessages --locale` option, when they contain hyphens
+ (``'-'``).
+
.. _deprecated-features-3.2:
Features deprecated in 3.2
diff --git a/tests/i18n/test_extraction.py b/tests/i18n/test_extraction.py
index a6a0060910..73336816cb 100644
--- a/tests/i18n/test_extraction.py
+++ b/tests/i18n/test_extraction.py
@@ -152,6 +152,20 @@ class BasicExtractorTests(ExtractorTests):
with self.assertRaisesRegex(CommandError, msg):
management.call_command('makemessages')
+ def test_valid_locale(self):
+ out = StringIO()
+ management.call_command('makemessages', locale=['de'], stdout=out, verbosity=1)
+ self.assertNotIn('invalid locale de', out.getvalue())
+ self.assertIn('processing locale de', out.getvalue())
+ self.assertIs(Path(self.PO_FILE).exists(), True)
+
+ def test_invalid_locale(self):
+ out = StringIO()
+ management.call_command('makemessages', locale=['pl-PL'], stdout=out, verbosity=1)
+ self.assertIn('invalid locale pl-PL, did you mean pl_PL?', out.getvalue())
+ self.assertNotIn('processing locale pl-PL', out.getvalue())
+ self.assertIs(Path('locale/pl-PL/LC_MESSAGES/django.po').exists(), False)
+
def test_comments_extractor(self):
management.call_command('makemessages', locale=[LOCALE], verbosity=0)
self.assertTrue(os.path.exists(self.PO_FILE))