Opened 15 months ago

Closed 15 months ago

Last modified 15 months ago

#34543 closed Bug (needsinfo)

Thousand separator breaking templates

Reported by: Pablo Riquelme Owned by: nobody
Component: Internationalization Version: 4.2
Severity: Normal Keywords: thousand_separator, thousand, separator, spanish
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no


Hi, I'm having a really weird behavior regarding the thousand separator using the same settings as I used with Django 4.1.9 but it breaks in Django 4.2 and 4.2.1.

The settings are

In Django 4.1 (tested both in 4.1.1 and 4.1.9), with the settings above, when I call numbers on template it shows correctly like 9.800 (with the dot specified in the thousand separator), but in Django 4.2 and 4.2.1, the same template with the same settings shows 9 800 (with a blank space as thousand separator), I tried switching on and off the USE_L10N and USE_I18N but nothing happens and the documentation does not says anything about a change of the thousand separator in templates, might be that in the new version it could be necessary to use the humanize or similar tag to display the thousand separator now?
It's also weird that when I set USE_THOUSAND_SEPARATOR = False, the blank space drops and it shows 9800
This happens in all my templates

Thanks to the discord user sarahboyce for pointing a commit made to the django project that changes the thousand separator from a dot "." to "\xa0", and the settings applied in does not override this.

Change History (4)

comment:1 by Mariusz Felisiak, 15 months ago

Component: UncategorizedInternationalization
Resolution: needsinfo
Status: newclosed

Hi, I don't think you've explained the issue in enough detail to confirm a bug in Django. THOUSAND_SEPARATOR for the es language was changed intentionally, and as documented: "if USE_L10N is set to True, then the locale-dictated format has higher precedence and will be applied instead". Also, in Django 5.0+ the locale-dictated format always has higher precedence.

Please reopen the ticket if you can provide a sample project that reproduces the issue.

comment:2 by Natalia Bidart, 15 months ago

Hola Pablo, could you please share an example of code that would work as expected in Django < 4.2 but it does not work as expected in Django 4.2 or higher? I'm not being able to reproduce the issue (in fact, neither Django 4.1 or Django 4.2 are honoring my settings, so I must be doing something wrong).


comment:3 by Pablo Riquelme, 15 months ago

In my settings I use across Django 4.1 and 4.2.

USE_I18N = True
USE_L10N = True
TIME_ZONE = 'America/Santiago'

In Django 4.1 I call a model using the model.object.get(), the model has
int_value= models.IntegerField(default=0)
then I return the object to the template to show it on screen.

In my templates I call it with

Value ${{obj.int_value}}

For example, one object has int_value 15340

In the template with django up to 4.1.9, it shows "Value $15.340", the format that i want it.
In the template with django 4.2 and 4.2.1 it shows "Value $15 340", with the blank space instead of the dot as thousand_separator.

Django will ignore my settings of the Thousand Separator that I declared on my, it might be that in all of this time, the setting was ignores but de default thousand separator was the dot, until the commit that i linked on the original ticket when it changed to a blank space.

If i change the Setting USE_I18N and/or USE_L10N and keep the other settings intact, the only impact is that the number will lose the thousand separator and the language of the app.

comment:4 by Claude Paroz, 15 months ago

I would suggest you use instead custom locale format file(s):

Note: See TracTickets for help on using tickets.
Back to Top