Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

pygettext: Extend support for specifying custom keywords #130453

Open
tomasr8 opened this issue Feb 22, 2025 · 0 comments
Open

pygettext: Extend support for specifying custom keywords #130453

tomasr8 opened this issue Feb 22, 2025 · 0 comments
Assignees
Labels
triaged The issue has been accepted as valid by a triager. type-feature A feature request or enhancement

Comments

@tomasr8
Copy link
Member

tomasr8 commented Feb 22, 2025

Feature or enhancement

Proposal:

pygettext already allows specifying custom keywords in a limited fashion. For example, specifying --keyword=foo will
look for functions named foo in addition to the default keywords (gettext, etc..).

However, the CLI currently only allows specifying single-argument functions (i.e. gettext('foo')). It is not possible to add
keywords that take msgid_plural or msgctxt or both.

Both xgettext and babel support this with a simple keywordspec syntax that defines the function name and argument positions of msgid, msgid_plural and msgctxt.

For example, --keyword:foo:1c,2 defines a pgettext-like function where the msgctxt is the first argument and msgid is the second argument, e.g. foo('context', 'message').

It is also possible to use t to only match functions with that exact number of arguments. For example, foo:1,1t only matches foo('bar') but not foo('bar', 'baz').

I propose to support this in pygettext as well. For that we will need to:

  • Support the keyword spec syntax when specifying keywords. I suggest skipping the t specifier for now.
  • Support specifying multiple --keyword arguments with the same function name (this will require some internal changes, as those are stored in a dictionary with the function name as the key).
  • Support the t specifier.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

@tomasr8 tomasr8 added the type-feature A feature request or enhancement label Feb 22, 2025
@tomasr8 tomasr8 self-assigned this Feb 22, 2025
@picnixz picnixz added the triaged The issue has been accepted as valid by a triager. label Feb 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triaged The issue has been accepted as valid by a triager. type-feature A feature request or enhancement
Projects
Status: No status
Development

No branches or pull requests

2 participants