Merge pull request #284 from LucianU/patch-1
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Spelling, grammar, and punctuation fixes to extensions docs.
authored by Armin Ronacher · committed by Armin Ronacher · parents 6a04a8b, 07497dc · Browse files · 1 file·+12 added−12 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+12 added−12 removed
- other:+12 added−12 removed
Provenance
- Commit
0d52d72- Tree
3b03ca3- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent 1
6a04a8b- Parent 2
07497dc
1 file changed+12 added−12 removed
modified:docs/extensions.rst+12 added-12 removed
2 unmodified lines3 Extensions4 ==========5 6 Jinja2 supports extensions that can add extra filters, tests, globals or even7-extend the parser. The main motivation of extensions is it to move often used7+extend the parser. The main motivation of extensions is to move often used8 code into a reusable class like adding support for internationalization.9 10 11 Adding Extensions1 unmodified line13 14 Extensions are added to the Jinja2 environment at creation time. Once the15 environment is created additional extensions cannot be added. To add an16 extension pass a list of extension classes or import paths to the17-`environment` parameter of the :class:`Environment` constructor. The following17+`extensions` parameter of the :class:`Environment` constructor. The following18 example creates a Jinja2 environment with the i18n extension loaded::19 20 jinja_env = Environment(extensions=['jinja2.ext.i18n'])21 9 unmodified lines31 used in combination with `gettext`_ or `babel`_. If the i18n extension is32 enabled Jinja2 provides a `trans` statement that marks the wrapped string as33 translatable and calls `gettext`.34 35-After enabling dummy `_` function that forwards calls to `gettext` is added35+After enabling, dummy `_` function that forwards calls to `gettext` is added36 to the environment globals. An internationalized application then has to37-provide at least an `gettext` and optionally a `ngettext` function into the38-namespace. Either globally or for each rendering.37+provide a `gettext` function and optionally an `ngettext` function into the38+namespace, either globally or for each rendering.39 40 Environment Methods41 ~~~~~~~~~~~~~~~~~~~42 43-After enabling of the extension the environment provides the following43+After enabling the extension, the environment provides the following44 additional methods:45 46 .. method:: jinja2.Environment.install_gettext_translations(translations, newstyle=False)47 48- Installs a translation globally for that environment. The tranlations48+ Installs a translation globally for that environment. The translations49 object provided must implement at least `ugettext` and `ungettext`.50 The `gettext.NullTranslations` and `gettext.GNUTranslations` classes51 as well as `Babel`_\s `Translations` class are supported.52 35 unmodified lines88 string was extracted from embedded Python code), and89 * `message` is the string itself (a `unicode` object, or a tuple90 of `unicode` objects for functions with multiple string arguments).91 92- If `Babel`_ is installed :ref:`the babel integration <babel-integration>`92+ If `Babel`_ is installed, :ref:`the babel integration <babel-integration>`93 can be used to extract strings for babel.94 95 For a web application that is available in multiple languages but gives all96 the users the same language (for example a multilingual forum software27 unmodified lines124 125 What's the big difference between standard and newstyle gettext calls? In126 general they are less to type and less error prone. Also if they are used127 in an autoescaping environment they better support automatic escaping.128-Here some common differences between old and new calls:128+Here are some common differences between old and new calls:129 130 standard gettext:131 132 .. sourcecode:: html+jinja11 unmodified lines144 {{ gettext('Hello World!') }}145 {{ gettext('Hello %(name)s!', name='World') }}146 {{ ngettext('%(num)d apple', '%(num)d apples', apples|count) }}147 148-The advantages of newstyle gettext is that you have less to type and that148+The advantages of newstyle gettext are that you have less to type and that149 named placeholders become mandatory. The latter sounds like a150 disadvantage but solves a lot of troubles translators are often facing151 when they are unable to switch the positions of two placeholder. With152 newstyle gettext, all format strings look the same.20 unmodified lines173 174 **Import name:** `jinja2.ext.loopcontrols`175 176 This extension adds support for `break` and `continue` in loops. After177-enabling Jinja2 provides those two keywords which work exactly like in177+enabling, Jinja2 provides those two keywords which work exactly like in178 Python.179 180 .. _with-extension:181 33 unmodified lines215 216 By writing extensions you can add custom tags to Jinja2. This is a non trival217 task and usually not needed as the default tags and expressions cover all218 common use cases. The i18n extension is a good example of why extensions are219-useful, another one would be fragment caching.219+useful. Another one would be fragment caching.220 221 When writing extensions you have to keep in mind that you are working with the222 Jinja2 template compiler which does not validate the node tree you are passing223 to it. If the AST is malformed you will get all kinds of compiler or runtime124 unmodified lines