为什么在gettext转换文件中需要msgid_plural? [英] Why is msgid_plural necessary in gettext translation files?

查看:163
本文介绍了为什么在gettext转换文件中需要msgid_plural?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了关于翻译的GNU Gettext手册复数形式,并查看其示例:

I've read the GNU Gettext manual about Translating plural forms and see its example:

 #, c-format
 msgid "One file removed"
 msgid_plural "%d files removed"
 msgstr[0] "%d slika je uklonjena"
 msgstr[1] "%d datoteke uklonjenih"
 msgstr[2] "%d slika uklonjenih"

为什么msgid_plural与msgid有所不同,并且不会破坏让翻译知道复数形式的目的吗?

Why is msgid_plural different from msgid, and doesn't that defeat the purpose of having translations be aware of plural forms?

我认为我可以做这样的事情(英语):

I'd think that I could do something like this (for English):

 #, c-format
 msgid "X geese"
 msgstr[0] "%d goose"
 msgstr[1] "%d geese"

 #, c-format
 msgid "sentence_about_geese_at_the_lake"
 msgstr[0] "There is one goose at the lake."
 msgstr[1] "There are %d geese at the lake."

(仅使用一个msgid).

(using just one msgid).

然后在我的代码中,我会有类似的东西:

Then in my code, I'd have something like:

<?php echo $this->translate('X geese', $numberA); ?> 
<?php echo $this->translate('sentence_about_geese_at_the_lake', $numberB); ?> 

如果$ numberA为3,它将说"3鹅".

If $numberA is 3, it would say "3 geese."

如果$ numberB为0,则下一行将显示湖上有0只鹅."

If $numberB is 0, the next line would say "There are 0 geese at the lake."

(因为英语,规则是(n!= 1),所以复数用于等于0或大于1的任何数字).

(because for English, the rule is (n != 1), so plural is used for any number that equals 0 or greater than 1).

对我来说,为相同的短语集合指定2个msgids似乎对我来说是多余的.

It seems redundant for me to be required to specify 2 msgids for the same collection of phrases.

感谢您的帮助!

推荐答案

gettext的想法之一是从源文件中提取msgid以创建POT文件,这些文件用作PO文件中存储的翻译的基础,然后编译为MO文件.如果找不到合适的翻译,还会使用msgid.

One of the ideas behind gettext is that the msgid is extracted from source files to create POT files, which are used as base for translations stored in PO files, and later compiled to MO files. A msgid is also used if no suitable translation is found.

msgid不是用户无法读取的键";它是可以在程序中使用的真实短语.因此,在您的代码中,您要求翻译为复数形式(此处为伪代码):

A msgid is not a "key" that is non-readable by users; it is a real phrase that can be used in the program. So when in your code you request a translation for a plural (pseudocode here):

ngettext("One file removed", "%d files removed", file_count)

...将使用这两个字符串a)从源代码中提取消息;这些消息将作为翻译者的指南b)当找不到适合当前语言环境的翻译时,将其作为默认字符串.

...these two strings will be used a) to extract messages from the source code; these messages will serve as guide for translators b) as the default strings when no suitable translation is found for the current locale.

这就是为什么复数字符串具有两个msgid的原因:显示它们如何在源程序中定义(对于翻译程序)并用作默认值(当不存在翻译时).

That's why a plural string has two msgid: to show how they are defined in the source program (for translators) and to be used as default (when no translation exists).

在其他本地化系统中,例如 Android字符串资源滚动YAML文件,它的工作原理与您想象的一样-等效于msgid是一个即使是复数形式的键",但是在源代码中也不会使用真正的短语,并且定义翻译甚至是针对原始语言的两步操作.

In other localization systems, like Android String Resources or Rails YAML files, it works like you imagined -- the equivalent to a msgid is a single "key" even for plurals, but then the real phrase is not used in the source code, and defining translations is a two-steps action even for the original language.

这篇关于为什么在gettext转换文件中需要msgid_plural?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