Skip to content

Conversation

@mardiros
Copy link

@mardiros mardiros commented Oct 17, 2025

At the moment, the localization methods dpgettext and dnpgettext are not properly handled by extract command.

It raises KeyError exception.

except if you pass explicitly --keyword dpgettext:2c,3 --keyword dnpgettext:2c,3,4

This MR fixed the issue by declaring the default position parameter of those methods.

Traceback raised:

$ uv run pybabel extract -F tests/functionals/i18n/babel.ini --input-dirs tests/functionals/ -o tests/functionals/i18n/mydomain.pot
extracting messages from tests/functionals/i18n/test_l10n.py (encoding="utf-8")
Traceback (most recent call last):
  File "/home/guillaume/workspace/git/xcomponent/.venv/bin/pybabel", line 8, in <module>
    sys.exit(main())
             ~~~~^^
  File "/home/guillaume/workspace/git/xcomponent/.venv/lib/python3.13/site-packages/babel/messages/frontend.py", line 998, in main
    return CommandLineInterface().run(sys.argv)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/home/guillaume/workspace/git/xcomponent/.venv/lib/python3.13/site-packages/babel/messages/frontend.py", line 924, in run
    return cmdinst.run()
           ~~~~~~~~~~~^^
  File "/home/guillaume/workspace/git/xcomponent/.venv/lib/python3.13/site-packages/babel/messages/frontend.py", line 522, in run
    for filename, lineno, message, comments, context in extracted:
                                                        ^^^^^^^^^
  File "/home/guillaume/workspace/git/xcomponent/.venv/lib/python3.13/site-packages/babel/messages/extract.py", line 217, in extract_from_dir
    yield from check_and_call_extract_file(
    ...<8 lines>...
    )
  File "/home/guillaume/workspace/git/xcomponent/.venv/lib/python3.13/site-packages/babel/messages/extract.py", line 282, in check_and_call_extract_file
    for message_tuple in extract_from_file(
                         ~~~~~~~~~~~~~~~~~^
        method, filepath,
        ^^^^^^^^^^^^^^^^^
    ...<3 lines>...
        strip_comment_tags=strip_comment_tags,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ):
    ^
  File "/home/guillaume/workspace/git/xcomponent/.venv/lib/python3.13/site-packages/babel/messages/extract.py", line 324, in extract_from_file
    return list(extract(method, fileobj, keywords, comment_tags,
                        options, strip_comment_tags))
  File "/home/guillaume/workspace/git/xcomponent/.venv/lib/python3.13/site-packages/babel/messages/extract.py", line 457, in extract
    specs = keywords[funcname] or None if funcname else None
            ~~~~~~~~^^^^^^^^^^
KeyError: 'dpgettext'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant