bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Support for native Qt plurals by Gettext?


From: Bruno Haible
Subject: Re: Support for native Qt plurals by Gettext?
Date: Wed, 28 Jan 2009 11:39:59 +0100
User-agent: KMail/1.9.9

Chusslove Illich wrote on 2008-12-05 in
<http://lists.gnu.org/archive/html/bug-gnu-utils/2008-12/msg00007.html>:
> Qt since 4.2 actually has native support for plural forms (I wasn't aware of
> this when we discussed qt-format/kde-format issues earlier), but somewhat
> different in concept than Gettext's:
> 
> http://www.system-linux.net/doc/qt4/doc/html/qobject.html#tr
> 
> http://doc.trolltech.com/qq/qq19-plurals.html

Thanks for the pointers. Interesting to see that they have implemented a
plural choice formula evaluation engine as well, just with a more restricted
set of formulas.

> Another thing is that if the
> number is negative, then the call is not considered plural at all

However, this is a thing xgettext cannot recognize, because the third argument
to tr() may be variable or computed.

> Furthermore, as above, the context, even if empty, must be supplied due to
> argument ordering (cf. my recent message on empty contexts).

Yes, gettext supports empty contexts. xgettext distinguishes an empty
context from a null context, like tr does: QObject::tr has the prototype

  static QString tr(const char *sourceText, const char *context = NULL, int n = 
-1);

so a context = "" is different from a context = NULL.

> So, the question is: should/could this (or a part of it) be supported by
> xgettext?

It will be supported in gettext 0.18:

$ cat foo.cc
  QString msg = tr("%n bird(s)", "", 10); // plural call
  QString msg = tr("%1 bird(s)", "").arg(10); // ordinary call
  QString msg = tr("%1 eagle(s)").arg(10); // ordinary call
$ xgettext --omit-header --no-location \
    --qt --keyword=tr:1,1t --keyword=tr:1,2c,2t --keyword=tr:1,1,2c,3t \
    -o - foo.cc 
#, qt-plural-format
msgctxt ""
msgid "%n bird(s)"
msgid_plural "%n bird(s)"
msgstr[0] ""
msgstr[1] ""

#, qt-format
msgctxt ""
msgid "%1 bird(s)"
msgstr ""

#, qt-format
msgid "%1 eagle(s)"
msgstr ""

Note:
  - the use of qt-plural-format to denote a string with %n,
  - msgid and msgid_plural are the same in this case,
  - the msgctxt has been extracted.

Bruno




reply via email to

[Prev in Thread] Current Thread [Next in Thread]