Is there's some global variable for gettin' language code in django template or atleast passing it through view? something like: {{ LANG }}
should produce "en" for example.. I really not comfortable when people using request.LANGUAGE_CODE
.
Detailed explanation would be appreciated =)
Functions of particular interest are django. utils. translation. get_language() which returns the language used in the current thread.
You cannot use python code in django template. This is by design, Django's idea of template is to isolate the presentation logic from the programming code.
This process relies on the GNU gettext toolset. Once this is done, Django takes care of translating web apps on the fly in each available language, according to users' language preferences.
It's an old topic. But some might find it useful.
{% load i18n %} ... {% get_current_language as LANGUAGE_CODE %}
Django reference and example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With