From 30c984b3f9f7f0249e4a900f6cce5c732c47cf83 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Wed, 22 Feb 2017 21:59:12 +0100 Subject: [PATCH] Fixed #27868 -- Filtered locale path subdirectories Thanks Tim Graham for the review. --- django/core/management/commands/makemessages.py | 6 +++++- tests/i18n/test_extraction.py | 13 +++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/django/core/management/commands/makemessages.py b/django/core/management/commands/makemessages.py index 17b1f05d5a..79c0ddb4d2 100644 --- a/django/core/management/commands/makemessages.py +++ b/django/core/management/commands/makemessages.py @@ -337,8 +337,12 @@ class Command(BaseCommand): os.makedirs(self.default_locale_path) # Build locale list + looks_like_locale = re.compile(r'[a-z]{2}') locale_dirs = filter(os.path.isdir, glob.glob('%s/*' % self.default_locale_path)) - all_locales = map(os.path.basename, locale_dirs) + all_locales = [ + lang_code for lang_code in map(os.path.basename, locale_dirs) + if looks_like_locale.match(lang_code) + ] # Account for excluded locales if process_all: diff --git a/tests/i18n/test_extraction.py b/tests/i18n/test_extraction.py index c0acd3f9f0..e6945f1014 100644 --- a/tests/i18n/test_extraction.py +++ b/tests/i18n/test_extraction.py @@ -604,6 +604,7 @@ class KeepPotFileExtractorTests(ExtractorTests): class MultipleLocaleExtractionTests(ExtractorTests): PO_FILE_PT = 'locale/pt/LC_MESSAGES/django.po' PO_FILE_DE = 'locale/de/LC_MESSAGES/django.po' + PO_FILE_KO = 'locale/ko/LC_MESSAGES/django.po' LOCALES = ['pt', 'de', 'ch'] def test_multiple_locales(self): @@ -611,6 +612,18 @@ class MultipleLocaleExtractionTests(ExtractorTests): self.assertTrue(os.path.exists(self.PO_FILE_PT)) self.assertTrue(os.path.exists(self.PO_FILE_DE)) + def test_all_locales(self): + """ + When the `locale` flag is absent, all dirs from the parent locale dir + are considered as language directories, except if the directory doesn't + start with two letters (which excludes __pycache__, .gitignore, etc.). + """ + os.mkdir(os.path.join('locale', '_do_not_pick')) + # Excluding locales that do not compile + management.call_command('makemessages', exclude=['ja', 'es_AR'], verbosity=0) + self.assertTrue(os.path.exists(self.PO_FILE_KO)) + self.assertFalse(os.path.exists('locale/_do_not_pick/LC_MESSAGES/django.po')) + class ExcludedLocaleExtractionTests(ExtractorTests):