[Django] #35389: stringformat filter in template breaks numeric localization

10 views
Skip to first unread message

Django

unread,
Apr 18, 2024, 1:31:00 PM4/18/24
to django-...@googlegroups.com
#35389: stringformat filter in template breaks numeric localization
-------------------------------------+-------------------------------------
Reporter: Danic | Owner: nobody
Type: Bug | Status: new
Component: Template | Version: 5.0
system | Keywords: locale,
Severity: Normal | localization
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
The stringformat filter breaks the numeric localization in the template.

With these settings

{{{
LANGUAGES = [
("de", _("German")),
("en", _("English")),
]
LANGUAGE_CODE = "de"
TIME_ZONE = "Europe/Berlin"
USE_I18N = True
USE_TZ = True
}}}

the following template

{{{
{{ 3.14 }}
{{ 3.14 | localize }}
{{ 3.14 | unlocalize }}
{{ 3.14159265359 | stringformat:".2f" }}
{{ 3.14159265359 | stringformat:".2f" | localize }}
{{ 3.14159265359 | stringformat:".2f" | unlocalize }}
}}}


Should print

{{{
3,14
3,14
3.14
3,14
3,14
3.14
}}}

but factually prints

{{{
3,14
3,14
3.14
3.14 <--
3.14 <--
3.14
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35389>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 18, 2024, 2:58:22 PM4/18/24
to django-...@googlegroups.com
#35389: stringformat filter in template breaks numeric localization
-------------------------------------+-------------------------------------
Reporter: Danic | Owner: nobody
Type: Bug | Status: closed
Component: Template system | Version: 5.0
Severity: Normal | Resolution: invalid
Keywords: locale, | Triage Stage:
localization | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* resolution: => invalid
* status: new => closed

Comment:

It's explicitly
[https://docs.djangoproject.com/en/stable/ref/templates/builtins/#stringformat
documented] that `stringformat`:

> ''Formats the variable according to the argument, a **string formatting
specifier**. This specifier uses the **printf-style String Formatting
syntax**, with the exception that the leading “%” is dropped.''

and in Python docs you will find that `.` is always used as a decimal
separate. `localize/unlocalize` doesn't affect strings so everything works
as expected.
--
Ticket URL: <https://code.djangoproject.com/ticket/35389#comment:1>
Reply all
Reply to author
Forward
0 new messages