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 entrymsgctxt
is optional and is used to differentiate between twomsgid
records with same content that may have different translations.(msgid, msgctxt)
is the unique key for the dictionary, ifmsgctxt
is missing you can consider itnull
.
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."
精彩评论