Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.0.X] Fixed #9212: Added code to check the xgettext version, and if…

… it is lower than 0.15, undo an incorrect encoding to utf-8 done by xgettext. This bug was fixed in xgettext 0.15, but the most-easily-installed Windows gettext binaries are older (0.13.1), so we work around it.

Backport of r9155 from trunk.


git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@9156 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 48f4388c8bbd072db1e7949c7b954ca9ce989f77 1 parent 0752742
Karen Tracey authored October 06, 2008
20  django/core/management/commands/makemessages.py
@@ -75,6 +75,22 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False, extens
75 75
             message = "usage: make-messages.py -l <language>\n   or: make-messages.py -a\n"
76 76
         raise CommandError(message)
77 77
 
  78
+    # xgettext versions prior to 0.15 assumed Python source files were encoded
  79
+    # in iso-8859-1, and produce utf-8 output.  In the case where xgettext is
  80
+    # given utf-8 input (required for Django files with non-ASCII characters),
  81
+    # this results in a utf-8 re-encoding of the original utf-8 that needs to be
  82
+    # undone to restore the original utf-8.  So we check the xgettext version
  83
+    # here once and set a flag to remember if a utf-8 decoding needs to be done
  84
+    # on xgettext's output for Python files.  We default to assuming this isn't
  85
+    # necessary if we run into any trouble determining the version.
  86
+    xgettext_reencodes_utf8 = False
  87
+    (stdin, stdout, stderr) = os.popen3('xgettext --version', 't')
  88
+    match = re.search(r'(?P<major>\d+)\.(?P<minor>\d+)', stdout.read())
  89
+    if match:
  90
+        xversion = (int(match.group('major')), int(match.group('minor')))
  91
+        if xversion < (0, 15):
  92
+            xgettext_reencodes_utf8 = True
  93
+ 
78 94
     languages = []
79 95
     if locale is not None:
80 96
         languages.append(locale)
@@ -139,6 +155,10 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False, extens
139 155
                 errors = stderr.read()
140 156
                 if errors:
141 157
                     raise CommandError("errors happened while running xgettext on %s\n%s" % (file, errors))
  158
+
  159
+                if xgettext_reencodes_utf8:
  160
+                    msgs = msgs.decode('utf-8').encode('iso-8859-1')
  161
+
142 162
                 if thefile != file:
143 163
                     old = '#: '+os.path.join(dirpath, thefile)[2:]
144 164
                     new = '#: '+os.path.join(dirpath, file)[2:]
7  docs/topics/i18n.txt
@@ -974,3 +974,10 @@ test or compile a changed message file, you will need the ``gettext`` utilities:
974 974
       * In the ``System variables`` list, click ``Path``, click ``Edit``
975 975
       * Add ``;C:\Program Files\gettext-utils\bin`` at the end of the
976 976
         ``Variable value`` field
  977
+
  978
+You may also use ``gettext`` binaries you have obtained elsewhere, so long as 
  979
+the ``xgettext --version`` command works properly. Some version 0.14.4 binaries
  980
+have been found to not support this command. Do not attempt to use Django 
  981
+translation utilities with a ``gettext`` package if the command ``xgettext
  982
+--version`` entered at a Windows command prompt causes a popup window saying
  983
+"xgettext.exe has generated errors and will be closed by Windows".

0 notes on commit 48f4388

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