Lines Matching +full:- +full:gettext
1 .. _jinja-extensions:
12 -----------------
23 .. _i18n-extension:
26 --------------
30 The i18n extension can be used in combination with `gettext`_ or
32 marks a block as translatable and calls ``gettext``.
34 After enabling, an application has to provide ``gettext`` and
36 function is added as an alias to the ``gettext`` function.
47 ``translations`` object must implement ``gettext`` and ``ngettext``.
48 :class:`gettext.NullTranslations`, :class:`gettext.GNUTranslations`,
51 .. versionchanged:: 2.5 Added new-style gettext support.
55 Install no-op gettext functions. This is useful if you want to
59 .. versionchanged:: 2.5 Added new-style gettext support.
61 .. method:: jinja2.Environment.install_gettext_callables(gettext, ngettext, newstyle=False)
63 Install the given ``gettext`` and ``ngettext`` callables into the
65 :func:`gettext.gettext` and :func:`gettext.ngettext`.
68 newstyle callables. See :ref:`newstyle-gettext` for more information.
70 .. versionadded:: 2.5 Added new-style gettext support.
83 - ``lineno`` is the number of the line on which the string was
85 - ``function`` is the name of the ``gettext`` function used (if
87 - ``message`` is the string itself, or a tuple of strings for
90 If `Babel`_ is installed, see :ref:`babel-integration` to extract
98 .. code-block:: python
105 for the current configuration, for example by using ``gettext.find``.
108 :ref:`the template documentation <i18n-in-templates>`.
110 .. _gettext: https://docs.python.org/3/library/gettext.html target
124 enabling the ``ext.i18n.trimmed`` :ref:`policy <ext-i18n-trimmed>`.
127 .. _newstyle-gettext:
129 New Style Gettext
134 New style gettext calls are less to type, less error prone, and support
137 You can use "new style" gettext calls by setting
143 With standard ``gettext`` calls, string formatting is a separate step
149 {{ gettext("Hello, World!") }}
150 {{ gettext("Hello, %(name)s!")|format(name=name) }}
155 New style ``gettext`` make formatting part of the call, and behind the
160 {{ gettext("Hello, World!") }}
161 {{ gettext("Hello, %(name)s!", name=name) }}
164 The advantages of newstyle gettext are:
166 - There's no separate formatting step, you don't have to remember to
168 - Only named placeholders are allowed. This solves a common problem
172 - String formatting is used even if no placeholders are used, which
175 - The translated string is marked safe, formatting performs escaping
181 --------------------
185 The "do" aka expression-statement extension adds a simple ``do`` tag to the
189 .. _loopcontrols-extension:
192 -------------
200 .. _with-extension:
203 --------------
209 This extension is now built-in and no longer does anything.
211 .. _autoescape-extension:
214 --------------------
220 This extension was removed and is now built-in. Enabling the
224 .. _debug-extension:
227 ---------------
236 .. _writing-extensions:
239 ------------------
243 By writing extensions you can add custom tags to Jinja. This is a non-trivial
257 ------------------
290 Inline ``gettext``
294 to parse calls to the ``_()`` gettext function inline with static data
297 .. code-block:: html
309 -------------