diff options
author | Benjamin Peterson <benjamin@python.org> | 2008-07-14 14:32:15 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2008-07-14 14:32:15 (GMT) |
commit | 801844d6fc8b48cfa969dd2573bd522a2b26f974 (patch) | |
tree | b792e1b3b54ed2dd3386e0ff58ffb3c9ef1d9d02 /Lib/gettext.py | |
parent | fbe94c55ca482bc30a831f8319bdc2074124a4e3 (diff) | |
download | cpython-801844d6fc8b48cfa969dd2573bd522a2b26f974.zip cpython-801844d6fc8b48cfa969dd2573bd522a2b26f974.tar.gz cpython-801844d6fc8b48cfa969dd2573bd522a2b26f974.tar.bz2 |
#2512 implement the 3.0 gettext API
All the u* gettext variants were renamed to their
none u* variants, since there's no point in translating
to byte strings. I also killed off the unicode parameters
for install
Diffstat (limited to 'Lib/gettext.py')
-rw-r--r-- | Lib/gettext.py | 36 |
1 files changed, 9 insertions, 27 deletions
diff --git a/Lib/gettext.py b/Lib/gettext.py index 6e14a93..d1f20bf 100644 --- a/Lib/gettext.py +++ b/Lib/gettext.py @@ -210,19 +210,6 @@ class NullTranslations: else: return msgid2 - def ugettext(self, message): - if self._fallback: - return self._fallback.ugettext(message) - return str(message) - - def ungettext(self, msgid1, msgid2, n): - if self._fallback: - return self._fallback.ungettext(msgid1, msgid2, n) - if n == 1: - return str(msgid1) - else: - return str(msgid2) - def info(self): return self._info @@ -235,15 +222,14 @@ class NullTranslations: def set_output_charset(self, charset): self._output_charset = charset - def install(self, str=False, names=None): + def install(self, names=None): import builtins - builtins.__dict__['_'] = str and self.ugettext or self.gettext + builtins.__dict__['_'] = self.gettext if hasattr(names, "__contains__"): if "gettext" in names: builtins.__dict__['gettext'] = builtins.__dict__['_'] if "ngettext" in names: - builtins.__dict__['ngettext'] = (str and self.ungettext - or self.ngettext) + builtins.__dict__['ngettext'] = self.ngettext if "lgettext" in names: builtins.__dict__['lgettext'] = self.lgettext if "lngettext" in names: @@ -367,31 +353,27 @@ class GNUTranslations(NullTranslations): else: return msgid2 - def ugettext(self, message): + def gettext(self, message): missing = object() tmsg = self._catalog.get(message, missing) if tmsg is missing: if self._fallback: - return self._fallback.ugettext(message) + return self._fallback.gettext(message) return str(message) return tmsg - gettext = ugettext - - def ungettext(self, msgid1, msgid2, n): + def ngettext(self, msgid1, msgid2, n): try: tmsg = self._catalog[(msgid1, self.plural(n))] except KeyError: if self._fallback: - return self._fallback.ungettext(msgid1, msgid2, n) + return self._fallback.ngettext(msgid1, msgid2, n) if n == 1: tmsg = str(msgid1) else: tmsg = str(msgid2) return tmsg - ngettext = ungettext - # Locate a .mo file using the gettext strategy def find(domain, localedir=None, languages=None, all=0): @@ -465,9 +447,9 @@ def translation(domain, localedir=None, languages=None, return result -def install(domain, localedir=None, str=False, codeset=None, names=None): +def install(domain, localedir=None, codeset=None, names=None): t = translation(domain, localedir, fallback=True, codeset=codeset) - t.install(str, names) + t.install(names) |