Search code examples
htmldjangobrowserlang

Force browser to render with en locale


I am dealing with a browser rendering problem that renders decimal points using a comma, instead of a dot, in some languages. This breaks some javascript code.

I tried setting lang attribute to en on the script/HTML tags and it appears not to work, and the browser still renders decimal points using a comma.

My question is there a way to override the Accept-Language header, and set it to only use en?

I am using Django. Otherwise dealing with this case directly in the code seems the only way.

The Problem:

99,00

What I want:

99.00


Solution

  • You should set the locale settings explicitly on settings. Django gives you a lot of possibilities when it comes to these settings.

    DECIMAL_SEPARATOR = '.'
    LANGUAGE_CODE = 'en-us'
    USE_I18N = True
    USE_L10N = True
    

    I believe that using the DECIMAL_SEPARATOR setting might solve your issue. Here is the link to documentation:

    https://docs.djangoproject.com/en/2.0/ref/settings/#decimal-separator