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 =)
If it didn’t already exist, you would need to write a template context processor. Here’s how you’d do that.
Put this somewhere:
And then, add a reference to it the
TEMPLATE_CONTEXT_PROCESSORSsetting. Something like this:(I recommend adding to the global setting because it means you don’t break things accidentally when a new context processor is added to the defaults.)
However, it does exist, as the inbuilt template context processor
django.template.context_processors.i18n. You can access it asLANGUAGE_CODE.Purely for interest, here’s the definition of that function:
Make sure that you’re using a
RequestContextfor your template rendering, not a plainContext, or it won’t work.