New submission from STINNER Victor <vstin...@redhat.com>:

When a translation .po file contains a comment in headers, it's kept when 
compiled as .mo by msgfmt.

Example with test.po:
---
msgid ""
msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Plural-Forms:  nplurals=2; plural=(n != 1);\n"
"#-#-#-#-#  plo.po (PACKAGE VERSION)  #-#-#-#-#\n"
---

Compile it with "msgfmt". Parse the output file messages.mo using test.py 
script:
---
import gettext, pprint
with open("messages.mo", "rb") as fp:
    t = gettext.GNUTranslations()
    t._parse(fp)
    pprint.pprint(t._info)
---

Output on Python 3.7.2:
---
{'content-type': 'text/plain; charset=UTF-8',
 'plural-forms': 'nplurals=2; plural=(n != 1);\n'
                 '#-#-#-#-#  plo.po (PACKAGE VERSION)  #-#-#-#-#'}
---

Output of Fedora Python 2.7.15 which contains a fix:
---
{'content-type': 'text/plain; charset=UTF-8',
 'plural-forms': 'nplurals=2; plural=(n != 1);'}
---

I'm not sure that keeping the comment as part of plural forms is correct. 
Comments should not be ignored?

I made my test on Fedora 29: msgfmt 0.19.8.1, Python 3.7.2.

Links:

* https://bugs.python.org/issue1448060#msg27754
* https://bugs.python.org/issue1475523
* https://bugzilla.redhat.com/show_bug.cgi?id=252136

Fedora has a patch since 2007 to ignore comments:
https://src.fedoraproject.org/rpms/python2/blob/master/f/python-2.5.1-plural-fix.patch

I can easily convert the patch to a PR, maybe with a test. The question is more 
if the fix is correct or not.

----------
components: Library (Lib)
messages: 337476
nosy: mdk, vstinner
priority: normal
severity: normal
status: open
title: gettext: GNUTranslations doesn't parse properly comments in description
versions: Python 2.7, Python 3.7, Python 3.8

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue36239>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to