gettext中“msgstr”的多个“msgid”

时间:2011-05-05 09:09:42

标签: gettext

是否可以使两个或更多 msgids 匹配一个 msgstr

例如, ('list.empty') ('list。 null')返回"There is no any objects yet."

如果我这样写在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没有另一个,它们会返回不同的结果。

有没有人有更好的黑客攻击?

1 个答案:

答案 0 :(得分:7)

您正以错误的方式接近gettext,以下是它的工作原理:

    每个条目都需要
  • msgid
  • msgctxt是可选的,用于区分具有相同内容且可能具有不同翻译的两个msgid记录。
  • (msgid, msgctxt)是字典的唯一键,如果缺少msgctxt,您可以将其视为null

您应该在实施之前阅读gettext documentation,因为它并不总是直截了当。

在您的情况下,这是您应该如何实现它:

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

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