How can I use ngettext() of php-gettext when the singular and plural form are the same?

849 views Asked by At

I'm using using library php-gettext to workaround the missing gettext extension on Google Cloud AppEngine. When the singular and plural form are the same in English, but different in other languages.

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

The Spanish translation would be

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

indicating the number of correct answers given.

But this gives me an error since the singular msgid is exactly the same as the plural msgid. Even the function dngettext() that allows to add a context to a translation, doesn't do the trick:

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

It triggers a warning and an error in the gettext library:

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()

I am using the English sentences as msgids and cannot change my whole project now to use cryptic IDs instead, like for example something like

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

What would be the appropriate way of handling identical singular and plural forms in the original language?

1

There are 1 answers

0
Roel Vermeulen On

Just found it is actually a known bug in the gettext library: https://bugs.launchpad.net/php-gettext/+bug/1415873?comments=all

You need to manually fix this bug to be able to use the ngettext function correctly.

This problem has nothing to do with the general gettext extension.