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

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

Re: Some questions about plural forms


From: Bruno Haible
Subject: Re: Some questions about plural forms
Date: Sat, 30 May 2009 01:15:22 +0200
User-agent: KMail/1.9.9

Hi,

Michał Sawicz wrote:
> Hi, I have some doubts about formatting plural forms in .po(t) files...
> 
> Can I have a gettext call like so (it's Python):
> 
> > ngettext("Singular string %(string)s",
> >          "Plural string for %(digit)d",
> >          num) % {'string': "string", 'digit': 20}

It is possible. xgettext extracts a plural message from this without
problems. But it is bizarre that the 'string' parameter is not used in
the English plural form.

> And a respective entry in .po:
> 
> > msgid "Singular string %(string)s",
> > msgid_plural "Plural string for %(digit)d"
> > msgstr[0] "Translated singular string %(string)s"
> > msgstr[1] "Translated plural string %(digit)d"

The "msgfmt -c" check yields an error:

  $ msgfmt -c x.po
  x.po:24: a format specification for argument 'string', as in 'msgstr[0]', 
doesn't exist in 'msgid'
  msgfmt: found 1 fatal error

The error message is slightly wrong. I'm changing it to
  x.po:24: a format specification for argument 'string', as in 'msgstr[0]', 
doesn't exist in 'msgid_plural'

But it highlights nevertheless the inconsistency regarding the 'string'
argument.

> So that I can have different string format for singular / plural forms?

Yes, but the only difference in parameters is that the msgid may omit the
reference to the integer parameter to which msgid_plural refers.

> POEdit complains about this as it seems to compare
> msgstr[0] format to msgid_plural instead of msgid... Is msgid used at
> all when there are plural forms?

POEdit is right. msgid_plural is the general form of the argument list,
whereas msgid is only a special case.

> Seems that the order of msgstr[] is defined purely by Plural-Forms

Yes.

> Also, Pybabel seems to require all msgstr[] to have the same formatting
> as msgid... This confuses me a lot...

That seems like an unnecessary restriction. For unnamed arguments, it is
normal and expected, but for named arguments, the integer argument should
be omittable, so that translators can use a word instead of a known number.

The next version of the gettext doc will state:

    Python supports format strings with unnamed arguments, such as
    `'...%d...'', and format strings with named arguments, such as
    `'...%(ident)d...''. ...
    In the context of plural forms, the format string used for the
    singular form does not use the numeric argument in many languages.
    Even in English, one prefers to write `"one hour"' instead of `"1
    hour"'.  Omitting individual arguments from format strings like
    this is only possible with the named argument syntax.  (With
    unnamed arguments, Python - unlike C - verifies that the format
    string uses all supplied arguments.)

Bruno




reply via email to

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