[issue8359] % formating - TypeError: not all arguments converted during string formatting

2010-04-13 Thread David Planella

David Planella  added the comment:

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.

--
nosy: +dpm

___
Python tracker 
<http://bugs.python.org/issue8359>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19341] locale.getdefaultencoding() returns wrong locale and encoding for ca_ES@valencia

2013-10-22 Thread David Planella

New submission from David Planella:

It seems getdefaultlocale does not return the correct encoding when the locale 
is set to ca_ES@valencia:

>>> import locale
>>> locale.setlocale(locale.LC_ALL, "")
'LC_CTYPE=ca_ES.UTF-8@valencia;LC_NUMERIC=ca_ES.UTF-8;LC_TIME=ca_ES.UTF-8;LC_COLLATE=ca_ES.UTF-8@valencia;LC_MONETARY=ca_ES.UTF-8;LC_MESSAGES=ca_ES.UTF-8@valencia;LC_PAPER=ca_ES.UTF-8;LC_NAME=ca_ES.UTF-8;LC_ADDRESS=ca_ES.UTF-8;LC_TELEPHONE=ca_ES.UTF-8;LC_MEASUREMENT=ca_ES.UTF-8;LC_IDENTIFICATION=ca_ES.UTF-8'
>>> locale.getdefaultlocale()
('ca_ES', 'utf_8_valencia')

Instead of 'utf_8_valencia', here I'd expect 'UTF-8' to be returned. The 
returned locale is also wrong: it should be ca_ES@valencia.

Looking quickly at the locale module's source code, it seems that the following 
item should be added to the locale_alias dict?

   'ca_es.@valencia':  'ca...@valencia.utf-8',

--
components: Library (Lib)
messages: 200886
nosy: dpm
priority: normal
severity: normal
status: open
title: locale.getdefaultencoding() returns wrong locale and encoding for 
ca_ES@valencia
type: behavior
versions: Python 2.7

___
Python tracker 
<http://bugs.python.org/issue19341>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com