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@ADDRESS>\n"
"Language-Team: LANGUAGE <l...@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 <rep...@bugs.python.org>
<http://bugs.python.org/issue19907>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to