Rob*_*ert 3 email django translation internationalization
在我的商品网站中,如果商品符合某些要求(模型中指定的过滤器),用户可以设置电子邮件警
因此,当用户"A"添加商品时,post_save信号将被发送到芹菜并检查是否应用了用户警报过滤器,如果有,则发送电子邮件.
问题是我不知道如何安全地为每封发送的电子邮件设置内容.该服务以更多语言提供.用户可以更改其配置文件中的语言(通过User < - Userprofile.language())字段,以便每封电子邮件的语言都设置为UserProfile.language()值...
尝试使用translation.activate(userinstance.UserProfile.language),但这不会像我期望的那样工作.我看到translation.activate()为整个线程执行翻译激活?
PS:电子邮件内容是从模板呈现的.
Gar*_*ees 10
translation.activate 适合我:
$ ./manage.py shell
Python 2.7.2 (default, Jan 20 2012, 15:23:49)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.utils import translation
>>> translation.get_language()
'en-us'
>>> translation.ugettext('E-mail address')
u'E-mail address'
>>> translation.activate('fr')
>>> translation.ugettext('E-mail address')
u'Adresse électronique'
Run Code Online (Sandbox Code Playgroud)
模板也有效:
>>> from django.template import Context, Template
>>> Template('{% load i18n %}{% trans "E-mail address" %}').render(Context())
u'Adresse électronique'
Run Code Online (Sandbox Code Playgroud)
我不知道为什么它不适合你.你的UserProfile.language()功能会带来什么样的价值?
| 归档时间: |
|
| 查看次数: |
2501 次 |
| 最近记录: |