#35333: Template tag `unlocalize` does not work with `date` and `time` filters.
-------------------------------------------+------------------------------
               Reporter:  Natalia Bidart   |          Owner:  Claude Paroz
                   Type:  Bug              |         Status:  assigned
              Component:  Template system  |        Version:  dev
               Severity:  Normal           |       Keywords:
           Triage Stage:  Accepted         |      Has patch:  0
    Needs documentation:  0                |    Needs tests:  0
Patch needs improvement:  0                |  Easy pickings:  0
                  UI/UX:  0                |
-------------------------------------------+------------------------------
 Following #35306, it was noticed that using the `date` or `time` template
 filters would not honor the `unlocalize` template tag. See regression
 tests:
 {{{#!diff
 diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py
 index 355505a10d..90cf4630bf 100644
 --- a/tests/i18n/tests.py
 +++ b/tests/i18n/tests.py
 @@ -1351,6 +1351,52 @@ class FormattingTests(SimpleTestCase):
                  self.assertEqual(template2.render(context), output2)
                  self.assertEqual(template3.render(context), output3)

 +    def test_unlocalize_honor_date_settings(self):
 +        filter_template = Template(
 +            "{% load l10n %}Localized: {{ my_value }}. "
 +            "Unlocalized: {{ my_value|unlocalize }}."
 +        )
 +        tag_template = Template(
 +            "{% load l10n %}Localized: {{ my_value }}. {% localize off
 %}"
 +            "Unlocalized: {{ my_value }}{% endlocalize %}."
 +        )
 +        filter_inside_unlocalize = Template(
 +            "{% load l10n %}Localized: {{ my_value|date }}. {% localize
 off %}"
 +            "Unlocalized: {{ my_value|date:'DATE_FORMAT' }}{% endlocalize
 %}."
 +        )
 +        context = Context({"my_value": datetime.date(2024, 12, 15)})
 +        expected_result = "Localized: 15. Dezember 2024. Unlocalized:
 15-12-2024."
 +        for case in (filter_template, tag_template,
 filter_inside_unlocalize):
 +            with (
 +                self.subTest(case=str(case)),
 +                translation.override("de", deactivate=True),
 +                self.settings(DATE_FORMAT="j-m-Y"),
 +            ):
 +                self.assertEqual(case.render(context), expected_result)
 +
 +    def test_unlocalize_honor_time_settings(self):
 +        filter_template = Template(
 +            "{% load l10n %}Localized: {{ my_value }}. "
 +            "Unlocalized: {{ my_value|unlocalize }}."
 +        )
 +        tag_template = Template(
 +            "{% load l10n %}Localized: {{ my_value }}. {% localize off
 %}"
 +            "Unlocalized: {{ my_value }}{% endlocalize %}."
 +        )
 +        filter_inside_unlocalize = Template(
 +            "{% load l10n %}Localized: {{ my_value|time }}. {% localize
 off %}"
 +            "Unlocalized: {{ my_value|time }}{% endlocalize %}."
 +        )
 +        context = Context({"my_value": datetime.time(1, 2, 3)})
 +        expected_result = "Localized: 01:02. Unlocalized: 01h 02m."
 +        for case in (filter_template, tag_template,
 filter_inside_unlocalize):
 +            with (
 +                self.subTest(case=str(case)),
 +                translation.override("de", deactivate=True),
 +                self.settings(TIME_FORMAT="H\\h i\\m"),
 +            ):
 +                self.assertEqual(case.render(context), expected_result)
 +
      def test_localized_off_numbers(self):
          """A string representation is returned for unlocalized
 numbers."""
          template = Template(
 }}}
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35333>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018e7c1a05f3-827eaa05-1e77-45c1-bd19-641f39ea6063-000000%40eu-central-1.amazonses.com.

Reply via email to