This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Problem w/6.27.2.2 GNUTranslations ungettext() example code
Type: Stage:
Components: Documentation Versions: Python 2.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: akuchling Nosy List: akuchling, mrmiller
Priority: normal Keywords:

Created on 2004-05-07 12:44 by mrmiller, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg20730 - (view) Author: Martin Miller (mrmiller) Date: 2004-05-07 12:44
> 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.



msg20731 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2004-07-10 17:17
Logged In: YES 
user_id=11375

Example fixed in CVS and in 2.3 branch; thanks!
History
Date User Action Args
2022-04-11 14:56:04adminsetgithub: 40231
2004-05-07 12:44:35mrmillercreate