Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #12673 - Require a version of GNU gettext of 0.1.5 and above.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12296 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit df82175c17667b76ac968e059583f795b8909526 1 parent 12d3799
Jannis Leidel authored January 26, 2010
59  django/core/management/commands/makemessages.py
@@ -5,18 +5,10 @@
5 5
 import warnings
6 6
 from itertools import dropwhile
7 7
 from optparse import make_option
  8
+from subprocess import PIPE, Popen
8 9
 
9 10
 from django.core.management.base import CommandError, BaseCommand
10 11
 
11  
-try:
12  
-    set
13  
-except NameError:
14  
-    from sets import Set as set     # For Python 2.3
15  
-
16  
-# Intentionally silence DeprecationWarnings about os.popen3 in Python 2.6. It's
17  
-# still sensible for us to use it, since subprocess didn't exist in 2.3.
18  
-warnings.filterwarnings('ignore', category=DeprecationWarning, message=r'os\.popen3')
19  
-
20 12
 pythonize_re = re.compile(r'\n\s*//')
21 13
 
22 14
 def handle_extensions(extensions=('html',)):
@@ -76,29 +68,21 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False, extens
76 68
             message = "usage: make-messages.py -l <language>\n   or: make-messages.py -a\n"
77 69
         raise CommandError(message)
78 70
 
79  
-    # xgettext versions prior to 0.15 assumed Python source files were encoded
80  
-    # in iso-8859-1, and produce utf-8 output.  In the case where xgettext is
81  
-    # given utf-8 input (required for Django files with non-ASCII characters),
82  
-    # this results in a utf-8 re-encoding of the original utf-8 that needs to be
83  
-    # undone to restore the original utf-8.  So we check the xgettext version
84  
-    # here once and set a flag to remember if a utf-8 decoding needs to be done
85  
-    # on xgettext's output for Python files.  We default to assuming this isn't
86  
-    # necessary if we run into any trouble determining the version.
87  
-    xgettext_reencodes_utf8 = False
88  
-    (stdin, stdout, stderr) = os.popen3('xgettext --version', 't')
89  
-    match = re.search(r'(?P<major>\d+)\.(?P<minor>\d+)', stdout.read())
  71
+    # We require gettext version 0.15 or newer.
  72
+    p = Popen('xgettext --version', shell=True, stdout=PIPE, stderr=PIPE)
  73
+    match = re.search(r'(?P<major>\d+)\.(?P<minor>\d+)', p.stdout.read())
90 74
     if match:
91 75
         xversion = (int(match.group('major')), int(match.group('minor')))
92 76
         if xversion < (0, 15):
93  
-            xgettext_reencodes_utf8 = True
94  
- 
  77
+            raise CommandError("Django internationalization requires GNU gettext 0.15 or newer. You are using version %s, please upgrade your gettext toolset." % match.group())
  78
+
95 79
     languages = []
96 80
     if locale is not None:
97 81
         languages.append(locale)
98 82
     elif all:
99  
-        locale_dirs = filter(os.path.isdir, glob.glob('%s/*' % localedir)) 
  83
+        locale_dirs = filter(os.path.isdir, glob.glob('%s/*' % localedir))
100 84
         languages = [os.path.basename(l) for l in locale_dirs]
101  
-    
  85
+
102 86
     for locale in languages:
103 87
         if verbosity > 0:
104 88
             print "processing language", locale
@@ -126,9 +110,9 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False, extens
126 110
                 thefile = '%s.py' % file
127 111
                 open(os.path.join(dirpath, thefile), "w").write(src)
128 112
                 cmd = 'xgettext -d %s -L Perl --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --from-code UTF-8 -o - "%s"' % (domain, os.path.join(dirpath, thefile))
129  
-                (stdin, stdout, stderr) = os.popen3(cmd, 't')
130  
-                msgs = stdout.read()
131  
-                errors = stderr.read()
  113
+                p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
  114
+                msgs = p.stdout.read()
  115
+                errors = p.stderr.read()
132 116
                 if errors:
133 117
                     raise CommandError("errors happened while running xgettext on %s\n%s" % (file, errors))
134 118
                 old = '#: '+os.path.join(dirpath, thefile)[2:]
