【问题标题】:How can I use ngettext() of php-gettext when the singular and plural form are the same?当单数和复数形式相同时,如何使用 php-gettext 的 ngettext()?
【发布时间】:2016-12-17 14:40:56
【问题描述】:

我正在使用库 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) 

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

【问题讨论】:

  • 第一个例子有什么错误?我刚试了一下,它运行良好(尽管没有翻译表)

标签: php gettext php-gettext


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多