From 248aee16066b2a336f16c844580cf043d853874b Mon Sep 17 00:00:00 2001 From: Ramiro Morales Date: Wed, 16 Jan 2013 16:21:47 -0300 Subject: [PATCH] Modified makemessages so it creates .pot files once per invocation. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It creates a `locale/django.pot` file once instead of one `locale//django.pot` file for every locale involved. Thanks Michal Čihař for the report and patch. --- .../core/management/commands/makemessages.py | 24 ++++++++++--------- .../i18n/commands/extraction.py | 3 ++- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/django/core/management/commands/makemessages.py b/django/core/management/commands/makemessages.py index 449d3d7c5a..2b2755d8d1 100644 --- a/django/core/management/commands/makemessages.py +++ b/django/core/management/commands/makemessages.py @@ -234,8 +234,6 @@ def write_po_file(pofile, potfile, domain, locale, verbosity, stdout, "#. #-#-#-#-# %s.pot (PACKAGE VERSION) #-#-#-#-#\n" % domain, "") with open(pofile, 'w') as fp: fp.write(msgs) - if not keep_pot: - os.unlink(potfile) if no_obsolete: msgs, errors, status = _popen( 'msgattrib %s %s -o "%s" --no-obsolete "%s"' % @@ -314,6 +312,16 @@ def make_messages(locale=None, domain='django', verbosity=1, all=False, wrap = '--no-wrap' if no_wrap else '' location = '--no-location' if no_location else '' + potfile = os.path.join(localedir, '%s.pot' % str(domain)) + + if os.path.exists(potfile): + os.unlink(potfile) + + for dirpath, file in find_files(".", ignore_patterns, verbosity, + stdout, symlinks=symlinks): + process_file(file, dirpath, potfile, domain, verbosity, extensions, + wrap, location, keep_pot, stdout) + for locale in locales: if verbosity > 0: stdout.write("processing language %s\n" % locale) @@ -322,20 +330,14 @@ def make_messages(locale=None, domain='django', verbosity=1, all=False, os.makedirs(basedir) pofile = os.path.join(basedir, '%s.po' % str(domain)) - potfile = os.path.join(basedir, '%s.pot' % str(domain)) - - if os.path.exists(potfile): - os.unlink(potfile) - - for dirpath, file in find_files(".", ignore_patterns, verbosity, - stdout, symlinks=symlinks): - process_file(file, dirpath, potfile, domain, verbosity, extensions, - wrap, location, keep_pot, stdout) if os.path.exists(potfile): write_po_file(pofile, potfile, domain, locale, verbosity, stdout, not invoked_for_django, wrap, location, no_obsolete, keep_pot) + if not keep_pot: + os.unlink(potfile) + class Command(NoArgsCommand): option_list = NoArgsCommand.option_list + ( diff --git a/tests/regressiontests/i18n/commands/extraction.py b/tests/regressiontests/i18n/commands/extraction.py index bd2b84a952..6a8ebc7670 100644 --- a/tests/regressiontests/i18n/commands/extraction.py +++ b/tests/regressiontests/i18n/commands/extraction.py @@ -297,8 +297,9 @@ class NoLocationExtractorTests(ExtractorTests): class KeepPotFileExtractorTests(ExtractorTests): + POT_FILE='locale/django.pot' + def setUp(self): - self.POT_FILE = self.PO_FILE + 't' super(KeepPotFileExtractorTests, self).setUp() def tearDown(self):