diff --git a/django/templatetags/l10n.py b/django/templatetags/l10n.py index b00a8b8606..9212753286 100644 --- a/django/templatetags/l10n.py +++ b/django/templatetags/l10n.py @@ -19,7 +19,7 @@ def unlocalize(value): Force a value to be rendered as a non-localized value, regardless of the value of ``settings.USE_L10N``. """ - return str(value) + return str(formats.localize(value, use_l10n=False)) class LocalizeNode(Node): diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py index 67e2eb6d46..752940b614 100644 --- a/tests/i18n/tests.py +++ b/tests/i18n/tests.py @@ -1017,20 +1017,30 @@ class FormattingTests(SimpleTestCase): def test_localize_templatetag_and_filter(self): """ - Tests the {% localize %} templatetag + Test the {% localize %} templatetag and the localize/unlocalize filters. """ - context = Context({'value': 3.14}) + context = Context({'float': 3.14, 'date': datetime.date(2016, 12, 31)}) template1 = Template( - '{% load l10n %}{% localize %}{{ value }}{% endlocalize %};' - '{% localize on %}{{ value }}{% endlocalize %}' + '{% load l10n %}{% localize %}{{ float }}/{{ date }}{% endlocalize %}; ' + '{% localize on %}{{ float }}/{{ date }}{% endlocalize %}' ) - template2 = Template("{% load l10n %}{{ value }};{% localize off %}{{ value }};{% endlocalize %}{{ value }}") - template3 = Template('{% load l10n %}{{ value }};{{ value|unlocalize }}') - template4 = Template('{% load l10n %}{{ value }};{{ value|localize }}') - output1 = '3,14;3,14' - output2 = '3,14;3.14;3,14' - output3 = '3,14;3.14' - output4 = '3.14;3,14' + template2 = Template( + '{% load l10n %}{{ float }}/{{ date }}; ' + '{% localize off %}{{ float }}/{{ date }};{% endlocalize %} ' + '{{ float }}/{{ date }}' + ) + template3 = Template( + '{% load l10n %}{{ float }}/{{ date }}; {{ float|unlocalize }}/{{ date|unlocalize }}' + ) + template4 = Template( + '{% load l10n %}{{ float }}/{{ date }}; {{ float|localize }}/{{ date|localize }}' + ) + expected_localized = '3,14/31. Dezember 2016' + expected_unlocalized = '3.14/Dez. 31, 2016' + output1 = '; '.join([expected_localized, expected_localized]) + output2 = '; '.join([expected_localized, expected_unlocalized, expected_localized]) + output3 = '; '.join([expected_localized, expected_unlocalized]) + output4 = '; '.join([expected_unlocalized, expected_localized]) with translation.override('de', deactivate=True): with self.settings(USE_L10N=False): self.assertEqual(template1.render(context), output1)