Issue
I googled a lot to find solution for my problem related to Django's L10N settings for en-IN
and found nothing satisfying which works. So, finally get back here to friends.
I'm struggling to format currency as Indian number formatting standard. Which follows NUMBER_GROUPING = (3, 2, 0)
and LANGUAGE_CODE = 'en-IN'
.
My current configurations of settings.py
file is:
LANGUAGE_CODE = 'en-IN'
USE_I18N = False
USE_L10N = True
USE_THOUSAND_SEPARATOR = True
NUMBER_GROUPING = (3, 2, 0)
Also tried setting:
USE_I18N = True
In template file I use:
{% load humanize %}
{# where object.price value is 524300 #}
<p>
{{ object.price }}
<!-- and -->
{{ object.price|intcomma }}
</p>
However this outputs:
524,300 instead 5,24,300
What am I doing wrong, which is stopping Django for follow settings of
LANGUAGE_CODE
,USE_L10N
andNUMBER_GROUPING
It works for hi-IN
If I changes
LANGUAGE_CODE = 'hi-IN'
, I get expected output of formatted currency as 5,24,300. But the problem is our site is not in Hindi language but in Indian English with Hindi localization. What a mess :(
Django Docs even showing example for language en_IN
. Which clearly telling it will format numbers as I expected. But it is not working for me.
Setting LANGUAGE_CODE = 'en_IN'
throws error. Do not accept underscore but hyphen.
My current system locale settings are as below:
LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=en_IN.UTF-8
LC_TIME=en_IN.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=en_IN.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=en_IN.UTF-8
LC_NAME=en_IN.UTF-8
LC_ADDRESS=en_IN.UTF-8
LC_TELEPHONE=en_IN.UTF-8
LC_MEASUREMENT=en_IN.UTF-8
LC_IDENTIFICATION=en_IN.UTF-8
LC_ALL=
Any idea or suggestion will really be appreciated!
Solution
I solved this problem using Django's custom format files for L10N.
I dig deep into docs and found this, solved my problem.
So, my new revision is here which solved my query even without changing LANGUAGE_CODE
.
My current mysite/settings.py
is:
USE_I18N = False
USE_L10N = True
FORMAT_MODULE_PATH = [
'mysite.formats'
]
And tree structure of formats is:
./mysite/formats/
|- __init__.py
|- en/
|- __init__.py
|- formats.py
# formats.py
USE_THOUSAND_SEPARATOR = True
NUMBER_GROUPING = (3, 2, 0)
And it works!
Answered By - Vin.AI
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.