Reputation: 222
I have a celery task that sends an email asynchronously
from djcelery.common import respects_language
@task(ignore_result=True)
@respects_language
def async_send_activation_email(registration_profile):
registration_profile.send_activation_email()
And the send activation email function
from django.core import context_processors
def send_activation_email(self):
variables = {
'some_variable':'something',
}
context = context_processors.i18n(None) # Allows to easily get all the language information into context. None is passed as the request does not matter for this context_processor.
# Subject
# Email subject *must not* contain newlines
subject = render_to_string(
'user_manager/activation/email_subject.txt',
variables,
context
)
...
context contains the correct informations (in my case LANGUAGE = 'fr', and other language options). Which is normal as they are correctly set by the @respects_language
decorator.
but render_to_string use the fallback language anyway.
Any idea about what might be happening ?
Upvotes: 3
Views: 1203
Reputation: 11
If you using docker for celery
Than need compile message for celery
#!/bin/bash
set -o errexit
set -o pipefail
set -o nounset
source $DJANGO_READ_DOT_ENV_SECRETS
echo "Compiling messages..."
# For example
python /app/manage.py compilemessages --locale=fr --ignore="venv/*" --ignore="local/*"
celery -A config.celery_app worker -l INFO
Upvotes: 0
Reputation: 2263
Try to use
from django.utils import translation
translation.activate('fr')
EDIT
Solution from comments on the question:
check your locale paths, they might be different when they are executed in celery.
Upvotes: 5