多个“msgid”对于“msgstr”在获取文本中
是否可以使两个或多个 msgid 与一个 msgstr 匹配?
例如,('list.empty')和('list.null') return “还没有任何对象。”
如果我在 po 文件中这样写:
msgid "list.empty"
msgid "list.null"
msgstr "There is no any objects yet."
它只是错误“缺少'msgstr'” :
但是,
msgid "list.empty"
msgstr "There is no any objects yet."
msgid "list.null"
msgstr "There is no any objects yet."
看起来和工作都很好,但很愚蠢,因为一旦我更改一个 msgstr 而没有另一个,它们就会返回不同的结果。
有人有更好的黑客吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您以错误的方式接近
gettext
,其工作原理如下:msgid
对于每个条目都是必需的msgctxt
是可选的,用于区分两个具有相同内容但可能有不同翻译的msgid
记录之间。(msgid, msgctxt)
是字典的唯一键,如果msgctxt
缺失,您可以将其视为null
。在实施之前,您应该阅读 gettext 文档,因为它不是总是直截了当。
就您而言,这就是您应该如何实现它:
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: