diff --git a/django/utils/formats.py b/django/utils/formats.py index d5e5a555f61..028e11415a0 100644 --- a/django/utils/formats.py +++ b/django/utils/formats.py @@ -197,6 +197,8 @@ def localize(value, use_l10n=None): elif isinstance(value, bool): # Make sure booleans don't get treated as numbers return str(value) elif isinstance(value, (decimal.Decimal, float, int)): + if use_l10n is False: + return str(value) 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/docs/releases/3.1.txt b/docs/releases/3.1.txt index c489f9cd89d..ba96ea670fc 100644 --- a/docs/releases/3.1.txt +++ b/docs/releases/3.1.txt @@ -677,6 +677,9 @@ Miscellaneous * The undocumented ``django.contrib.postgres.fields.jsonb.JsonAdapter`` class is removed. +* The :ttag:`{% localize off %} ` tag and :tfilter:`unlocalize` + filter no longer respect :setting:`DECIMAL_SEPARATOR` setting. + .. _deprecated-features-3.1: Features deprecated in 3.1 diff --git a/docs/topics/i18n/formatting.txt b/docs/topics/i18n/formatting.txt index 3dbb10f2dc6..f58ff0e9639 100644 --- a/docs/topics/i18n/formatting.txt +++ b/docs/topics/i18n/formatting.txt @@ -142,6 +142,9 @@ To force localization of a single value, use :tfilter:`localize`. To control localization over a large section of a template, use the :ttag:`localize` template tag. +Returns a string representation for unlocalized numbers (``int``, ``float``, +or ``Decimal``). + .. _custom-format-files: Creating custom format files diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py index 9b2d1258bc2..affda21fb42 100644 --- a/tests/i18n/tests.py +++ b/tests/i18n/tests.py @@ -1218,6 +1218,7 @@ class FormattingTests(SimpleTestCase): for use_l10n in [True, False]: with self.subTest(use_l10n=use_l10n), self.settings( USE_L10N=use_l10n, + DECIMAL_SEPARATOR=',', USE_THOUSAND_SEPARATOR=True, THOUSAND_SEPARATOR='°', NUMBER_GROUPING=2,