> Here is an example:
>
> n = len(os.listdir('.'))
> cat = GNUTranslations(somefile)
> message = cat.ungettext(
> 'There is %(num)d file in this directory',
> 'There are %(num)d files in this directory',
> n) % {'n': n}
The last line of code in the example should be:
> n) % {'num': n}
Also, I don't think the example illustrates a realistic
usage of the ungettext() method, as it is unlikely that
the message catalog is going to have different message
id's for all the possible variations of the string each
with a different number of files in them -- exactly the
problem that ungettext() is suppose to address.
A better example would just use ungettext() to pick
either the word "file" or "files" based on the value of
n. It would be more realistic and the example code
would probably be simpler.
|