为什么日语宣称有
Plural-Forms: nplurals=1; plural=0;
- 即单数和复数之间没有区别?
虽然名词的单数形式和复数形式(比如说“铅笔”)确实是相同的(都是“enpitsu”),但短语“这支铅笔”和“这些铅笔”不是一样的不同的?单数是“Kono enpitsu”,复数是“Korera no enpitsu”。 (对吗?)
那么为什么我不能(在 PHP 中)
ngettext('This pencil','These pencils', $n);
即使我手动将
.po
文件修改为以下
msgid "This pencil"
msgid_plural "These pencils"
msgstr[0] "この鉛筆"
msgstr[1] "これらの鉛筆"
当我用 Poedit 打开文件时,它无法识别复数!
谢谢!
那么为什么我不能(在 PHP 中)
因为这不是 gettext 复数形式的用途。它们适用于包含数字的字符串,例如(“%d 支铅笔”、“%d 支铅笔”)。这就是为什么 ngettext
函数有一个整数参数 - 要插入到字符串中的值。
土耳其语和匈牙利语在这方面似乎与日语表现相同,他们各自的语言团队已决定使用
nplurals = 2; plural=(n != 1)
作为默认值
Plural-Forms
。但我找不到任何
msgstr[0]
和
msgstr[1]
对于这些语言确实不同的例子,这表明你问的问题可能是一个学术问题。gettext 框架不适用于翻译文学作品。例如,在德语(也许还有更多语言)中,建议写出较小的数字(0 到 12),并仅在较大的数字时使用数字。但是为了
ngettext()
的目的,德语应该被认为有 14 种复数形式吗?还要记住,
ngettext()
只能翻译简单的表达方式,例如“删除一个文件”/“删除%d个文件”。您不能将其用于“%d 个文件和 %d 个目录已删除”之类的表达式。另外,这段代码是不正确的:
ngettext("One file deleted. You can find it in the recycle bin.",
"%d files deleted. You can find them in the recycle bin.",
number_of_files);
无论使用哪种语言,这都会产生 number_of_files == 0
的无意义内容。您可以通过更改所有 PO 文件(包括英语)的
Plural-Forms
来解决此问题,确保
n == 0
始终具有明显的复数形式,然后将其放入 PO 文件中:
msgid "One file deleted. You can find it in the recycle bin."
msgid_plural "%d files deleted. You can find them in the recycle bin."
msgstr[0] "No file deleted."
msgstr[1] "One file deleted. You can find it in the recycle bin."
msgstr[2] "%d files deleted. You can find them in the recycle bin."
那会起作用的。但你应该这样做吗?不。您应该只解决代码中的问题,而不是 PO 文件中的问题。如果您的日语翻译抱怨他们必须区分“この铅笔”和“これらの铅笔”,那么在代码中找到解决方法可能比更改 PO 头更容易。当您实施解决方法时,您很可能会发现您还必须专门处理该情况
n == 0
。这就是为什么日语团队关于默认
Plural-Forms
表达的决定可能适合绝大多数情况。