7

I have a Django project with settings set to lang 'pl', in every template I use localized date format, for example:

{{ item.date|date:'D, d N H:i:s e' }}

result:
    Wt, 13 Lis 2012 22:00:00

But in only one template I must use format for lang 'en':

Thu, 13 Nov 2012 22:00:00 GMT

How can I accomplish this?

Chad
  • 19,219
  • 4
  • 50
  • 73
Nips
  • 13,162
  • 23
  • 65
  • 103
  • Have you tried the `unlocalize` template filter (with `{% load l10n %}`)? https://docs.djangoproject.com/en/1.3/topics/i18n/localization/#template-filters – Timmy O'Mahony Nov 13 '12 at 22:18
  • No, this not work, maybe because ulocalize set locale to server locales which is set to 'pl'... I don't know. {% localize off %} also not work – Nips Nov 13 '12 at 22:57
  • This answer can resolve your problem: http://stackoverflow.com/questions/9853906/django-switch-language-setting-for-template-rendering – Tarsis Azevedo Nov 13 '12 at 22:58

2 Answers2

23

This helps for me:

{% load i18n %}

{% language 'en' %}
  {{ item.date|date:'D, d N H:i:s e' }}
{% endlanguage %}

For more details, see the Django online documentation.

Q Caron
  • 952
  • 13
  • 26
mmtootmm
  • 800
  • 6
  • 17
2

This help for me, in that view where I use lang 'en' and load template:

from django.conf import settings

settings.LANGUAGE_CODE = 'en'
settings.USE_L10N = False
settings.USE_I18N = False
Nips
  • 13,162
  • 23
  • 65
  • 103
  • It's never a good idea to modify the global settings like this. Django provides `translation.override()` to set a language context within a view. – Tim Tisdall Apr 18 '23 at 15:07