From ac91d5ef086f466c27e77157c67fe4f1df9b7557 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Sat, 4 Dec 2010 07:44:00 +0000 Subject: [PATCH] Fixed #14807 -- Ensure that boolean values aren't localized as T.rue and Fa.lse because of the thousand separator. Thanks to vanschelven for the report and patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@14804 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/utils/formats.py | 5 ++++- tests/regressiontests/i18n/tests.py | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/django/utils/formats.py b/django/utils/formats.py index 18fcbb600f..c23a37cb2b 100644 --- a/django/utils/formats.py +++ b/django/utils/formats.py @@ -6,6 +6,7 @@ from django.utils.translation import get_language, to_locale, check_for_language from django.utils.importlib import import_module from django.utils.encoding import smart_str from django.utils import dateformat, numberformat, datetime_safe +from django.utils.safestring import mark_safe # format_cache is a mapping from (format_type, lang) to the format string. # By using the cache, it is possible to avoid running get_format_modules @@ -114,7 +115,9 @@ def localize(value, use_l10n=None): If use_l10n is provided and is not None, that will force the value to be localized (or not), overriding the value of settings.USE_L10N. """ - if isinstance(value, (decimal.Decimal, float, int, long)): + if isinstance(value, bool): + return mark_safe(unicode(value)) + elif isinstance(value, (decimal.Decimal, float, int, long)): return number_format(value, use_l10n=use_l10n) elif isinstance(value, datetime.datetime): return date_format(value, 'DATETIME_FORMAT', use_l10n=use_l10n) diff --git a/tests/regressiontests/i18n/tests.py b/tests/regressiontests/i18n/tests.py index 615ffe822c..f552795f06 100644 --- a/tests/regressiontests/i18n/tests.py +++ b/tests/regressiontests/i18n/tests.py @@ -268,6 +268,7 @@ class FormattingTests(TestCase): self.assertEqual(u'66.666,666', localize(self.n)) self.assertEqual(u'99.999,999', localize(self.f)) self.assertEqual(u'10.000', localize(self.l)) + self.assertEqual(u'True', localize(True)) settings.USE_THOUSAND_SEPARATOR = False self.assertEqual(u'66666,666', localize(self.n))