luc
luc

Reputation: 43096

django : get the current locale inside a templatetag

I've an internationalized django (1.4) app.

In this app, I have a templatetag which needs to know what is the current language.

I think I could use django.utils.translation.get_language but it seems that inside the templatetag, it returns the default language and not the current language.

I fixed it by reading request.LANGUAGE_CODE from context.

But I would like to know if there is a better way to get the language in a templatetag

Upvotes: 2

Views: 752

Answers (1)

Hedde van der Heide
Hedde van der Heide

Reputation: 22449

There's a few default templatetags you can use

{% get_current_language %}

or

{% get_current_language as FOO %}

e.g.

{% render_bar request FOO %}

Upvotes: 2

Related Questions