Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django date localization doesn't seem to work when run from command-line manage command

I have a template which uses {{date|date:"l j F"}} to localize a date. When I use it in a view this works fine (served from either ./manage.py runserver or uwsgi.

When I use this template to send an email from the command line using a management/commands command however, it falls back to the en_US locale. (Friday instead of Vrijdag etc)

I've included settings.LANGUAGE_CODE, settings.USE_L10N and settings.USE_I18N in the template to make sure which locale is being used, and then it says nl_NL in both cases, as expected.

Any ideas on how to fix this?

like image 356
quarkness Avatar asked Mar 19 '12 22:03

quarkness


1 Answers

It turns out one has to manually activate translation in management commands:

from django.utils import translation

translation.activate(settings.LANGUAGE_CODE)

did the trick. See https://code.djangoproject.com/ticket/10078

like image 199
quarkness Avatar answered Nov 07 '22 11:11

quarkness