【问题标题】:Multiple "msgid" for an "msgstr" in gettextgettext 中“msgstr”的多个“msgid”
【发布时间】:2011-08-19 04:59:13
【问题描述】:

是否可以让两个或多个 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 而没有另一个,它们会返回不同的结果。

有人有更好的技巧吗?

【问题讨论】:

    标签: gettext


    【解决方案1】:

    你以错误的方式接近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."
    

    【讨论】:

    • 它拼写为 msgctxt 而不是 msgctx。
    猜你喜欢
    • 2011-05-06
    • 1970-01-01
    • 1970-01-01
    • 2018-12-13
    • 2014-07-05
    • 2014-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多