53π
β
I solved this by including code below in the template
{% load i18n %}
{% get_current_language as LANGUAGE_CODE %}
and the variable LANGUAGE_CODE
has the value you want (see also django docs for an example usage).
14π
You might want to write your own context processor, which would call to_locale
and automatically populate the context with the result β it would just be something like this.
from django.utils.translation import to_locale, get_language
def locale(request):
return {'LOCALE': to_locale(get_language())}
π€Ismail Badawi
- [Django]-Django multiple and dynamic databases
- [Django]-Django Queryset with filtering on reverse foreign key
- [Django]-Django β How to get self.id when saving a new object?
3π
I thought of implementing my own custom template tag that would simply output to_locale(get_language())
but the answer above is easier to implement so I like it better.
π€urig
- [Django]-Use Python standard logging in Celery
- [Django]-Django storages: Import Error β no module named storages
- [Django]-Django: FloatField or DecimalField for Currency?
Source:stackexchange.com