可翻译模板

django-templates-i18n的Python项目详细描述


应用程序提供了在数据库中存储模板并使用django modeltransflation应用程序本地化模板的能力。 如果您需要经常更改模板内容,并且不想重新编译所有ugettext消息,则此功能非常有用。 一直如此。它也适用于电子邮件模板。

在Django 1.4.5测试。

要求

  • Django
  • Django模型转换

安装

  1. 使用pip安装python库:pip install django-templates-i18n

  2. templates_i18n添加到django设置文件中的INSTALLED_APPS

  3. 同步并迁移数据库

  4. 在django设置文件中指定所需的语言:

    from django.utils.translation import gettext
    
    LANGUAGE_CODE = 'en'
    LANGUAGES = (
        ('en', gettext('English')),
        ('de', gettext('German')),
    )
    
  5. 运行sync_translation_fieldsupdate_translation_fields命令(来自modeltranslationapp)

用法

每当父字段更改时,都会进行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)

作者

图书馆由Pragmatic Mateserik telepovsky提供。见our other libraries

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Spring MVC 4.0 RequestMapping无值,基于methodname   java Samsung 10 plus不允许wifi p2p发现   春爪哇。伊奥。IOException:找不到文件   java JasperReport饼图示例   java我试图使用mockito注释来测试我的代码,但无法解决mockito异常   命令行界面Java:制作简单的交互式cli应用程序   java jdk1之间的区别是什么。7_9 9和jdk1。7_271   java重载一个被重写的、继承的方法   java LazyInitializationException春季启动   java Play Framework 2.2.1 3个表之间存在大量关系