Skip to content

Commit

Permalink
Fix i18n docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dag committed Dec 13, 2010
1 parent a3cb43b commit b4ff024
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
3 changes: 2 additions & 1 deletion docs/conf.py
Expand Up @@ -223,5 +223,6 @@
# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {
'http://docs.python.org/': None,
'http://flask.pocoo.org/docs': None
'http://flask.pocoo.org/docs': None,
'http://werkzeug.pocoo.org/documentation/dev/': None,
}
27 changes: 23 additions & 4 deletions docs/index.rst
Expand Up @@ -246,14 +246,19 @@ Using with Flask-Babel

You can use Flask-Genshi with `Flask-Babel`_ for internationalization.
First, set up the :class:`~genshi.filters.Translator` filter with
the callback interface via :meth:`~Genshi.template_parsed`::
the callback interface via :meth:`~Genshi.template_parsed`. The filter
wants a message catalogue and to get the right one for every request you
can use Werkzeug's :class:`~werkzeug.LocalProxy`::

from werkzeug import LocalProxy
from genshi.filters import Translator
from flaskext.babel import gettext
from flaskext.babel import get_translations

current_translations = LocalProxy(get_translations)

@genshi.template_parsed
def callback(template):
Translator(gettext).setup(template)
Translator(current_translations).setup(template)

You'll want a ``babel.cfg`` similar to this one:

Expand All @@ -265,7 +270,21 @@ You'll want a ``babel.cfg`` similar to this one:
template_class = genshi.template.NewTextTemplate
Consult the Genshi documentation on `Internationalization and Localization`_
for details on extracting translation strings from Genshi templates.
for details on extracting translation strings from Genshi templates. Beware
of a documentation bug though, the XML namespace should *not* end in a
slash. Here's a working template example:

.. code-block:: html+genshi

<html xmlns:i18n="http://genshi.edgewall.org/i18n">
<head>
<title i18n:msg="subtitle">Legendary Site - $title</title>
</head>
</html>

The above will result in the string ``Legendary Site - %(subtitle)s`` in
your message catalogue.


.. versionadded:: 0.5

Expand Down

0 comments on commit b4ff024

Please sign in to comment.