mirror of
https://github.com/django/django.git
synced 2025-07-04 01:39:20 +00:00
unicode: Implemented comparisons between *_lazy() objects. comparing
ugettext_lazy() instances to each other now works, for example. git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5489 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
2126d41aba
commit
f4387422f0
@ -64,6 +64,18 @@ def lazy(func, *resultclasses):
|
|||||||
else:
|
else:
|
||||||
return Promise.__str__(self)
|
return Promise.__str__(self)
|
||||||
|
|
||||||
|
def __cmp__(self, rhs):
|
||||||
|
if self._delegate_str:
|
||||||
|
s = str(self.__func(*self.__args, **self.__kw))
|
||||||
|
elif self._delegate_unicode:
|
||||||
|
s = unicode(self.__func(*self.__args, **self.__kw))
|
||||||
|
else:
|
||||||
|
s = self.__func(*self.__args, **self.__kw)
|
||||||
|
if isinstance(rhs, Promise):
|
||||||
|
return -cmp(rhs, s)
|
||||||
|
else:
|
||||||
|
return cmp(s, rhs)
|
||||||
|
|
||||||
def __mod__(self, rhs):
|
def __mod__(self, rhs):
|
||||||
if self._delegate_str:
|
if self._delegate_str:
|
||||||
return str(self) % rhs
|
return str(self) % rhs
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
|
||||||
ur"""
|
ur"""
|
||||||
>>> from django.utils.translation import ugettext_lazy, activate, deactivate
|
Format string interpolation should work with *_lazy objects.
|
||||||
|
|
||||||
|
>>> from django.utils.translation import ugettext_lazy, activate, deactivate, gettext_lazy
|
||||||
>>> s = ugettext_lazy('Add %(name)s')
|
>>> s = ugettext_lazy('Add %(name)s')
|
||||||
>>> d = {'name': 'Ringo'}
|
>>> d = {'name': 'Ringo'}
|
||||||
>>> s % d
|
>>> s % d
|
||||||
@ -14,4 +16,18 @@ u'Ringo hinzuf\xfcgen'
|
|||||||
u'Dodaj Ringo'
|
u'Dodaj Ringo'
|
||||||
>>> deactivate()
|
>>> deactivate()
|
||||||
|
|
||||||
|
It should be possible to compare *_lazy objects.
|
||||||
|
|
||||||
|
>>> s1 = ugettext_lazy('Add %(name)s')
|
||||||
|
>>> s == s1
|
||||||
|
True
|
||||||
|
>>> s2 = gettext_lazy('Add %(name)s')
|
||||||
|
>>> s3 = gettext_lazy('Add %(name)s')
|
||||||
|
>>> s2 == s3
|
||||||
|
True
|
||||||
|
>>> s == s2
|
||||||
|
True
|
||||||
|
>>> s4 = ugettext_lazy('Some other string')
|
||||||
|
>>> s == s4
|
||||||
|
False
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user