2

我正在使用库php-gettext来解决 Google Cloud AppEngine 上缺少的gettext扩展。当英语中单数和复数形式相同,但在其他语言中不同时。

ngettext("%d correct", "%d correct", $n)

西班牙语翻译将是

"%d correcto" (singular)
"%d correctos" (plural)

表示给出的正确答案的数量。

但这给了我一个错误,因为单数msgid与复数完全相同msgid。即使dngettext()是允许在翻译中添加上下文的函数也不能解决问题:

dngettext("Number of correct answers", "%d correct", "%d correct", $n)

它在库中触发警告和错误gettext

PHP Notice:  Undefined offset: -1
PHP Parse error: syntax error, unexpected '!=' (T_IS_NOT_EQUAL)
PHP Notice:  Undefined variable: number
PHP Warning:  Missing argument 4 for gettext_reader::npgettext()

我将英语句子用作msgids 并且现在无法更改我的整个项目以使用神秘的 ID,例如

ngettext("%d-correct-singular", "%d-correct-plural", $n) 

在原始语言中处理相同的单数和复数形式的适当方法是什么?

4

1 回答 1

0

刚刚发现它实际上是gettext库中的一个已知错误:https ://bugs.launchpad.net/php-gettext/+bug/1415873?comments=all

您需要手动修复此错误才能正确使用 ngettext 函数。

这个问题与一般的 gettext 扩展无关。

于 2016-12-17T15:22:29.773 回答