Code

Ticket #17008: 0a4b228-patch.diff

File 0a4b228-patch.diff, 5.2 KB (added by airstrike, 3 years ago)
Line 
1diff --git a/django/core/management/commands/makemessages.py b/django/core/management/commands/makemessages.py
2index 2c6e171..82eacdb 100755
3--- a/django/core/management/commands/makemessages.py
4+++ b/django/core/management/commands/makemessages.py
5@@ -115,7 +115,7 @@ def copy_plural_forms(msgs, locale, domain, verbosity):
6 
7 def make_messages(locale=None, domain='django', verbosity='1', all=False,
8         extensions=None, symlinks=False, ignore_patterns=[], no_wrap=False,
9-        no_obsolete=False):
10+        no_obsolete=False, keep_pot=False):
11     """
12     Uses the locale directory from the Django SVN tree or an application/
13     project to process all
14@@ -201,7 +201,7 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False,
15                 msgs, errors = _popen(cmd)
16                 if errors:
17                     os.unlink(os.path.join(dirpath, thefile))
18-                    if os.path.exists(potfile):
19+                    if os.path.exists(potfile) and not keep_pot:
20                         os.unlink(potfile)
21                     raise CommandError(
22                         "errors happened while running xgettext on %s\n%s" %
23@@ -248,7 +248,7 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False,
24                 if errors:
25                     if thefile != file:
26                         os.unlink(os.path.join(dirpath, thefile))
27-                    if os.path.exists(potfile):
28+                    if os.path.exists(potfile) and not keep_pot:
29                         os.unlink(potfile)
30                     raise CommandError(
31                         "errors happened while running xgettext on %s\n%s" %
32@@ -275,7 +275,8 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False,
33             msgs, errors = _popen('msguniq %s --to-code=utf-8 "%s"' %
34                                   (wrap, potfile))
35             if errors:
36-                os.unlink(potfile)
37+                if not keep_pot:
38+                    os.unlink(potfile)
39                 raise CommandError(
40                     "errors happened while running msguniq\n%s" % errors)
41             if os.path.exists(pofile):
42@@ -287,7 +288,8 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False,
43                 msgs, errors = _popen('msgmerge %s -q "%s" "%s"' %
44                                       (wrap, pofile, potfile))
45                 if errors:
46-                    os.unlink(potfile)
47+                    if not keep_pot:
48+                        os.unlink(potfile)
49                     raise CommandError(
50                         "errors happened while running msgmerge\n%s" % errors)
51             elif not invoked_for_django:
52@@ -299,7 +301,8 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False,
53                 f.write(msgs)
54             finally:
55                 f.close()
56-            os.unlink(potfile)
57+            if not keep_pot:
58+                os.unlink(potfile)
59             if no_obsolete:
60                 msgs, errors = _popen('msgattrib %s -o "%s" --no-obsolete "%s"' %
61                                       (wrap, pofile, pofile))
62@@ -329,6 +332,9 @@ class Command(NoArgsCommand):
63             default=False, help="Don't break long message lines into several lines"),
64         make_option('--no-obsolete', action='store_true', dest='no_obsolete',
65             default=False, help="Remove obsolete message strings"),
66+        make_option('--keep-pot', action='store_true', dest='keep_pot',
67+            default=False, help="Keep .pot file after making messages. Useful when debugging."),
68+
69     )
70     help = ( "Runs over the entire source tree of the current directory and "
71 "pulls out all strings marked for translation. It creates (or updates) a message "
72@@ -352,6 +358,7 @@ class Command(NoArgsCommand):
73         ignore_patterns = list(set(ignore_patterns))
74         no_wrap = options.get('no_wrap')
75         no_obsolete = options.get('no_obsolete')
76+        keep_pot = options.get('keep_pot')
77         if domain == 'djangojs':
78             extensions = handle_extensions(extensions or ['js'])
79         else:
80@@ -361,4 +368,4 @@ class Command(NoArgsCommand):
81             sys.stdout.write('examining files with the extensions: %s\n'
82                              % get_text_list(list(extensions), 'and'))
83 
84-        make_messages(locale, domain, verbosity, process_all, extensions, symlinks, ignore_patterns, no_wrap, no_obsolete)
85+        make_messages(locale, domain, verbosity, process_all, extensions, symlinks, ignore_patterns, no_wrap, no_obsolete, keep_pot)
86diff --git a/docs/ref/django-admin.txt b/docs/ref/django-admin.txt
87index c07b61c..0dfd325 100755
88--- a/docs/ref/django-admin.txt
89+++ b/docs/ref/django-admin.txt
90@@ -475,6 +475,14 @@ Use the ``--no-default-ignore`` option to disable the default values of
91 Use the ``--no-wrap`` option to disable breaking long message lines into
92 several lines in language files.
93 
94+.. django-admin-option:: --keep-pot
95+
96+.. versionadded:: 1.4
97+
98+Use the ``--keep-pot`` option to prevent django from deleting the temporary .pot file
99+it generates before creating the .po file. This is useful for debugging errors which
100+may prevent the final language files from being created.
101+
102 reset <appname appname ...>
103 ---------------------------
104