Fixed #27868 -- Filtered locale path subdirectories

Thanks Tim Graham for the review.
This commit is contained in:
Claude Paroz 2017-02-22 21:59:12 +01:00
parent e6065c7b83
commit 30c984b3f9
2 changed files with 18 additions and 1 deletions

View File

@ -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:

View File

@ -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):