Oleksiy
Oleksiy

Reputation: 816

How to translate dates in django template?

I've read documentation, I put i18n in top and tried to translate date variables by:

{%  blocktrans %}
                   {{ month_verbose }}
{% endblocktrans %}

But it doesn't work, also I want to translate month_verbose to current language. I don't know how to combine current language with translation with dates. So what is the best way to translate dates in django templates?

UPD View for this template Var month verbose is on 39th row Template here month verbose on 33rd row

Upvotes: 1

Views: 5954

Answers (1)

Derek Kwok
Derek Kwok

Reputation: 13058

Add django.middleware.locale.LocaleMiddleware to settings.MIDDLEWARE_CLASSES.

You can remove the blocktrans tags. Django date filter values are localized automatically when USE_L10N=True, so there's no need to use localize template tag or filter.

# prints out "uk"
{{ request.LANGUAGE_CODE }} 

# prints out "Січ"
{{ month_verbose|date:"M" }}

Upvotes: 4

Related Questions