Skip to content
Myr

Ticket #292 - Allow custom translator to be specified in the environment.

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

--HG-- branch : trunk

authored by Lakin Wecker · committed by Lakin Wecker · parent 1986d2c · Browse files · 1 file+11 added−2 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+11 added−2 removed

  • other:+11 added−2 removed

1 file+11 added−2 removed

modified:jinja/environment.py+11 added-2 removed
10 unmodified lines
11from jinja.lexer import Lexer12from jinja.parser import Parser13from jinja.loaders import LoaderWrapper14from jinja.datastructure import SilentUndefined, Markup, Context, FakeTranslator15from jinja.translators.python import PythonTranslator 16from jinja.utils import collect_translations, get_attribute17from jinja.exceptions import FilterNotFound, TestNotFound, \18 SecurityException, TemplateSyntaxError19from jinja.defaults import DEFAULT_FILTERS, DEFAULT_TESTS, DEFAULT_NAMESPACE
34 unmodified lines
54 context_class=Context,55 undefined_singleton=SilentUndefined,56 disable_regexps=False,57 friendly_traceback=True,57 translator_factory=None):58 translator_factory=None,59 template_translator=PythonTranslator):60 """61 Here the possible initialization parameters:6263 ========================= ============================================
54 unmodified lines
118 `translator_factory` A callback function that is called with119 the context as first argument to get the120 translator for the current instance.121 *new in Jinja 1.2*122 `template_translator` An class that defines a static method called123 process which can be used to process the 124 template's AST into a compiled python module.125 *new in Jinja 1.2*126 ========================= ============================================127128 All of these variables except those marked with a star (*) are129 modifiable after environment initialization.
36 unmodified lines
166167 # and here the translator factory168 self.translator_factory = translator_factory169170 # and here the AST translator171 self.template_translator = template_translator172173 # create lexer174 self.lexer = Lexer(self)175176 def loader(self, value):
50 unmodified lines
227 """228 Load a template from a loader. If the template does not exist, you229 will get a `TemplateNotFound` exception.230 """222 return self._loader.load(filename)231 return self._loader.load(filename, translator=self.template_translator)232233 def to_unicode(self, value):234 """235 Convert a value to unicode with the rules defined on the environment.
169 unmodified lines