[Django] #33281: Thousand separator is the wrong character

101 views
Skip to first unread message

Django

unread,
Nov 12, 2021, 3:21:31 AM11/12/21
to django-...@googlegroups.com
#33281: Thousand separator is the wrong character
--------------------------------------------+------------------------
Reporter: Demetris Stavrou | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 3.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------------------------+------------------------
Given the following configuration:

{{{
# settings.py
LANGUAGE_CODE = 'el-gr'
USE_L10N = False
USE_THOUSAND_SEPARATOR = True
THOUSAND_SEPARATOR = ","
NUMBER_GROUPING = 3
}}}

{{{
# views.py
class ThousandView(TemplateView):
template_name = "thousand_template.html"

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["test_number"] = 1234
return context
}}}

{{{
# thousand_template.html
{% load humanize %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
{{ test_number|intcomma }}
</body>
</html>
}}}

one would expect that the `test_number` value is rendered as `1,234`.
However, it is rendered as `1.234`. I intentionally used `el-gr` because
the locale defines the thousand separator to be `.`. As shown in the
settings, this shouldn't matter since we use `USE_L10N=False`. However, it
seems that it affects the result, because if `en-us` is used instead, then
the number is rendered as `1,234`.

**Testing this with Django version 3.1.13, works as expected**, i.e. given
the above configuration, the number is correctly rendered as `1,234`.

--
Ticket URL: <https://code.djangoproject.com/ticket/33281>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 12, 2021, 3:53:47 AM11/12/21
to django-...@googlegroups.com
#33281: intcomma template filter doesn't depend on the USE_L10N setting.
----------------------------------+--------------------------------------

Reporter: Demetris Stavrou | Owner: nobody
Type: Uncategorized | Status: closed
Component: Template system | Version: 3.2
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Changes (by Mariusz Felisiak):

* cc: Claude Paroz (added)
* resolution: => invalid
* status: new => closed
* component: Uncategorized => Template system


Comment:

It's an intentional change and is mentioned in the
[https://docs.djangoproject.com/en/3.2/releases/3.2/#miscellaneous release
notes]:

> ''"The intcomma and intword template filters no longer depend on the
USE_L10N setting."''

see also bd4e409695f8d6deebb1b3f70ffb9bc670477c2a.

--
Ticket URL: <https://code.djangoproject.com/ticket/33281#comment:1>

Django

unread,
Nov 12, 2021, 9:54:09 AM11/12/21
to django-...@googlegroups.com
#33281: intcomma template filter doesn't depend on the USE_L10N setting.
----------------------------------+--------------------------------------
Reporter: Demetris Stavrou | Owner: nobody
Type: Uncategorized | Status: closed
Component: Template system | Version: 3.2
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------

Comment (by Demetris Stavrou):

Thank you for the information. However, I was not able to use a comma as a
thousands separator. I went through the documentation multiple times, and
it is not apparent how to achieve this. If the `intcomma` is removed from
the template, then the thousands separator disappears.

Maybe I am missing something, but based on the above, there seems to be an
issue; it could be in the documentation not being clear?

--
Ticket URL: <https://code.djangoproject.com/ticket/33281#comment:2>

Django

unread,
Nov 12, 2021, 10:24:43 AM11/12/21
to django-...@googlegroups.com
#33281: intcomma template filter doesn't depend on the USE_L10N setting.
----------------------------------+--------------------------------------
Reporter: Demetris Stavrou | Owner: nobody
Type: Uncategorized | Status: closed
Component: Template system | Version: 3.2
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------

Comment (by Claude Paroz):

I guess that for your use case, the better would be to create your own
`intcomma` filter that calls the Django `intcomma` with `use_l10n` param
to `False`.

--
Ticket URL: <https://code.djangoproject.com/ticket/33281#comment:3>

Django

unread,
Nov 15, 2021, 2:31:21 AM11/15/21
to django-...@googlegroups.com
#33281: intcomma template filter doesn't depend on the USE_L10N setting.
----------------------------------+--------------------------------------
Reporter: Demetris Stavrou | Owner: nobody
Type: Uncategorized | Status: closed
Component: Template system | Version: 3.2
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------

Comment (by Demetris Stavrou):

Thank you for suggesting how to solve this problem on my project. However,
the reason I opened this ticket was to help improve Django development
experience. I do believe that the documentation could improve to better
explain how this works. Honestly, it is not clear to me yet, what is going
on. I am walking you through my thought process, when looking at the
documentation:

> Note, however, that to enable number formatting with thousand separators
it is necessary to set USE_THOUSAND_SEPARATOR = True in your settings
file. Alternatively, you could use intcomma to format numbers in your
template.

Starting from here, even if I use `USE_THOUSAND_SEPARATOR=True` the `{{
<big_number> }}` is still rendered as `123456789 `. But based on the
documentation it should work, right? So going further in the
documentation:

> When set to True and USE_L10N is also True, Django will format numbers
using the NUMBER_GROUPING and THOUSAND_SEPARATOR settings.

From here, I am a bit confused as it is not clear whether I can use the
setting if `USE_L10N = False`. The sentence implies that I can use it in
either case. I also set `NUMBER_GROUPING = 3` and `THOUSAND_SEPARATOR =
","` as the documentation suggests. The `{{ <big_number> }}` is still
rendered as `123456789 `.

At this point I also try and set `USE_L10N = True`. The `{{ <big_number>
}}` is now rendered as `123.456.789 `. So the thousand separator now
works, but with the wrong character. This makes sense because the locale I
am using dictates `.` as the separator. However, the project requires `,`
as the separator. Going back to the documentation:

> These settings may also be dictated by the locale, which takes
precedence.

So the behavior I am seeing is correct, but I am stuck, because if I
remove the locale, the the separator disappears as well.

I am not sure what I am missing here, but is seems to me that the
separator settings make sense only when the localization is False, since
it takes precedence. But they don't seem to work at all.

I respect the decision of the maintainers to consider this as not an issue
and I am just including the above in case they are useful (I am not
expecting an answer).

--
Ticket URL: <https://code.djangoproject.com/ticket/33281#comment:4>

Django

unread,
Nov 15, 2021, 3:13:32 AM11/15/21
to django-...@googlegroups.com
#33281: intcomma template filter doesn't depend on the USE_L10N setting.
----------------------------------+--------------------------------------
Reporter: Demetris Stavrou | Owner: nobody
Type: Uncategorized | Status: closed
Component: Template system | Version: 3.2
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------

Comment (by Claude Paroz):

I feel your pain :-)
Django is currently in a transition period to
[https://docs.djangoproject.com/en/dev/releases/4.0/#use-l10n-deprecation
remove the USE_L10N settings], which we hope will simplify a bit the
settings combination hell. The downside is that it will make the life a
bit harder for those wanting to force some specific locale formatting for
their project. The documentation will also probably need some rework here
and there, so we appreciate your input.

--
Ticket URL: <https://code.djangoproject.com/ticket/33281#comment:5>

Reply all
Reply to author
Forward
0 new messages