diff --git a/django/utils/translation/__init__.py b/django/utils/translation/__init__.py index 7311a6145c..9d9e4a1e65 100644 --- a/django/utils/translation/__init__.py +++ b/django/utils/translation/__init__.py @@ -107,6 +107,12 @@ def lazy_number(func, resultclass, number=None, **kwargs): proxy = lazy(func, resultclass)(**kwargs) else: 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): if isinstance(rhs, dict) and number: try: diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py index 08ed5abe86..7d7d7210ab 100644 --- a/tests/i18n/tests.py +++ b/tests/i18n/tests.py @@ -227,6 +227,10 @@ class TranslationTests(SimpleTestCase): ) 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) def test_pgettext(self): trans_real._active = local()