@@ -156,15 +140,12 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False, extens
156 140
                     sys.stdout.write('processing file %s in %s\n' % (file, dirpath))
157 141
                 cmd = 'xgettext -d %s -L Python --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --keyword=ugettext_noop --keyword=ugettext_lazy --keyword=ungettext_lazy:1,2 --from-code UTF-8 -o - "%s"' % (
158 142
                     domain, os.path.join(dirpath, thefile))
159  
-                (stdin, stdout, stderr) = os.popen3(cmd, 't')
160  
-                msgs = stdout.read()
161  
-                errors = stderr.read()
  143
+                p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
  144
+                msgs = p.stdout.read()
  145
+                errors = p.stderr.read()
162 146
                 if errors:
163 147
                     raise CommandError("errors happened while running xgettext on %s\n%s" % (file, errors))
164 148
 
165  
-                if xgettext_reencodes_utf8:
166  
-                    msgs = msgs.decode('utf-8').encode('iso-8859-1')
167  
-
168 149
                 if thefile != file:
169 150
                     old = '#: '+os.path.join(dirpath, thefile)[2:]
170 151
                     new = '#: '+os.path.join(dirpath, file)[2:]
@@ -180,16 +161,16 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False, extens
180 161
                     os.unlink(os.path.join(dirpath, thefile))
181 162
 
182 163
         if os.path.exists(potfile):
183  
-            (stdin, stdout, stderr) = os.popen3('msguniq --to-code=utf-8 "%s"' % potfile, 't')
184  
-            msgs = stdout.read()
185  
-            errors = stderr.read()
  164
+            p = Popen('msguniq --to-code=utf-8 "%s"' % potfile, shell=True, stdout=PIPE, stderr=PIPE)
  165
+            msgs = p.stdout.read()
  166
+            errors = p.stderr.read()
186 167
             if errors:
187 168
                 raise CommandError("errors happened while running msguniq\n%s" % errors)
188 169
             open(potfile, 'w').write(msgs)
189 170
             if os.path.exists(pofile):
190  
-                (stdin, stdout, stderr) = os.popen3('msgmerge -q "%s" "%s"' % (pofile, potfile), 't')
191  
-                msgs = stdout.read()
192  
-                errors = stderr.read()
  171
+                p = Popen('msgmerge -q "%s" "%s"' % (pofile, potfile), shell=True, stdout=PIPE, stderr=PIPE)
  172
+                msgs = p.stdout.read()
  173
+                errors = p.stderr.read()
193 174
                 if errors:
194 175
                     raise CommandError("errors happened while running msgmerge\n%s" % errors)
195 176
             open(pofile, 'wb').write(msgs)
12  docs/topics/i18n.txt
@@ -512,6 +512,16 @@ creation and upkeep of these files.
512 512
     The old tool ``bin/make-messages.py`` has been moved to the command
513 513
     ``django-admin.py makemessages`` to provide consistency throughout Django.
514 514
 
  515
+.. admonition:: Gettext utilities
  516
+
  517
+    The ``makemessages`` command (and ``compilemessages`` discussed later) use
  518
+    commands from the GNU gettext toolset: ``xgetetxt``, ``msgfmt``,
  519
+    ``msgmerge`` and ``msguniq``.
  520
+
  521
+    .. versionchanged:: 1.2
  522
+
  523
+    The minimum version of the ``gettext`` utilities supported is 0.15.
  524
+
515 525
 To create or update a message file, run this command::
516 526
 
517 527
     django-admin.py makemessages -l de
@@ -1062,7 +1072,7 @@ or want to test or compile a changed message file, you will need the
1062 1072
       * ``gettext-runtime-X.zip``
1063 1073
       * ``gettext-tools-X.zip``
1064 1074
 
1065  
-      ``X`` is the version number, we recomend using ``0.15`` or higher.
  1075
+      ``X`` is the version number, we are requiring ``0.15`` or higher.
1066 1076
 
1067 1077
     * Extract the contents of the ``bin\`` directories in both files to the
1068 1078
       same folder on your system (i.e. ``C:\Program Files\gettext-utils``)

0 notes on commit df82175

Please sign in to comment.
Something went wrong with that request. Please try again.