pythondjangolocalization

Localized date strftime in Django view


I would like to send localized date in JSON from django view

Normal text translation via

ugettext

is OK

Following code in view has no effect:

translation.activate("ru")
print datetime.now().strtime("%B")

Output is "August", instead of "Август"

I read about python's "locale" module, but it's named as thread unsafe

How to force strftime to use django's locale?


Solution

  • Finally i used date filter from django templates:

    from django.template.defaultfilters import date as _date
    from datetime import datetime
    
    _date(datetime.now(), "d b, D")