Opened 7 months ago
Closed 7 months ago
#35389 closed Bug (invalid)
stringformat filter in template breaks numeric localization
Reported by: | Danic | Owned by: | nobody |
---|---|---|---|
Component: | Template system | Version: | 5.0 |
Severity: | Normal | Keywords: | locale, localization |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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
Note:
See TracTickets
for help on using tickets.
It's explicitly documented that
stringformat
: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.