From 8750296918072c97a51f6809d19828ce3f1b8d40 Mon Sep 17 00:00:00 2001 From: Ramiro Morales Date: Fri, 22 Nov 2013 23:47:04 -0300 Subject: [PATCH] [1.6.x] 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. --- .../management/commands/compilemessages.py | 4 +- .../core/management/commands/makemessages.py | 4 +- docs/ref/django-admin.txt | 7 --- docs/releases/1.6.1.txt | 5 ++ tests/i18n/commands/compilation.py | 10 ++-- tests/i18n/commands/extraction.py | 48 ++++++++----------- 6 files changed, 35 insertions(+), 43 deletions(-) diff --git a/django/core/management/commands/compilemessages.py b/django/core/management/commands/compilemessages.py index cb41492004..9e9df26a73 100644 --- a/django/core/management/commands/compilemessages.py +++ b/django/core/management/commands/compilemessages.py @@ -33,7 +33,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: @@ -59,7 +59,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.' diff --git a/django/core/management/commands/makemessages.py b/django/core/management/commands/makemessages.py index 54352fd0ee..5b096610be 100644 --- a/django/core/management/commands/makemessages.py +++ b/django/core/management/commands/makemessages.py @@ -168,7 +168,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', @@ -264,7 +264,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] diff --git a/docs/ref/django-admin.txt b/docs/ref/django-admin.txt index 5dcee8fe6f..6c6ba476f6 100644 --- a/docs/ref/django-admin.txt +++ b/docs/ref/django-admin.txt @@ -131,8 +131,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 @@ -523,11 +521,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. diff --git a/docs/releases/1.6.1.txt b/docs/releases/1.6.1.txt index db05bcdca2..683b231c77 100644 --- a/docs/releases/1.6.1.txt +++ b/docs/releases/1.6.1.txt @@ -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). diff --git a/tests/i18n/commands/compilation.py b/tests/i18n/commands/compilation.py index 12bb89ed08..8e807aa9cf 100644 --- a/tests/i18n/commands/compilation.py +++ b/tests/i18n/commands/compilation.py @@ -29,7 +29,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)) @@ -45,7 +45,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)) @@ -63,7 +63,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({})) @@ -88,7 +88,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)) @@ -110,4 +110,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()) diff --git a/tests/i18n/commands/extraction.py b/tests/i18n/commands/extraction.py index 18a9040126..e0b6debc70 100644 --- a/tests/i18n/commands/extraction.py +++ b/tests/i18n/commands/extraction.py @@ -64,7 +64,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() @@ -92,7 +92,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()) @@ -108,7 +108,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_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) six.assertRegex(self, str(context_manager.exception), @@ -137,7 +137,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())) @@ -147,7 +147,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): @@ -157,7 +157,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()) @@ -183,7 +183,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()) @@ -202,7 +202,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)) @@ -259,7 +259,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() @@ -286,7 +286,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) @@ -331,7 +331,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()) @@ -353,7 +353,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()) @@ -362,7 +362,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() @@ -374,7 +374,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()) @@ -382,7 +382,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()) @@ -394,7 +394,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()) @@ -404,7 +404,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 @@ -442,18 +442,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)) @@ -477,9 +477,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))