可翻译模板
项目描述
应用程序提供了将模板存储在数据库中并使用django-modeltranslation应用程序进行本地化的功能。如果您需要频繁更改模板内容而不想每次都重新编译所有ugettext消息,这很有用。它也适用于电子邮件模板。
在Django 1.4.5上进行了测试。
要求
Django
django-modeltranslation
安装
使用pip安装Python库:pip install django-templates-i18n
将templates_i18n添加到您的Django设置文件中的INSTALLED_APPS
同步和迁移您的数据库
在您的Django设置文件中指定所需的语言
from django.utils.translation import gettext LANGUAGE_CODE = 'en' LANGUAGES = ( ('en', gettext('English')), ('de', gettext('German')), )
运行来自modeltranslation应用程序的sync_translation_fields和update_translation_fields命令
使用方法
每当父字段更改时,都会进行Ajax调用。您必须设置Ajax URL以返回json列表列表
from django.http import HttpResponse from django.template import Template, Context from django.views.generic import View from templates_i18n.models import Template_i18n class MyView(View): def dispatch(self, request, *args, **kwargs): template_i18n = Template_i18n.objects.get(machine_name='my-template') template = Template(template_i18n.content) context = Context({'user': request.user}) return HttpResponse(template.render(context))
或
from django.core.mail import send_mail from django.template import Template, Context from templates_i18n.models import Template_i18n def dispatch(self, request, *args, **kwargs): template_i18n = Template_i18n.objects.get(machine_name='my-template') template = Template(template_i18n.content) context = Context({'user': request.user}) message = template.render(context) send_mail('Subject here', message, 'from@example.com', ['to@example.com'], fail_silently=False)
项目详情
关闭
django-templates-i18n-0.1.0.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 981ea2d50790e0e290f3ae7d94ea1dd22ef2bfedad2db07ca53651a71262a167 |
|
MD5 | 3856d49d68020433e68131b2a4ae58e3 |
|
BLAKE2b-256 | 766c15e4316eeb4a6780e88b2b3d36fe16b59db66165fef7803fc6ad4170acf0 |