commit 104d80fbe490747ea9f410fc76a5e720cb7e6669
Author: Andre Terra <acterra@timbrasil.com.br>
Date: Thu Oct 6 15:17:35 2011 -0300
Added a --keep-pot option to makemessages to ease debugging.
diff --git a/django/core/management/commands/makemessages.py b/django/core/management/commands/makemessages.py
index 2c6e171..42929d6 100755
a
|
b
|
def copy_plural_forms(msgs, locale, domain, verbosity):
|
115 | 115 | |
116 | 116 | def make_messages(locale=None, domain='django', verbosity='1', all=False, |
117 | 117 | extensions=None, symlinks=False, ignore_patterns=[], no_wrap=False, |
118 | | no_obsolete=False): |
| 118 | no_obsolete=False, keep_pot=False): |
119 | 119 | """ |
120 | 120 | Uses the locale directory from the Django SVN tree or an application/ |
121 | 121 | project to process all |
… |
… |
def make_messages(locale=None, domain='django', verbosity='1', all=False,
|
163 | 163 | languages = [os.path.basename(l) for l in locale_dirs] |
164 | 164 | |
165 | 165 | wrap = no_wrap and '--no-wrap' or '' |
| 166 | unlink_potfile = lambda potfile: None if keep_pot else os.unlink(potfile) |
166 | 167 | |
167 | 168 | for locale in languages: |
168 | 169 | if verbosity > 0: |
… |
… |
def make_messages(locale=None, domain='django', verbosity='1', all=False,
|
201 | 202 | msgs, errors = _popen(cmd) |
202 | 203 | if errors: |
203 | 204 | os.unlink(os.path.join(dirpath, thefile)) |
204 | | if os.path.exists(potfile): |
| 205 | if os.path.exists(potfile) and not keep_pot: |
205 | 206 | os.unlink(potfile) |
206 | 207 | raise CommandError( |
207 | 208 | "errors happened while running xgettext on %s\n%s" % |
… |
… |
def make_messages(locale=None, domain='django', verbosity='1', all=False,
|
248 | 249 | if errors: |
249 | 250 | if thefile != file: |
250 | 251 | os.unlink(os.path.join(dirpath, thefile)) |
251 | | if os.path.exists(potfile): |
| 252 | if os.path.exists(potfile) and not keep_pot: |
252 | 253 | os.unlink(potfile) |
253 | 254 | raise CommandError( |
254 | 255 | "errors happened while running xgettext on %s\n%s" % |
… |
… |
def make_messages(locale=None, domain='django', verbosity='1', all=False,
|
275 | 276 | msgs, errors = _popen('msguniq %s --to-code=utf-8 "%s"' % |
276 | 277 | (wrap, potfile)) |
277 | 278 | if errors: |
278 | | os.unlink(potfile) |
| 279 | unlink_potfile(potfile) |
279 | 280 | raise CommandError( |
280 | 281 | "errors happened while running msguniq\n%s" % errors) |
281 | 282 | if os.path.exists(pofile): |
… |
… |
def make_messages(locale=None, domain='django', verbosity='1', all=False,
|
287 | 288 | msgs, errors = _popen('msgmerge %s -q "%s" "%s"' % |
288 | 289 | (wrap, pofile, potfile)) |
289 | 290 | if errors: |
290 | | os.unlink(potfile) |
| 291 | unlink_potfile(potfile) |
291 | 292 | raise CommandError( |
292 | 293 | "errors happened while running msgmerge\n%s" % errors) |
293 | 294 | elif not invoked_for_django: |
… |
… |
def make_messages(locale=None, domain='django', verbosity='1', all=False,
|
299 | 300 | f.write(msgs) |
300 | 301 | finally: |
301 | 302 | f.close() |
302 | | os.unlink(potfile) |
| 303 | unlink_potfile(potfile) |
303 | 304 | if no_obsolete: |
304 | 305 | msgs, errors = _popen('msgattrib %s -o "%s" --no-obsolete "%s"' % |
305 | 306 | (wrap, pofile, pofile)) |
… |
… |
class Command(NoArgsCommand):
|
329 | 330 | default=False, help="Don't break long message lines into several lines"), |
330 | 331 | make_option('--no-obsolete', action='store_true', dest='no_obsolete', |
331 | 332 | default=False, help="Remove obsolete message strings"), |
| 333 | make_option('--keep-pot', action='store_true', dest='keep_pot', |
| 334 | default=False, help="Keep .pot file after making messages. Useful when debugging."), |
| 335 | |
332 | 336 | ) |
333 | 337 | help = ( "Runs over the entire source tree of the current directory and " |
334 | 338 | "pulls out all strings marked for translation. It creates (or updates) a message " |
… |
… |
class Command(NoArgsCommand):
|
352 | 356 | ignore_patterns = list(set(ignore_patterns)) |
353 | 357 | no_wrap = options.get('no_wrap') |
354 | 358 | no_obsolete = options.get('no_obsolete') |
| 359 | keep_pot = options.get('keep_pot') |
355 | 360 | if domain == 'djangojs': |
356 | 361 | extensions = handle_extensions(extensions or ['js']) |
357 | 362 | else: |
… |
… |
class Command(NoArgsCommand):
|
361 | 366 | sys.stdout.write('examining files with the extensions: %s\n' |
362 | 367 | % get_text_list(list(extensions), 'and')) |
363 | 368 | |
364 | | make_messages(locale, domain, verbosity, process_all, extensions, symlinks, ignore_patterns, no_wrap, no_obsolete) |
| 369 | make_messages(locale, domain, verbosity, process_all, extensions, symlinks, ignore_patterns, no_wrap, no_obsolete, keep_pot) |