Django

Code

Changeset 9155

Show
Ignore:
Timestamp:
10/05/08 20:36:35 (3 months ago)
Author:
kmtracey
Message:

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.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/management/commands/makemessages.py

    r9148 r9155  
    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.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  
    7894    languages = [] 
    7995    if locale is not None: 
     
    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:] 
  • django/trunk/docs/topics/i18n.txt

    r9131 r9155  
    975975      * Add ``;C:\Program Files\gettext-utils\bin`` at the end of the 
    976976        ``Variable value`` field 
     977 
     978You may also use ``gettext`` binaries you have obtained elsewhere, so long as  
     979the ``xgettext --version`` command works properly. Some version 0.14.4 binaries 
     980have been found to not support this command. Do not attempt to use Django  
     981translation 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".