Reputation: 1272
I used ugettext in one of my tasks. I had edited the po file. But it didn't work. Does anyone know why? thanks!
from django.utils.translation import ugettext
@task
def testtask():
.....
msg = ugettext('test')
.....
Read the celery document, I put the language parameter in the task, and do activate(language) before msg = ugettext('test') ,and it works.
Upvotes: 3
Views: 2086
Reputation: 16644
Django determines the current language using the LocaleMiddleware. As a celery task is processed out of any request scope, so it will fall back to LANGUAGE_CODE. As you stated you need to activated the language manually, then the language is bound to the local thread and therefore available for ugettext
.
Upvotes: 4