How to switch L10N in django
LANGUAGE_CODE = 'ru-RU'
USE_I18N = True
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current loca开发者_开发问答le
USE_L10N = False
{{ post.date_added|date:"b" }} gives "окт" in templates. If I set USE_I18N = False then it gives oct as it should be. Is this a bug ? How can I solve this problem ? Are there any possibilities to disable USE_I18N in template (in part of it) ?
Django relies on strftime heavily, but : http://docs.python.org/library/datetime.html
Directive Meaning Notes
%a Locale’s abbreviated weekday name.
%A Locale’s full weekday name.
%b Locale’s abbreviated month name.
%B Locale’s full month name.
So when USE_I18N=True the month name is converted into russian because it's locale dependent. Will write my own template tag probably :(
As of Django 1.3 You can use localize
and unlocalize
filters (after loading library l10n
i.e. doing {% load l10n %}
).
You could try this:
{% load l10n %}
{{ post.date_added|unlocalize|date:"b" }}
精彩评论