Skip to content
Myr

[svn] added django translator documentation

Before adoption: this commit came in with the history the project adopted, so no landing records it.

--HG-- branch : trunk

authored by Armin Ronacher · committed by Armin Ronacher · parent 649c7b9 · Browse files · 1 file+24 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+24 added−1 removed

  • other:+24 added−1 removed

1 file+24 added−1 removed

modified:docs/src/devrecipies.txt+24 added-1 removed
81 unmodified lines
82function similar to the one shipped with django just that it uses Jinja for83rendering. It applies the context processors on the context and consumes a84`RequestContext`:8586.. sourcecode:: jinja86.. sourcecode:: python8788 from django.template.context import get_standard_processors89 from django.http import HttpResponse90 from jinja import Environment, FileSystemLoader, ChoiceLoader
9 unmodified lines
100 if request:101 for processor in get_standard_processors():102 context.update(processor(request))103 return HttpResponse(template.render(context))104105106If you want to plug Jinja into the Django i18n system you can use this107environment class:108109.. sourcecode:: python110111 from jinja import Environment112 from django.utils.translation import gettext, ngettext113114 class DjangoTranslator(object):115116 def __init__(self):117 self.gettext = gettext118 self.ngettext = ngettext119120 class DjangoEnvironment(Environment):121122 def get_translator(self, context):123 return DjangoTranslator()124125Because Django uses gettext internally we can create just assign the126ngettext and gettext functions directly to the translator class.