Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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 jezdez authored
Showing with 31 additions and 40 deletions.
  1. +20 −39 django/core/management/commands/makemessages.py
  2. +11 −1 docs/topics/i18n.txt
59 django/core/management/commands/makemessages.py
View
@@ -5,18 +5,10 @@
import warnings
from itertools import dropwhile
from optparse import make_option
+from subprocess import PIPE, Popen
from django.core.management.base import CommandError, BaseCommand
-try:
- set
-except NameError:
- from sets import Set as set # For Python 2.3
-
-# Intentionally silence DeprecationWarnings about os.popen3 in Python 2.6. It's
-# still sensible for us to use it, since subprocess didn't exist in 2.3.
-warnings.filterwarnings('ignore', category=DeprecationWarning, message=r'os\.popen3')
-
pythonize_re = re.compile(r'\n\s*//')
def handle_extensions(extensions=('html',)):
@@ -76,29 +68,21 @@ 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"
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())
+ # We require gettext version 0.15 or newer.
+ p = Popen('xgettext --version', shell=True, stdout=PIPE, stderr=PIPE)
+ match = re.search(r'(?P<major>\d+)\.(?P<minor>\d+)', p.stdout.read())
if match:
xversion = (int(match.group('major')), int(match.group('minor')))
if xversion < (0, 15):
- xgettext_reencodes_utf8 = True
-
+ raise CommandError("Django internationalization requires GNU gettext 0.15 or newer. You are using version %s, please upgrade your gettext toolset." % match.group())
+
languages = []
if locale is not None:
languages.append(locale)
elif all:
- locale_dirs = filter(os.path.isdir, glob.glob('%s/*' % localedir))
+ locale_dirs = filter(os.path.isdir, glob.glob('%s/*' % localedir))
languages = [os.path.basename(l) for l in locale_dirs]
-
+
for locale in languages:
if verbosity > 0:
print "processing language", locale
@@ -126,9 +110,9 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False, extens
thefile = '%s.py' % file
open(os.path.join(dirpath, thefile), "w").write(src)
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))
- (stdin, stdout, stderr) = os.popen3(cmd, 't')
- msgs = stdout.read()
- errors = stderr.read()
+ p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
+ msgs = p.stdout.read()
+ errors = p.stderr.read()
if errors:
raise CommandError("errors happened while running xgettext on %s\n%s" % (file, errors))
old = '#: '+os.path.join(dirpath, thefile)[2:]
@@ -156,15 +140,12 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False, extens
sys.stdout.write('processing file %s in %s\n' % (file, dirpath))
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"' % (
domain, os.path.join(dirpath, thefile))
- (stdin, stdout, stderr) = os.popen3(cmd, 't')
- msgs = stdout.read()
- errors = stderr.read()
+ p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
+ msgs = p.stdout.read()
+ errors = p.stderr.read()
if 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:
old = '#: '+os.path.join(dirpath, thefile)[2:]
new = '#: '+os.path.join(dirpath, file)[2:]
@@ -180,16 +161,16 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False, extens
os.unlink(os.path.join(dirpath, thefile))
if os.path.exists(potfile):
- (stdin, stdout, stderr) = os.popen3('msguniq --to-code=utf-8 "%s"' % potfile, 't')
- msgs = stdout.read()
- errors = stderr.read()
+ p = Popen('msguniq --to-code=utf-8 "%s"' % potfile, shell=True, stdout=PIPE, stderr=PIPE)
+ msgs = p.stdout.read()
+ errors = p.stderr.read()
if errors:
raise CommandError("errors happened while running msguniq\n%s" % errors)
open(potfile, 'w').write(msgs)
if os.path.exists(pofile):
- (stdin, stdout, stderr) = os.popen3('msgmerge -q "%s" "%s"' % (pofile, potfile), 't')
- msgs = stdout.read()
- errors = stderr.read()
+ p = Popen('msgmerge -q "%s" "%s"' % (pofile, potfile), shell=True, stdout=PIPE, stderr=PIPE)
+ msgs = p.stdout.read()
+ errors = p.stderr.read()
if errors:
raise CommandError("errors happened while running msgmerge\n%s" % errors)
open(pofile, 'wb').write(msgs)
12 docs/topics/i18n.txt
View
@@ -512,6 +512,16 @@ creation and upkeep of these files.
The old tool ``bin/make-messages.py`` has been moved to the command
``django-admin.py makemessages`` to provide consistency throughout Django.
+.. admonition:: Gettext utilities
+
+ The ``makemessages`` command (and ``compilemessages`` discussed later) use
+ commands from the GNU gettext toolset: ``xgetetxt``, ``msgfmt``,
+ ``msgmerge`` and ``msguniq``.
+
+ .. versionchanged:: 1.2
+
+ The minimum version of the ``gettext`` utilities supported is 0.15.
+
To create or update a message file, run this command::
django-admin.py makemessages -l de
@@ -1062,7 +1072,7 @@ or want to test or compile a changed message file, you will need the
* ``gettext-runtime-X.zip``
* ``gettext-tools-X.zip``
- ``X`` is the version number, we recomend using ``0.15`` or higher.
+ ``X`` is the version number, we are requiring ``0.15`` or higher.
* Extract the contents of the ``bin\`` directories in both files to the
same folder on your system (i.e. ``C:\Program Files\gettext-utils``)
Please sign in to comment.
Something went wrong with that request. Please try again.