我有一个案例与PHP gettext()
(使用this library替换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()
我使用的英文句子为msgid
,现在不能改变我的整个项目来使用神秘的ID,比如像
ngettext("%d-correct-singular", "%d-correct-plural", $n)
在原始语言中处理相同的单数和复数形式的适当方法是什么?
答案 0 :(得分:0)
刚刚发现它实际上是gettext库中的已知错误:https://bugs.launchpad.net/php-gettext/+bug/1415873?comments=all
您需要手动修复此错误才能正确使用ngettext函数。
此问题与常规gettext扩展无关。