django-templates-i18n
App provides ability to store templates in database and localize it using django-modeltranslation app. It is useful if you need to change template content too often and you don’t want to recompile all ugettext messages all the times. It is also suitable for email templates.
Tested on Django 1.4.5.
Requirements
Django
django-modeltranslation
Installation
Install python library using pip: pip install django-templates-i18n
Add templates_i18n to INSTALLED_APPS in your Django settings file
Sync and migrate your database
Specify desired languages in your Django settings file:
from django.utils.translation import gettext LANGUAGE_CODE = 'en' LANGUAGES = ( ('en', gettext('English')), ('de', gettext('German')), )Run sync_translation_fields and update_translation_fields commands (from modeltranslation app)
Usage
Ajax call is made whenever the parent field is changed. You must set up the ajax URL to return json list of lists:
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))
or:
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)
Metadata
Release files for django-templates-i18n 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django-templates-i18n-0.1.0.tar.gz | 2.9 kB | Without provenance | Details |
Release files / django-templates-i18n-0.1.0.tar.gz
| Download URL | django-templates-i18n-0.1.0.tar.gz |
|---|---|
| Size | 2.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
981ea2d50790e0e290f3ae7d94ea1dd22ef2bfedad2db07ca53651a71262a167
|
|
BLAKE2b-256 checksum How to use checksums |
766c15e4316eeb4a6780e88b2b3d36fe16b59db66165fef7803fc6ad4170acf0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-templates-i18n 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.