summaryrefslogtreecommitdiffstats
path: root/ipalib/text.py
diff options
context:
space:
mode:
authorPetr Viktorin <pviktori@redhat.com>2015-09-17 18:50:51 +0200
committerMartin Basti <mbasti@redhat.com>2015-10-22 18:34:46 +0200
commitab75964b9a5166568ce200a6356057ea47cb1ec3 (patch)
tree1a0565285e2644b6e37362a9f85e9aff4dd7018d /ipalib/text.py
parent8a2b65a35731470da0befeb01a4e863d782f0e6f (diff)
downloadfreeipa-ab75964b9a5166568ce200a6356057ea47cb1ec3.tar.gz
freeipa-ab75964b9a5166568ce200a6356057ea47cb1ec3.tar.xz
freeipa-ab75964b9a5166568ce200a6356057ea47cb1ec3.zip
Work around ipalib.text (i18n) str/unicode handling
Python 3 doesn't provide ugettext/ungettext, since gettext/ngettext work with (unicode) strings. Reviewed-By: Tomas Babej <tbabej@redhat.com>
Diffstat (limited to 'ipalib/text.py')
-rw-r--r--ipalib/text.py27
1 files changed, 18 insertions, 9 deletions
diff --git a/ipalib/text.py b/ipalib/text.py
index 9afe4d300..28953fa78 100644
--- a/ipalib/text.py
+++ b/ipalib/text.py
@@ -247,21 +247,27 @@ class Gettext(LazyText):
return '%s(%r, domain=%r, localedir=%r)' % (self.__class__.__name__,
self.msg, self.domain, self.localedir)
- def __str__(self):
+ def as_unicode(self):
"""
Translate this message and return as a ``unicode`` instance.
"""
if self.key in context.__dict__:
- g = context.__dict__[self.key].ugettext
+ t = context.__dict__[self.key]
+ else:
+ t = create_translation(self.key)
+ if six.PY2:
+ return t.ugettext(self.msg)
else:
- g = create_translation(self.key).ugettext
- return g(self.msg)
+ return t.gettext(self.msg)
+
+ def __str__(self):
+ return unicode(self.as_unicode())
def __json__(self):
- return self.__unicode__() #pylint: disable=no-member
+ return unicode(self) #pylint: disable=no-member
def __mod__(self, kw):
- return self.__unicode__() % kw #pylint: disable=no-member
+ return unicode(self) % kw #pylint: disable=no-member
@six.python_2_unicode_compatible
@@ -401,10 +407,13 @@ class NGettext(LazyText):
def __call__(self, count):
if self.key in context.__dict__:
- ng = context.__dict__[self.key].ungettext
+ t = context.__dict__[self.key]
+ else:
+ t = create_translation(self.key)
+ if six.PY2:
+ return t.ungettext(self.singular, self.plural, count)
else:
- ng = create_translation(self.key).ungettext
- return ng(self.singular, self.plural, count)
+ return t.ngettext(self.singular, self.plural, count)
@six.python_2_unicode_compatible