diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2009-01-04 00:46:21 -0700 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2009-01-04 00:46:21 -0700 |
commit | c161784973fdedb146a4087d8692b157214c4db0 (patch) | |
tree | d6f318e607647b4163e52061a153f6a11287815f /ipalib | |
parent | c081ce5460018634fb30249ead2168ebf3a79044 (diff) | |
download | freeipa-c161784973fdedb146a4087d8692b157214c4db0.tar.gz freeipa-c161784973fdedb146a4087d8692b157214c4db0.tar.xz freeipa-c161784973fdedb146a4087d8692b157214c4db0.zip |
Added request.ugettext() and request.ungettext() functions; added corresponding unit tests
Diffstat (limited to 'ipalib')
-rw-r--r-- | ipalib/errors2.py | 4 | ||||
-rw-r--r-- | ipalib/request.py | 14 |
2 files changed, 13 insertions, 5 deletions
diff --git a/ipalib/errors2.py b/ipalib/errors2.py index 7fd4b9c9..4cb84870 100644 --- a/ipalib/errors2.py +++ b/ipalib/errors2.py @@ -38,7 +38,7 @@ to the caller. """ from inspect import isclass -import request +from request import ugettext, ungettext class PrivateError(StandardError): @@ -159,7 +159,7 @@ class PublicError(StandardError): def __init__(self, message=None, **kw): self.kw = kw if message is None: - message = self.get_format(request._) % kw + message = self.get_format() % kw StandardError.__init__(self, message) def get_format(self, _): diff --git a/ipalib/request.py b/ipalib/request.py index f5400b75..6ad7ad35 100644 --- a/ipalib/request.py +++ b/ipalib/request.py @@ -32,12 +32,20 @@ from constants import OVERRIDE_ERROR context = threading.local() -def _(message): - if hasattr(context, 'gettext'): - return context.gettext(message) +def ugettext(message): + if hasattr(context, 'ugettext'): + return context.ugettext(message) return message.decode('UTF-8') +def ungettext(singular, plural, n): + if hasattr(context, 'ungettext'): + return context.ungettext(singular, plural, n) + if n == 1: + return singular.decode('UTF-8') + return plural.decode('UTF-8') + + def set_languages(*languages): if hasattr(context, 'languages'): raise StandardError(OVERRIDE_ERROR % |