多个“msgid”对于“msgstr”在获取文本中

发布于 2024-11-05 05:36:01 字数 617 浏览 0 评论 0原文

是否可以使两个或多个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青柠芒果 2024-11-12 05:36:01

您以错误的方式接近 gettext,其工作原理如下:

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

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

就您而言,这就是您应该如何实现它:

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

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

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."
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文