Fixed #21488 -- Multiple locales treatment in i18n commands.

Removed multiple locales separated by commas variation (that wasn't
working as documented) in favor of simply allowing use of the
``--locale``/``-l`` options more than once for ``makemessages`` and
``compilemessages``.

Thanks Romain Beylerian for the report and Claude, Simon for their help.

8750296918 from stable/1.6.x.
This commit is contained in:
Ramiro Morales 2013-11-22 23:47:04 -03:00
parent ffc37e2343
commit 62b393c5ae
6 changed files with 37 additions and 45 deletions

View File

@ -35,7 +35,7 @@ def compile_messages(stdout, locale=None):
for basedir in basedirs:
if locale:
dirs = [os.path.join(basedir, l, 'LC_MESSAGES') for l in (locale if isinstance(locale, list) else [locale])]
dirs = [os.path.join(basedir, l, 'LC_MESSAGES') for l in locale]
else:
dirs = [basedir]
for ldir in dirs:
@ -61,7 +61,7 @@ def compile_messages(stdout, locale=None):
class Command(BaseCommand):
option_list = BaseCommand.option_list + (
make_option('--locale', '-l', dest='locale', action='append',
help='locale(s) to process (e.g. de_AT). Default is to process all. Can be used multiple times, accepts a comma-separated list of locale names.'),
help='locale(s) to process (e.g. de_AT). Default is to process all. Can be used multiple times.'),
)
help = 'Compiles .po files to .mo files for use with builtin gettext support.'

View File

