Comment 0 for bug 1050061

Revision history for this message
Michael Terry (mterry) wrote :

In utils/ui.py, the following lines are used:

INSTALL_KWARGS = {}
if sys.version_info < (3,):
    INSTALL_KWARGS["unicode"] = True
gettext.install('ubuntu-sso-client', **INSTALL_KWARGS)

But that causes problems for Python apps that use the module. For example, duplicity ran into a problem where it uses gettext.install, only to be later overridden by ubuntu_sso's gettext.install. It's not suitable for a Python module to attempt to own Python builtins like _().

This can be reproduced like so:
> import gettext
> gettext.install('duplicity')
> print(_)
<bound method NullTranslations.gettext of <gettext.NullTranslations instance at 0xb743ceac>>
> import ubuntu_sso.credentials
> print(_)
<bound method NullTranslations.ugettext of <gettext.NullTranslations instance at 0xb6d4cc0c>>

You see how it's changed to ugettext instead of gettext? And it's switched default domains.

A more suitable thing for ubuntu_sso to do is something like:

t = gettext.translation('ubuntu-sso-client')
_ = t.ugettext

This is what the gettext documentation recommends for modules (http://docs.python.org/library/gettext.html#gettext.NullTranslations.install).