Skip to content

Commit

Permalink
Fixed #9212: Added code to check the xgettext version, and if it is l…
Browse files Browse the repository at this point in the history
…ower 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.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@9155 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
kmtracey committed Oct 6, 2008
1 parent b131462 commit 5d3b222
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
20 changes: 20 additions & 0 deletions django/core/management/commands/makemessages.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -75,6 +75,22 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False, extens
message = "usage: make-messages.py -l <language>\n or: make-messages.py -a\n" message = "usage: make-messages.py -l <language>\n or: make-messages.py -a\n"
raise CommandError(message) raise CommandError(message)


# xgettext versions prior to 0.15 assumed Python source files were encoded
# in iso-8859-1, and produce utf-8 output. In the case where xgettext is
# given utf-8 input (required for Django files with non-ASCII characters),
# this results in a utf-8 re-encoding of the original utf-8 that needs to be
# undone to restore the original utf-8. So we check the xgettext version
# here once and set a flag to remember if a utf-8 decoding needs to be done
# on xgettext's output for Python files. We default to assuming this isn't
# necessary if we run into any trouble determining the version.
xgettext_reencodes_utf8 = False
(stdin, stdout, stderr) = os.popen3('xgettext --version', 't')
match = re.search(r'(?P<major>\d+)\.(?P<minor>\d+)', stdout.read())
if match:
xversion = (int(match.group('major')), int(match.group('minor')))
if xversion < (0, 15):
xgettext_reencodes_utf8 = True

languages = [] languages = []
if locale is not None: if locale is not None:
languages.append(locale) languages.append(locale)
Expand Down Expand Up @@ -139,6 +155,10 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False, extens
errors = stderr.read() errors = stderr.read()
if errors: if errors:
raise CommandError("errors happened while running xgettext on %s\n%s" % (file, errors)) raise CommandError("errors happened while running xgettext on %s\n%s" % (file, errors))

if xgettext_reencodes_utf8:
msgs = msgs.decode('utf-8').encode('iso-8859-1')

if thefile != file: if thefile != file:
old = '#: '+os.path.join(dirpath, thefile)[2:] old = '#: '+os.path.join(dirpath, thefile)[2:]
new = '#: '+os.path.join(dirpath, file)[2:] new = '#: '+os.path.join(dirpath, file)[2:]
Expand Down
7 changes: 7 additions & 0 deletions docs/topics/i18n.txt
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -974,3 +974,10 @@ test or compile a changed message file, you will need the ``gettext`` utilities:
* In the ``System variables`` list, click ``Path``, click ``Edit`` * In the ``System variables`` list, click ``Path``, click ``Edit``
* Add ``;C:\Program Files\gettext-utils\bin`` at the end of the * Add ``;C:\Program Files\gettext-utils\bin`` at the end of the
``Variable value`` field ``Variable value`` field

You may also use ``gettext`` binaries you have obtained elsewhere, so long as
the ``xgettext --version`` command works properly. Some version 0.14.4 binaries
have been found to not support this command. Do not attempt to use Django
translation utilities with a ``gettext`` package if the command ``xgettext
--version`` entered at a Windows command prompt causes a popup window saying
"xgettext.exe has generated errors and will be closed by Windows".

0 comments on commit 5d3b222

Please sign in to comment.