@ -169,7 +169,7 @@ class Command(NoArgsCommand):
option_list = NoArgsCommand.option_list + (
make_option('--locale', '-l', default=None, dest='locale', action='append',
help='Creates or updates the message files for the given locale(s) (e.g. pt_BR). '
'Can be used multiple times, accepts a comma-separated list of locale names.'),
'Can be used multiple times.'),
make_option('--domain', '-d', default='django', dest='domain',
help='The domain of the message files (default: "django").'),
make_option('--all', '-a', action='store_true', dest='all',
@ -265,7 +265,7 @@ class Command(NoArgsCommand):
# Build po files for each selected locale
locales = []
if locale is not None:
locales += locale.split(',') if not isinstance(locale, list) else locale
locales = locale
elif process_all:
locale_dirs = filter(os.path.isdir, glob.glob('%s/*' % localedir))
locales = [os.path.basename(l) for l in locale_dirs]

View File

@ -119,8 +119,6 @@ Example usage::
django-admin.py compilemessages --locale=pt_BR --locale=fr
django-admin.py compilemessages -l pt_BR
django-admin.py compilemessages -l pt_BR -l fr
django-admin.py compilemessages --locale=pt_BR,fr
django-admin.py compilemessages -l pt_BR,fr
.. versionchanged:: 1.6
@ -533,11 +531,6 @@ Example usage::
django-admin.py makemessages -l pt_BR
django-admin.py makemessages -l pt_BR -l fr
You can also use commas to separate multiple locales::
django-admin.py makemessages --locale=de,fr,pt_BR
django-admin.py makemessages -l de,fr,pt_BR
.. versionchanged:: 1.6
Added the ability to specify multiple locales.

View File

@ -30,3 +30,8 @@ Bug fixes
key (#21472).
* Fixed a regression where custom querysets for foreign keys were overwritten
if ``ModelAdmin`` had ordering set (#21405).
* Removed mention of a feature in the ``--locale``/``-l`` option of
``makemessages`` and ``compilemessages`` commands that never worked as
promised: Support of multiple locale names separated by commas. It's still
possible to specify multiplle locales in one run by suing the option
multiple times (#21488, #17181).

View File

@ -33,7 +33,7 @@ class PoFileTests(MessageCompilationTests):
def test_bom_rejection(self):
with self.assertRaises(CommandError) as cm:
call_command('compilemessages', locale=self.LOCALE, stdout=StringIO())
call_command('compilemessages', locale=[self.LOCALE], stdout=StringIO())
self.assertIn("file has a BOM (Byte Order Mark)", cm.exception.args[0])
self.assertFalse(os.path.exists(self.MO_FILE))
@ -49,7 +49,7 @@ class PoFileContentsTests(MessageCompilationTests):
self.addCleanup(os.unlink, os.path.join(test_dir, self.MO_FILE))
def test_percent_symbol_in_po_file(self):
call_command('compilemessages', locale=self.LOCALE, stdout=StringIO())
call_command('compilemessages', locale=[self.LOCALE], stdout=StringIO())
self.assertTrue(os.path.exists(self.MO_FILE))
@ -67,7 +67,7 @@ class PercentRenderingTests(MessageCompilationTests):
@override_settings(LOCALE_PATHS=(os.path.join(test_dir, 'locale'),))
def test_percent_symbol_escaping(self):
from django.template import Template, Context
call_command('compilemessages', locale=self.LOCALE, stdout=StringIO())
call_command('compilemessages', locale=[self.LOCALE], stdout=StringIO())
with translation.override(self.LOCALE):
t = Template('{% load i18n %}{% trans "Looks like a str fmt spec %% o but shouldn\'t be interpreted as such" %}')
rendered = t.render(Context({}))
@ -92,7 +92,7 @@ class MultipleLocaleCompilationTests(MessageCompilationTests):
self.addCleanup(self.rmfile, os.path.join(localedir, self.MO_FILE_FR))
def test_one_locale(self):
call_command('compilemessages', locale='hr', stdout=StringIO())
call_command('compilemessages', locale=['hr'], stdout=StringIO())
self.assertTrue(os.path.exists(self.MO_FILE_HR))
@ -114,4 +114,4 @@ class CompilationErrorHandling(MessageCompilationTests):
def test_error_reported_by_msgfmt(self):
with self.assertRaises(CommandError):
call_command('compilemessages', locale=self.LOCALE, stdout=StringIO())
call_command('compilemessages', locale=[self.LOCALE], stdout=StringIO())

View File

@ -69,7 +69,7 @@ class BasicExtractorTests(ExtractorTests):
def test_comments_extractor(self):
os.chdir(self.test_dir)
management.call_command('makemessages', locale=LOCALE, verbosity=0)
management.call_command('makemessages', locale=[LOCALE], verbosity=0)
self.assertTrue(os.path.exists(self.PO_FILE))
with io.open(self.PO_FILE, 'r', encoding='utf-8') as fp:
po_contents = fp.read()
@ -97,7 +97,7 @@ class BasicExtractorTests(ExtractorTests):
def test_templatize_trans_tag(self):
# ticket #11240
os.chdir(self.test_dir)
management.call_command('makemessages', locale=LOCALE, verbosity=0)
management.call_command('makemessages', locale=[LOCALE], verbosity=0)
self.assertTrue(os.path.exists(self.PO_FILE))
with open(self.PO_FILE, 'r') as fp:
po_contents = force_text(fp.read())
@ -113,7 +113,7 @@ class BasicExtractorTests(ExtractorTests):
def test_templatize_blocktrans_tag(self):
# ticket #11966
os.chdir(self.test_dir)
management.call_command('makemessages', locale=LOCALE, verbosity=0)
management.call_command('makemessages', locale=[LOCALE], verbosity=0)
self.assertTrue(os.path.exists(self.PO_FILE))
with open(self.PO_FILE, 'r') as fp:
po_contents = force_text(fp.read())
@ -123,7 +123,7 @@ class BasicExtractorTests(ExtractorTests):
def test_blocktrans_trimmed(self):
os.chdir(self.test_dir)
management.call_command('makemessages', locale=LOCALE, verbosity=0)
management.call_command('makemessages', locale=[LOCALE], verbosity=0)
self.assertTrue(os.path.exists(self.PO_FILE))
with open(self.PO_FILE, 'r') as fp:
po_contents = force_text(fp.read())
@ -139,9 +139,9 @@ class BasicExtractorTests(ExtractorTests):
def test_extraction_error(self):
os.chdir(self.test_dir)
self.assertRaises(SyntaxError, management.call_command, 'makemessages', locale=LOCALE, extensions=['tpl'], verbosity=0)
self.assertRaises(SyntaxError, management.call_command, 'makemessages', locale=[LOCALE], extensions=['tpl'], verbosity=0)
with self.assertRaises(SyntaxError) as context_manager:
management.call_command('makemessages', locale=LOCALE, extensions=['tpl'], verbosity=0)
management.call_command('makemessages', locale=[LOCALE], extensions=['tpl'], verbosity=0)
six.assertRegex(
self, str(context_manager.exception),
r'Translation blocks must not include other block tags: blocktrans \(file templates[/\\]template_with_error\.tpl, line 3\)'
@ -154,7 +154,7 @@ class BasicExtractorTests(ExtractorTests):
shutil.copyfile('./not_utf8.sample', './not_utf8.txt')
self.addCleanup(self.rmfile, os.path.join(self.test_dir, 'not_utf8.txt'))
stdout = StringIO()
management.call_command('makemessages', locale=LOCALE, stdout=stdout)
management.call_command('makemessages', locale=[LOCALE], stdout=stdout)
self.assertIn("UnicodeDecodeError: skipped file not_utf8.txt in .",
force_text(stdout.getvalue()))
@ -164,7 +164,7 @@ class BasicExtractorTests(ExtractorTests):
shutil.copyfile('./code.sample', './code_sample.py')
self.addCleanup(self.rmfile, os.path.join(self.test_dir, 'code_sample.py'))
stdout = StringIO()
management.call_command('makemessages', locale=LOCALE, stdout=stdout)
management.call_command('makemessages', locale=[LOCALE], stdout=stdout)
self.assertIn("code_sample.py:4", force_text(stdout.getvalue()))
def test_template_message_context_extractor(self):
@ -174,7 +174,7 @@ class BasicExtractorTests(ExtractorTests):
Refs #14806.
"""
os.chdir(self.test_dir)
management.call_command('makemessages', locale=LOCALE, verbosity=0)
management.call_command('makemessages', locale=[LOCALE], verbosity=0)
self.assertTrue(os.path.exists(self.PO_FILE))
with open(self.PO_FILE, 'r') as fp:
po_contents = force_text(fp.read())
@ -200,7 +200,7 @@ class BasicExtractorTests(ExtractorTests):
def test_context_in_single_quotes(self):
os.chdir(self.test_dir)
management.call_command('makemessages', locale=LOCALE, verbosity=0)
management.call_command('makemessages', locale=[LOCALE], verbosity=0)
self.assertTrue(os.path.exists(self.PO_FILE))
with open(self.PO_FILE, 'r') as fp:
po_contents = force_text(fp.read())
@ -219,7 +219,7 @@ class BasicExtractorTests(ExtractorTests):
# translator comments syntax
with warnings.catch_warnings(record=True) as ws:
warnings.simplefilter('always')
management.call_command('makemessages', locale=LOCALE, extensions=['thtml'], verbosity=0)
management.call_command('makemessages', locale=[LOCALE], extensions=['thtml'], verbosity=0)
self.assertEqual(len(ws), 3)
for w in ws:
self.assertTrue(issubclass(w.category, TranslatorCommentWarning))
@ -279,7 +279,7 @@ class JavascriptExtractorTests(ExtractorTests):
def test_javascript_literals(self):
os.chdir(self.test_dir)
management.call_command('makemessages', domain='djangojs', locale=LOCALE, verbosity=0)
management.call_command('makemessages', domain='djangojs', locale=[LOCALE], verbosity=0)
self.assertTrue(os.path.exists(self.PO_FILE))
with open(self.PO_FILE, 'r') as fp:
po_contents = fp.read()
@ -307,7 +307,7 @@ class IgnoredExtractorTests(ExtractorTests):
'xxx_*',
]
stdout = StringIO()
management.call_command('makemessages', locale=LOCALE, verbosity=2,
management.call_command('makemessages', locale=[LOCALE], verbosity=2,
ignore_patterns=ignore_patterns, stdout=stdout)
data = stdout.getvalue()
self.assertTrue("ignoring directory ignore_dir" in data)
@ -351,7 +351,7 @@ class SymlinkExtractorTests(ExtractorTests):
except (OSError, NotImplementedError):
raise SkipTest("os.symlink() is available on this OS but can't be used by this user.")
os.chdir(self.test_dir)
management.call_command('makemessages', locale=LOCALE, verbosity=0, symlinks=True)
management.call_command('makemessages', locale=[LOCALE], verbosity=0, symlinks=True)
self.assertTrue(os.path.exists(self.PO_FILE))
with open(self.PO_FILE, 'r') as fp:
po_contents = force_text(fp.read())
@ -373,7 +373,7 @@ class CopyPluralFormsExtractorTests(ExtractorTests):
def test_copy_plural_forms(self):
os.chdir(self.test_dir)
management.call_command('makemessages', locale=LOCALE, verbosity=0)
management.call_command('makemessages', locale=[LOCALE], verbosity=0)
self.assertTrue(os.path.exists(self.PO_FILE))
with open(self.PO_FILE, 'r') as fp:
po_contents = force_text(fp.read())
@ -382,7 +382,7 @@ class CopyPluralFormsExtractorTests(ExtractorTests):
def test_override_plural_forms(self):
"""Ticket #20311."""
os.chdir(self.test_dir)
management.call_command('makemessages', locale='es', extensions=['djtpl'], verbosity=0)
management.call_command('makemessages', locale=['es'], extensions=['djtpl'], verbosity=0)
self.assertTrue(os.path.exists(self.PO_FILE_ES))
with io.open(self.PO_FILE_ES, 'r', encoding='utf-8') as fp:
po_contents = fp.read()
@ -394,7 +394,7 @@ class NoWrapExtractorTests(ExtractorTests):
def test_no_wrap_enabled(self):
os.chdir(self.test_dir)
management.call_command('makemessages', locale=LOCALE, verbosity=0, no_wrap=True)
management.call_command('makemessages', locale=[LOCALE], verbosity=0, no_wrap=True)
self.assertTrue(os.path.exists(self.PO_FILE))
with open(self.PO_FILE, 'r') as fp:
po_contents = force_text(fp.read())
@ -402,7 +402,7 @@ class NoWrapExtractorTests(ExtractorTests):
def test_no_wrap_disabled(self):
os.chdir(self.test_dir)
management.call_command('makemessages', locale=LOCALE, verbosity=0, no_wrap=False)
management.call_command('makemessages', locale=[LOCALE], verbosity=0, no_wrap=False)
self.assertTrue(os.path.exists(self.PO_FILE))
with open(self.PO_FILE, 'r') as fp:
po_contents = force_text(fp.read())
@ -414,7 +414,7 @@ class LocationCommentsTests(ExtractorTests):
def test_no_location_enabled(self):
"""Behavior is correct if --no-location switch is specified. See #16903."""
os.chdir(self.test_dir)
management.call_command('makemessages', locale=LOCALE, verbosity=0, no_location=True)
management.call_command('makemessages', locale=[LOCALE], verbosity=0, no_location=True)
self.assertTrue(os.path.exists(self.PO_FILE))
with open(self.PO_FILE, 'r') as fp:
po_contents = force_text(fp.read())
@ -424,7 +424,7 @@ class LocationCommentsTests(ExtractorTests):
def test_no_location_disabled(self):
"""Behavior is correct if --no-location switch isn't specified."""
os.chdir(self.test_dir)
management.call_command('makemessages', locale=LOCALE, verbosity=0, no_location=False)
management.call_command('makemessages', locale=[LOCALE], verbosity=0, no_location=False)
self.assertTrue(os.path.exists(self.PO_FILE))
with open(self.PO_FILE, 'r') as fp:
# Standard comment with source file relative path should be present -- #16903
@ -462,18 +462,18 @@ class KeepPotFileExtractorTests(ExtractorTests):
def test_keep_pot_disabled_by_default(self):
os.chdir(self.test_dir)
management.call_command('makemessages', locale=LOCALE, verbosity=0)
management.call_command('makemessages', locale=[LOCALE], verbosity=0)
self.assertFalse(os.path.exists(self.POT_FILE))
def test_keep_pot_explicitly_disabled(self):
os.chdir(self.test_dir)
management.call_command('makemessages', locale=LOCALE, verbosity=0,
management.call_command('makemessages', locale=[LOCALE], verbosity=0,
keep_pot=False)
self.assertFalse(os.path.exists(self.POT_FILE))
def test_keep_pot_enabled(self):
os.chdir(self.test_dir)
management.call_command('makemessages', locale=LOCALE, verbosity=0,
management.call_command('makemessages', locale=[LOCALE], verbosity=0,
keep_pot=True)
self.assertTrue(os.path.exists(self.POT_FILE))
@ -497,9 +497,3 @@ class MultipleLocaleExtractionTests(ExtractorTests):
management.call_command('makemessages', locale=['pt', 'de'], verbosity=0)
self.assertTrue(os.path.exists(self.PO_FILE_PT))
self.assertTrue(os.path.exists(self.PO_FILE_DE))
def test_comma_separated_locales(self):
os.chdir(self.test_dir)
management.call_command('makemessages', locale='pt,de,ch', verbosity=0)
self.assertTrue(os.path.exists(self.PO_FILE_PT))
self.assertTrue(os.path.exists(self.PO_FILE_DE))