跳转到主要内容

可翻译模板

项目描述

应用程序提供了将模板存储在数据库中并使用django-modeltranslation应用程序进行本地化的功能。如果您需要频繁更改模板内容而不想每次都重新编译所有ugettext消息,这很有用。它也适用于电子邮件模板。

在Django 1.4.5上进行了测试。

要求

  • Django

  • django-modeltranslation

安装

  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. 运行来自modeltranslation应用程序的sync_translation_fieldsupdate_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)

作者

此库由来自Pragmatic MatesErik Telepovsky创建。请参阅我们的其他库

项目详情


下载文件

下载适用于您的平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分发

django-templates-i18n-0.1.0.tar.gz (2.9 kB 查看哈希值)

上传时间

支持