mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
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>
This commit is contained in:
parent
8a2b65a357
commit
ab75964b9a
@ -247,21 +247,27 @@ class Gettext(LazyText):
|
|||||||
return '%s(%r, domain=%r, localedir=%r)' % (self.__class__.__name__,
|
return '%s(%r, domain=%r, localedir=%r)' % (self.__class__.__name__,
|
||||||
self.msg, self.domain, self.localedir)
|
self.msg, self.domain, self.localedir)
|
||||||
|
|
||||||
def __str__(self):
|
def as_unicode(self):
|
||||||
"""
|
"""
|
||||||
Translate this message and return as a ``unicode`` instance.
|
Translate this message and return as a ``unicode`` instance.
|
||||||
"""
|
"""
|
||||||
if self.key in context.__dict__:
|
if self.key in context.__dict__:
|
||||||
g = context.__dict__[self.key].ugettext
|
t = context.__dict__[self.key]
|
||||||
else:
|
else:
|
||||||
g = create_translation(self.key).ugettext
|
t = create_translation(self.key)
|
||||||
return g(self.msg)
|
if six.PY2:
|
||||||
|
return t.ugettext(self.msg)
|
||||||
|
else:
|
||||||
|
return t.gettext(self.msg)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return unicode(self.as_unicode())
|
||||||
|
|
||||||
def __json__(self):
|
def __json__(self):
|
||||||
return self.__unicode__() #pylint: disable=no-member
|
return unicode(self) #pylint: disable=no-member
|
||||||
|
|
||||||
def __mod__(self, kw):
|
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
|
@six.python_2_unicode_compatible
|
||||||
@ -401,10 +407,13 @@ class NGettext(LazyText):
|
|||||||
|
|
||||||
def __call__(self, count):
|
def __call__(self, count):
|
||||||
if self.key in context.__dict__:
|
if self.key in context.__dict__:
|
||||||
ng = context.__dict__[self.key].ungettext
|
t = context.__dict__[self.key]
|
||||||
else:
|
else:
|
||||||
ng = create_translation(self.key).ungettext
|
t = create_translation(self.key)
|
||||||
return ng(self.singular, self.plural, count)
|
if six.PY2:
|
||||||
|
return t.ungettext(self.singular, self.plural, count)
|
||||||
|
else:
|
||||||
|
return t.ngettext(self.singular, self.plural, count)
|
||||||
|
|
||||||
|
|
||||||
@six.python_2_unicode_compatible
|
@six.python_2_unicode_compatible
|
||||||
|
Loading…
Reference in New Issue
Block a user