diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/gettext.py | 16 | ||||
-rw-r--r-- | Lib/test/test_gettext.py | 8 |
2 files changed, 21 insertions, 3 deletions
diff --git a/Lib/gettext.py b/Lib/gettext.py index a20c6f1..90ebc51 100644 --- a/Lib/gettext.py +++ b/Lib/gettext.py @@ -239,9 +239,19 @@ class NullTranslations: def set_output_charset(self, charset): self._output_charset = charset - def install(self, unicode=False): + def install(self, unicode=False, names=None): import __builtin__ __builtin__.__dict__['_'] = unicode and self.ugettext or self.gettext + if hasattr(names, "__contains__"): + if "gettext" in names: + __builtin__.__dict__['gettext'] = __builtin__.__dict__['_'] + if "ngettext" in names: + __builtin__.__dict__['ngettext'] = (unicode and self.ungettext + or self.ngettext) + if "lgettext" in names: + __builtin__.__dict__['lgettext'] = self.lgettext + if "lngettext" in names: + __builtin__.__dict__['lngettext'] = self.lngettext class GNUTranslations(NullTranslations): @@ -479,9 +489,9 @@ def translation(domain, localedir=None, languages=None, return result -def install(domain, localedir=None, unicode=False, codeset=None): +def install(domain, localedir=None, unicode=False, codeset=None, names=None): t = translation(domain, localedir, fallback=True, codeset=codeset) - t.install(unicode) + t.install(unicode, names) diff --git a/Lib/test/test_gettext.py b/Lib/test/test_gettext.py index 517dfc0..76253de 100644 --- a/Lib/test/test_gettext.py +++ b/Lib/test/test_gettext.py @@ -145,6 +145,14 @@ trggrkg zrffntr pngnybt yvoenel.''') # Try unicode return type t.install(unicode=True) eq(_('mullusk'), 'bacon') + # Test installation of other methods + import __builtin__ + t.install(unicode=True, names=["gettext", "lgettext"]) + eq(_, t.ugettext) + eq(__builtin__.gettext, t.ugettext) + eq(lgettext, t.lgettext) + del __builtin__.gettext + del __builtin__.lgettext class GettextTestCase2(GettextBaseTest): |