【发布时间】:2013-11-28 15:08:56
【问题描述】:
我有一个异步发送电子邮件的 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 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 包含正确的信息(在我的情况下 LANGUAGE = 'fr' 和其他语言选项)。这是正常的,因为它们是由 @respects_language 装饰器正确设置的。
但 render_to_string 还是使用备用语言。
对可能发生的事情有任何想法吗?
【问题讨论】:
-
您是否尝试过在不同于 render_to_string 的东西上使用该语言?就像打印一条消息或类似的东西来测试它是否存在。另一件事可能是 djcelery 没有正确设置语言环境路径...
-
没有一个简单的 ugettext 或 ugettext_lazy 也不起作用。我将研究语言环境路径问题
-
就是这样!非常感谢
-
Np,我编辑了我的答案,以便其他人在那里找到解决方案。
标签: django internationalization celery