开发者

Multiple "msgid" for an "msgstr" in gettext

Is it possible to make two or more msgids matching one msgstr?

For example, both ('list.empty') and ('list.null') return "There is no any objects yet."

If I write this way in po file:

msgid "list.empty"
msgid "list.null"
msgstr "There is no any objects yet."

It just errors with "missing 'msgstr'":

However,

msgid "list.empty"
msgstr "There is no any objects yet."

msgid "list.null"
msgstr "There is no any objects yet."

Looks and works fine but stupid, because once I change one msgstr without another, they return different result.

Does 开发者_如何转开发anyone have any better hacks?


You are approaching gettext in the wrong way, here is how it works:

  • msgid is required for each entry
  • msgctxt is optional and is used to differentiate between two msgid records with same content that may have different translations.
  • (msgid, msgctxt) is the unique key for the dictionary, if msgctxt is missing you can consider it null.

You should read the gettext documentation before implementing as it's not always straightforward.

In your case, this is how you are supposed to implement it:

msgctxt "list.empty"
msgid "There is no any objects yet."

msgctxt "list.null"
msgid "There is no any objects yet."
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