pygettext: Extend support for specifying custom keywords
@tomasr8 đang làm issue này rồi.
Từ ngày 22/2/2025.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 35.9k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
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
tspecifier for now. - Support specifying multiple
--keywordarguments 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
tspecifier.
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
- gh-130463
- gh-130709
- gh-131380
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Đánh giá
Issue này chưa được đánh giá.