`_
may also be extracted from Mako templates when a comment tag is
specified to `Babel`_ (such as with
the ``-c`` option).
For example, a project ``"myproj"`` contains the following Mako
template at ``myproj/myproj/templates/name.html``:
.. sourcecode:: mako
Name:
## TRANSLATORS: This is a proper name. See the gettext
## manual, section Names.
${_('Francois Pinard')}
To extract gettext messages from this template the project needs
a Mako section in its `Babel Extraction Method Mapping
file `_
(typically located at ``myproj/babel.cfg``):
.. sourcecode:: cfg
# Extraction from Python source files
[python: myproj/**.py]
# Extraction from Mako templates
[mako: myproj/templates/**.html]
input_encoding = utf-8
The Mako extractor supports an optional ``input_encoding``
parameter specifying the encoding of the templates (identical to
:class:`.Template`/:class:`.TemplateLookup`'s ``input_encoding`` parameter).
Invoking `Babel`_'s extractor at the
command line in the project's root directory:
.. sourcecode:: sh
myproj$ pybabel extract -F babel.cfg -c "TRANSLATORS:" .
will output a `gettext` catalog to `stdout` including the following:
.. sourcecode:: pot
#. TRANSLATORS: This is a proper name. See the gettext
#. manual, section Names.
#: myproj/templates/name.html:5
msgid "Francois Pinard"
msgstr ""
This is only a basic example:
`Babel`_ can be invoked from ``setup.py``
and its command line options specified in the accompanying
``setup.cfg`` via `Babel Distutils/Setuptools
Integration `_.
Comments must immediately precede a `gettext` message to be
extracted. In the following case the ``TRANSLATORS:`` comment would
not have been extracted:
.. sourcecode:: mako
## TRANSLATORS: This is a proper name. See the gettext
## manual, section Names.
Name: ${_('Francois Pinard')}
See the `Babel User
Guide `_
for more information.
.. _babel: http://babel.edgewall.org/
API Reference
=============
.. autoclass:: mako.template.Template
:show-inheritance:
:members:
.. autoclass:: mako.template.DefTemplate
:show-inheritance:
:members:
.. autoclass:: mako.lookup.TemplateCollection
:show-inheritance:
:members:
.. autoclass:: mako.lookup.TemplateLookup
:show-inheritance:
:members:
.. autoclass:: mako.exceptions.RichTraceback
:show-inheritance:
.. py:attribute:: error
the exception instance.
.. py:attribute:: message
the exception error message as unicode.
.. py:attribute:: source
source code of the file where the error occurred.
If the error occurred within a compiled template,
this is the template source.
.. py:attribute:: lineno
line number where the error occurred. If the error
occurred within a compiled template, the line number
is adjusted to that of the template source.
.. py:attribute:: records
a list of 8-tuples containing the original
python traceback elements, plus the
filename, line number, source line, and full template source
for the traceline mapped back to its originating source
template, if any for that traceline (else the fields are ``None``).
.. py:attribute:: reverse_records
the list of records in reverse
traceback -- a list of 4-tuples, in the same format as a regular
python traceback, with template-corresponding
traceback records replacing the originals.
.. py:attribute:: reverse_traceback
the traceback list in reverse.
.. autofunction:: mako.exceptions.html_error_template
.. autofunction:: mako.exceptions.text_error_template