python / python/cpython

pygettext: Extend support for specifying custom keywords

未關閉
#130,453 3 則留言 0 個 reaction 已指派 1 人 在 GitHub 檢視

@tomasr8 已經在處理了。

開始於 2025年2月22日。

triaged type-feature
主要語言
Python
星號
77.2k
分支
36k
PR 合併指標
PR 指標待擷取

描述

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
  • gh-130463
  • gh-130709
  • gh-131380

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。