[issue19907] gettext - Non ascii chars in header

Michael Müller report at bugs.python.org
Fri Dec 6 12:20:33 CET 2013


New submission from Michael Müller:

When having non ascii chars in the header of an translation file (xxx.po) the following error will be raised:

  File "D:\Python33\lib\gettext.py", line 410, in translation
    t = _translations.setdefault(key, class_(fp))
  File "D:\Python33\lib\gettext.py", line 160, in __init__
    self._parse(fp)
  File "D:\Python33\lib\gettext.py", line 265, in _parse
    item = b_item.decode().strip()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe4 in position 51: invalid continuation byte

translation file head:

"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2013-12-06 11:47\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE+Mitteleuropäische Zeit\n"
"Last-Translator: FULL NAME <EMAIL at ADDRESS>\n"
"Language-Team: LANGUAGE <LL at li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: utf-8\n"
"Generated-By: pygettext.py 1.5\n"

The problem here exists with the PO-Revision-Date which is followed by the timezone offset in current language (here "Mitteleuropäische Zeit") which is automatically added by pygettext.py.
When removing it the file will work without any problems.

Current pygettext.py code part:
[Line 444] ...
    def write(self, fp):
        options = self.__options
        timestamp = time.strftime('%Y-%m-%d %H:%M+%Z')
        # The time stamp in the header doesn't have the same format as that
        # generated by xgettext...
        print(pot_header % {'time': timestamp, 'version': __version__}, file=fp)
...

To avoid this it would be better to use gmtime and not to append the timezone:

...
    def write(self, fp):
        options = self.__options
        timestamp = time.strftime('%Y-%m-%d %H:%M', time.gmtime())
...

----------
components: Library (Lib)
messages: 205361
nosy: Michael.Müller
priority: normal
severity: normal
status: open
title: gettext - Non ascii chars in header
type: enhancement
versions: Python 3.3

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19907>
_______________________________________


More information about the Python-bugs-list mailing list