1👍
Here is what I ended up doing – completely naked and without any test/check/exception-handling:
from importlib import import_module
from django.utils.translation import get_language
fm = import_module('.formats', 'django.conf.locale.%s' % get_language())
try:
return getattr(fm, 'DECIMAL_SEPARATOR')
except AttributeError:
return '.'
0👍
Django has native localization built in for both templates and forms.
Where are you determining this?
In a template:
{% load l10n %}{% localize on %}{{ value }}{% endlocalize %}
Or in a form:
To enable a form field to localize input and output data simply use its
localize argument:
class CashRegisterForm(forms.Form):
product = forms.CharField()
revenue = forms.DecimalField(max_digits=4, decimal_places=2, localize=True)
You have to enable the localization module:
The formatting system is disabled by default. To enable it, it’s necessary to set
USE_L10N = True
in your settings file.
- Prevent Django from logout through url before hitting enter
- Django, how can I loop through the choices in HTML and display in radio buttons?
0👍
from django.util.format import get_format #or get_format_lazy
from django.utils.translation import get_language
decimal_seperator = get_format('DECIMAL_SEPARATOR',get_language())
Feel free to use ‘DATE_FORMAT’, ‘THOUSAND_SEPARATOR’,’NUMBER_GROUPING’ etc instead of ‘DECIMAL_SEPARATOR’
I got import error at some point using @jens-lundstrom answer.
Source:stackexchange.com