You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
pygettext: Extend support for specifying custom keywords #130453
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
Note also that --keyword without argument and --keyword= resets keywords to default. I am not sure whether we should support this or not.
More important, currently in pygettext the defaults take precedence over --keyword arguments, so you cannot override defaults. This does not look right. How is with this in xgettext?
Note also that --keyword without argument and --keyword= resets keywords to default. I am not sure whether we should support this or not.
Not sure either to be honest.
More important, currently in pygettext the defaults take precedence over --keyword arguments, so you cannot override defaults. This does not look right. How is with this in xgettext ?
Both babel and xgettext let you do that. For example for xgettext --keyword='_:1,2' and this input file
Activity
gh-130453: pygettext: Extend support for specifying custom keywords (G…
tomasr8 commentedon Feb 25, 2025
The first PR (with the most changes) was merged, but there is more work needed. I'll reuse this issue for the followup PRs :)
serhiy-storchaka commentedon Feb 25, 2025
Note also that
--keywordwithout argument and--keyword=resets keywords to default. I am not sure whether we should support this or not.More important, currently in
pygettextthe defaults take precedence over--keywordarguments, so you cannot override defaults. This does not look right. How is with this inxgettext?tomasr8 commentedon Feb 28, 2025
Not sure either to be honest.
Both babel and xgettext let you do that. For example for
xgettext --keyword='_:1,2'and this input filexgettext will extract
while pygettext will extract
i.e. the default keyword takes precedence. I'll fix it.
gh-130453: pygettext: Allow overriding default keywords when using `-…
gh-130453: pygettext: Allow specifying multiple keywords with the sam…