[Python-Dev] Small issues in gettext support

"Martin v. Löwis" martin at v.loewis.de
Tue Apr 27 17:07:27 EDT 2004


Gustavo Niemeyer wrote:

>    # Encode the Unicode tmsg back to an 8-bit string, if possible
>    if self._charset:
> 	return tmsg.encode(self._charset)
> 
> to use the system encoding (sys.getdefaultencoding()) instead of
> self._charset.

That shouldn't be sys.getdefaultencoding(), but
locale.getpreferredencoding().

However, I agree with Barry that the current behaviour should not
be changed. People may already rely on gettext returning byte
strings as-is.


> - Change the default codeset used by gettext.py in functions
>   returning an encoded string to match the system encoding.

No. Explicit is better that implicit; users desiring that
feature should write

_charset = locale.getpreferredencoding()
def _(msg):
   return dgettext("domain", msg).encode(_charset)

I advocate never to use gettext.install, in which case you
have a custom _ implementation *anyway*, which would then
also include the textual domain. It should not be too
much effort for that function to transcode if desired.

> - Introduce bind_textdomain_codeset() in locale.
> - Introduce bind_textdomain_codeset() in gettext.py implementing
>   an equivalent functionality.

That is ok. You could also try to provide that feature
consistently, e.g. inside .install.

Regards,
Martin




More information about the Python-Dev mailing list