Search code examples
htmldjangodjango-viewsinternationalization

Django internationalisation and digits behaviour


I have a website in English, Spanish, German and French. One of the tables has a meter bar like:

Bar example

<meter value="{{fav.value}}" min="0" max="10"></meter>

I found the meter bar only works in the English version, particularly, the meter goes from 0 to 10 with 2 decimals accuracy.

If I override the value in view.py with an integer value (e.g. fav.value = 2), it works in all languages. If I override the value with a float (e.g. fav.value = 2.5), it would only show the green meter fill in the English version.

Anyone has any idea what why this may be happening?


Solution

  • You probably have {% load l10n %} in your template. Django localizes the value for every locale. You can disable localization for that specific value.

    <meter value="{{fav.value|unlocalize}}" min="0" max="10"></meter>
    

    Documentation