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.

Author dpm
Recipients dpm, eric.smith, georg.brandl, sneetsher
Date 2010-04-13.09:01:57
SpamBayes Score 5.6453604e-07
Marked as misclassified No
Message-id <1271149321.04.0.212207516154.issue8359@psf.upfronthosting.co.za>
In-reply-to
Content
It would be nice that %-formatting had the same functionality as in C when it comes to discarding unnamed arguments, but from the comments I understand that being deprecated no changes in functionality are contemplated.

However, before recommending using str.format, the fact that gettext does not yet seem to support it should also be taken into account. Some examples:

= %-formatting =

print gettext.ngettext("%(package)d package", "%(package)d packages", countInstall) % { 'package': countInstall}

Renders the following in a POT template:

#, python-format
msgid "%(package)d package"
msgid_plural "%(package)d packages"
msgstr[0] ""
msgstr[1] ""

-- All good. The string is marked as a python-format one and the %(package) argument can be dropped in the translation for the languages which need it. No program crash.

= str.format() formatting =

print gettext.ngettext("{no_of_packages} package", "{no_of_packages} packages", countInstall).format(no_of_packages=countInstall)

Renders the following in a POT template:

msgid "{no_of_packages} package"
msgid_plural "{no_of_packages} packages"
msgstr[0] ""
msgstr[1] ""

-- Not marked as python-format, since gettext does not seem to support the {} notation. No error-checking can take place for arguments. Not good.

print _("{day} day").format(day=countInstall)

msgid "{day} day"
msgstr ""

-- Same comment as above.

print _("{0} package").format(countInstall)

Extracted string in a POT template:

msgid "{0} package"
msgstr ""

-- Same comment as above

I understand that part of the error is in gettext, but I thought I'd mention it here as well, since this has caused quite a lot of crashes in Hebrew and Arabic translations in Ubuntu in the past, and will continue to do it until addressed.
History
Date User Action Args
2010-04-13 09:02:01dpmsetrecipients: + dpm, georg.brandl, eric.smith, sneetsher
2010-04-13 09:02:01dpmsetmessageid: <1271149321.04.0.212207516154.issue8359@psf.upfronthosting.co.za>
2010-04-13 09:01:59dpmlinkissue8359 messages
2010-04-13 09:01:57dpmcreate