Fixed #25571 -- Fixed boolean evaluation of ungettext_lazy
This commit is contained in:
parent
1ce11f6064
commit
8b5acda821
|
@ -107,6 +107,12 @@ def lazy_number(func, resultclass, number=None, **kwargs):
|
||||||
proxy = lazy(func, resultclass)(**kwargs)
|
proxy = lazy(func, resultclass)(**kwargs)
|
||||||
else:
|
else:
|
||||||
class NumberAwareString(resultclass):
|
class NumberAwareString(resultclass):
|
||||||
|
def __bool__(self):
|
||||||
|
return bool(kwargs['singular'])
|
||||||
|
|
||||||
|
def __nonzero__(self): # Python 2 compatibility
|
||||||
|
return type(self).__bool__(self)
|
||||||
|
|
||||||
def __mod__(self, rhs):
|
def __mod__(self, rhs):
|
||||||
if isinstance(rhs, dict) and number:
|
if isinstance(rhs, dict) and number:
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -227,6 +227,10 @@ class TranslationTests(SimpleTestCase):
|
||||||
)
|
)
|
||||||
self.assertEqual(result % {'name': 'Joe', 'num': 4}, "Joe has 4 good results")
|
self.assertEqual(result % {'name': 'Joe', 'num': 4}, "Joe has 4 good results")
|
||||||
|
|
||||||
|
def test_ungettext_lazy_bool(self):
|
||||||
|
self.assertTrue(ungettext_lazy('%d good result', '%d good results'))
|
||||||
|
self.assertFalse(ungettext_lazy('', ''))
|
||||||
|
|
||||||
@override_settings(LOCALE_PATHS=extended_locale_paths)
|
@override_settings(LOCALE_PATHS=extended_locale_paths)
|
||||||
def test_pgettext(self):
|
def test_pgettext(self):
|
||||||
trans_real._active = local()
|
trans_real._active = local()
|
||||||
|
|
Loading…
Reference in New Issue