Django 芹菜任务中未翻译的电子邮件
我有一个芹菜任务,它异步发送电子邮件Django 芹菜任务中未翻译的电子邮件,django,internationalization,celery,Django,Internationalization,Celery,我有一个芹菜任务,它异步发送电子邮件 from djcelery.common import respects_language @task(ignore_result=True) @respects_language def async_send_activation_email(registration_profile): registration_profile.send_activation_email() 和发送激活电子邮件功能 from django.core impor
from djcelery.common import respects_language
@task(ignore_result=True)
@respects_language
def async_send_activation_email(registration_profile):
registration_profile.send_activation_email()
和发送激活电子邮件功能
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
)
...
上下文包含正确的信息(在我的例子中是LANGUAGE='fr'和其他语言选项)。这是正常的,因为它们是由@appresents\u语言
装饰器正确设置的
但无论如何都要使用回退语言
你知道会发生什么吗 尝试使用
from django.utils import translation
translation.activate('fr')
编辑
从对该问题的评论中得出的解决方案:
检查您的区域设置路径,它们在芹菜中执行时可能会不同。看看@apports\u语言是如何工作的,并说明了
get\u language
返回'fr'
您是否尝试在与render\u to\u字符串不同的地方使用该语言?比如打印一条消息或者类似的东西来测试它是否存在。另一件事可能是DjCellery没有正确设置区域设置路径…不,简单的ugettext或ugettext\u lazy也不起作用。我会调查现场路径,就是这样!感谢lotNp,我编辑了我的答案,以便其他人可以在那里找到解决方案。