Comment 3 for bug 730499

Revision history for this message
David Planella (dpm) wrote : Re: [Bug 730499] Re: Translations: plural forms

El dl 07 de 03 de 2011 a les 11:28 +0000, en/na Aurélien Gâteau va
escriure:
> We have a problem: it is not possible to replace plural handling in
> QTranslator with a gettext implementation.
>
> More details:
> Regular translations are handled by
> QTranslator::translate(const char * context, const char * sourceText, const char * disambiguation = 0 ) const
>
> This method is virtual, our GettextTranslator reimplements it to use
> gettext instead.
>
> Plural translations on the other hand are handled by
> QTranslator::translate ( const char * context, const char * sourceText, const char * disambiguation, int n ) const
>
> which is *not* virtual and does not call the other translate() method.
>
>
> The only solution I can think of is to use gettext directly, ignoring Qt translation system. This requires the following:
> - Adjust the C++ code to use gettext functions instead of tr().
> - Write QML bindings for the gettext functions.
> - Adjust the QML code to use the QML bindings instead of qsTr().
> - Adjust update-unity-2d-pot to not use qt keywords (tr and qsTr).
> - Get rid of GettextTranslator
>

Thanks Aurélien for the detailed analysis and for laying out the current
options.

I've got a quick question. I've got no previous experience with Qt code,
so bear with me if it seem obvious or far-fetched :)

      * Would there not be another way to override
        "QTranslator::translate ( const char * context, const char *
        sourceText, const char * disambiguation, int n ) const" by a
        call to the ngettext function form gettext?

I'm just wondering that there must be a way to do it so that we can use
the work that's already been done. KDE use gettext with Qt code and
handle plural forms, perhaps it might be worth looking at how they do
it.

And for the sake of completeness, to answer the question:
> 2. Does launchpad support these markers?

Launchpad supports all format specifiers that gettext supports. As
gettext supports 'qt-plural-format' as in the example below, this should
not be a problem.

#, qt-plural-format
msgctxt ""
msgid "%n bird(s)"
msgid_plural "%n bird(s)"
msgstr[0] ""
msgstr[1] ""

--
David Planella
Ubuntu Translations Coordinator
www.ubuntu.com / www.davidplanella.wordpress.com
www.identi.ca/dplanella / www.twitter.com/dplanella