From 602b9ba6b37c4ac4ed445f8c9e9dccd68d631899 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sun, 19 Feb 2006 13:26:36 +0000 Subject: Patch #1349274: gettext.install() now optionally installs additional translation functions other than _() in the builtin namespace. --- Lib/gettext.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'Lib/gettext.py') diff --git a/Lib/gettext.py b/Lib/gettext.py index a20c6f1522..90ebc51800 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) -- cgit v1.2.1