[Catalyst] Proper ngettext with Catalyst

J. Shirley jshirley at gmail.com
Sun Feb 1 01:12:09 GMT 2009


On Sat, Jan 31, 2009 at 8:29 AM, Nikolai Prokoschenko
<nikolai at prokoschenko.de> wrote:
> 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.
>


I see your complaint, and am amused that it has not affected me
before.  The reason is that my method is using simple "stubs" in
$c->loc.

So, in English I would have:
msgid "Count Of Apples"
msgstr "I have %quant(%1, apple, apples)"

But in Japanese (which doesn't have plurals forms):
msgid "Count Of Apples"
msgstr "%1 apple have" # (translated with preserved word order)

I didn't realize there was any other way to do it, so happy I learned
something... I'm admittedly not very knowledgeable when it comes to
.po and gettext.

-J



More information about the Catalyst mailing list