python / cpython

The Python programming language
https://www.python.org
Other
63.22k stars 30.28k forks source link

Incorrect handling for msgctxt in msgfmt.py #85012

Open 9d1bfdb7-9158-451d-9fe9-1792cb086a9b opened 4 years ago

9d1bfdb7-9158-451d-9fe9-1792cb086a9b commented 4 years ago
BPO 40835
Nosy @da1910
Files
  • test.po
  • 40835.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields: ```python assignee = None closed_at = None created_at = labels = ['type-bug', '3.8'] title = 'Incorrect handling for msgctxt in msgfmt.py' updated_at = user = 'https://github.com/da1910' ``` bugs.python.org fields: ```python activity = actor = 'da1910' assignee = 'none' closed = False closed_date = None closer = None components = ['Demos and Tools'] creation = creator = 'da1910' dependencies = [] files = ['49205', '49206'] hgrepos = [] issue_num = 40835 keywords = ['patch'] message_count = 3.0 messages = ['370502', '370504', '370507'] nosy_count = 1.0 nosy_names = ['da1910'] pr_nums = [] priority = 'normal' resolution = None stage = None status = 'open' superseder = None type = 'behavior' url = 'https://bugs.python.org/issue40835' versions = ['Python 3.8'] ```

    9d1bfdb7-9158-451d-9fe9-1792cb086a9b commented 4 years ago

    Running msgfmt.py with the attached po file will produce an incorrect context for the entry "test".

    Looking at the script, we require a comment to follow a contexted section for the context to be cleared. The gettext documentation makes clear that all comments are optional, so this is not desired behaviour.

    My reading of the gettext documentation has a "msgctxt" line applying only to the current entry, so it should be cleared once the last msgstr has been written for that entry.

    I will endeavour to provide a patch within the next day or two.

    9d1bfdb7-9158-451d-9fe9-1792cb086a9b commented 4 years ago

    Test po file included

    9d1bfdb7-9158-451d-9fe9-1792cb086a9b commented 4 years ago

    And a patch:

    After the end of a message entry the options for the next line are:

    1. A comment - we already reset msgctxt to None here
    2. A blank line - we can have empty lines anywhere we want, so do nothing
    3. A new msgctxt line - Set msgctxt to the new context
    4. A msgid - This is the current failing behaviour. Fix sets msgctxt back to None.
    m-aciek commented 10 months ago

    Does msgfmt.py have its test suite? It would be worth to add also a regression test there.

    tomasr8 commented 10 months ago

    There is Lib/test/test_tools/test_i18n.py for pygettext but no tests for msgfmt as far as I'm aware