singalen: (Default)
singalen ([personal profile] singalen) wrote2010-04-02 05:05 pm
Entry tags:

Как в gettext переводить строки, зависящие от чисел

Если кто не бывает в нашей уютной рассылке...
Вот как это выглядит в po-файле (файле локализуемых ресурсов). Я сам узнал, только когда занялся переводом.

Для русского:
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%"
"10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
...
msgid "year"
msgid_plural "years"
msgstr[0] "%i год"
msgstr[1] "%i года"
msgstr[2] "%i лет"


И функция:
char * ngettext (const char *msgid1, const char *msgid2, unsigned long int n)

Соответственно, код не зависит от количества и структуры множественных чисел в языке.

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting