[Catalyst] Proper ngettext with Catalyst

Nikolai Prokoschenko nikolai at prokoschenko.de
Sat Jan 31 16:29:39 GMT 2009


Hello,

I've asked this question on StackOverflow the other day, but the topic
seems more complex, so I'll repeat the question here.

I'm introducing translations to an existing Catalyst project. One of
requirements is to use standard gettext .po file format, since we want
to reuse all the existing tools. I've found Catalyst::Plugin::I18n on
CPAN and thought I'm done with that, but as it tuns out, the journey
would me much longer.

Locale::Maketext::Lexicon, which C::P::I18n bases on, doesn't support
standard plural forms. An example: if I wanted to translate the string
"I have $x apples" I would write using gettext: ngettext("I have %d
apple", "I have %d apples", $x). Thus xgettext would produce:

msgid "I have %d apple"
msgid_plural "I have %d apples"
msgstr[0] ""
msgstr[1] ""

However, with C::P::I18n the syntax is (as I understand it, haven't
done Maketext before): loc("I have [quant,_1,apple,apples]", $x).
Therefore, xgettext.pl produces

msgid "I have [quant,_1,apple,apples]"
msgstr ""

or alternatively

msgid "I have %quant(_1,apple,apples)"
msgstr ""

which

a. is wrong technically, since standard gettext tools (poedit, kbabel,
rosetta) wouldn't be able to edit plural forms
b. is wrong semantically, since plural form count is different in
different languages and the position of a word can differ depending on
the number (this is one reason why gnu recommends translating complete
sentences)
c. forces translators to deal with programming and virtues of maketext

The only solution I've came up with so far is taking parts of
Locale::gettext_pp and building up a module which uses standard
gettext tools. This one works (tested tonight), but gettext fails to
extract all the strings from TemplateToolkit templates, so I'm stuck
with a half-baked solution again.

Can anyone recommend a sane solution for this problem?

Thanks

Nikolai.



More information about the Catalyst mailing list