FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Can't parse POT files with plurals generated by xgettext · Issue #1154 · python-babel/babel · GitHub

Repository navigation

Can't parse POT files with plurals generated by xgettext #1154

Open

Description

Overview Description

xgettext generates a plural-forms header with all-caps strings as placeholders:
Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n

pofile.read_po chokes on these.

Steps to Reproduce

xgettext --output=- - --language=C <<<'ngettext("Hello World!", "Hello Worlds!", 3);' | python3 -c 'import sys; from babel.messages import pofile; pofile.read_po(sys.stdin)'

Actual Results

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/nix/store/wpv3wmn4j889lm2sabq8294vap8gwmri-python3-3.11.10-env/lib/python3.11/site-packages/babel/messages/pofile.py", line 387, in read_po
    parser.parse(fileobj)
  File "/nix/store/wpv3wmn4j889lm2sabq8294vap8gwmri-python3-3.11.10-env/lib/python3.11/site-packages/babel/messages/pofile.py", line 310, in parse
    self._process_comment(line)
  File "/nix/store/wpv3wmn4j889lm2sabq8294vap8gwmri-python3-3.11.10-env/lib/python3.11/site-packages/babel/messages/pofile.py", line 269, in _process_comment
    self._finish_current_message()
  File "/nix/store/wpv3wmn4j889lm2sabq8294vap8gwmri-python3-3.11.10-env/lib/python3.11/site-packages/babel/messages/pofile.py", line 206, in _finish_current_message
    self._add_message()
  File "/nix/store/wpv3wmn4j889lm2sabq8294vap8gwmri-python3-3.11.10-env/lib/python3.11/site-packages/babel/messages/pofile.py", line 200, in _add_message
    self.catalog[msgid] = message
    ~~~~~~~~~~~~^^^^^^^
  File "/nix/store/wpv3wmn4j889lm2sabq8294vap8gwmri-python3-3.11.10-env/lib/python3.11/site-packages/babel/messages/catalog.py", line 686, in __setitem__
    self.mime_headers = message_from_string(message.string).items()
    ^^^^^^^^^^^^^^^^^
  File "/nix/store/wpv3wmn4j889lm2sabq8294vap8gwmri-python3-3.11.10-env/lib/python3.11/site-packages/babel/messages/catalog.py", line 495, in _set_mime_headers
    self._num_plurals = int(params.get('nplurals', 2))
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: 'INTEGER'

Expected Results

Parsing the PO template successfully, even if the plural specification is invalid.

Reproducibility

Seems to be entirely deterministic.

Additional Information

Activity

  1. added a commit that references this issue on Feb 3, 2025
    6cf8070
  2. added theissue type on Dec 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL