Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Open
lheckemann opened this issue Nov 19, 2024 · 0 comments
Open

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

lheckemann opened this issue Nov 19, 2024 · 0 comments

Comments

@lheckemann
Copy link

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

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants