Ticket #9212: 9212.diff

File 9212.diff, 1.9 KB (added by Karen Tracey, 16 years ago)
  • django/core/management/commands/makemessages.py

     
    7575            message = "usage: make-messages.py -l <language>\n   or: make-messages.py -a\n"
    7676        raise CommandError(message)
    7777
     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.compile(r'.*?(?P<major>\d+)\.(?P<minor>\d+)').match(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
    7894    languages = []
    7995    if locale is not None:
    8096        languages.append(locale)
     
    139155                errors = stderr.read()
    140156                if errors:
    141157                    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
    142162                if thefile != file:
    143163                    old = '#: '+os.path.join(dirpath, thefile)[2:]
    144164                    new = '#: '+os.path.join(dirpath, file)[2:]
Back to Top