Use with Other Extensions and Packages

Form Processing with flatland

First, set up flatland with the callback interface:

from flatland.out.genshi import setup

def callback(template):

Don’t forget the form namespace:

<html xmlns:form="">
  <input type="text" form:bind="form.username"/>

New in version 0.5.

Internationalization with Flask-Babel

You can use Flask-Genshi with Flask-Babel for internationalization. First, set up the Translator filter with the callback interface via template_parsed(). The filter wants a message catalogue and to get the right one for every request you can use Werkzeug’s LocalProxy:

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

current_translations = LocalProxy(get_translations)

def callback(template):

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

[python: **.py]
template_class = genshi.template.NewTextTemplate

Consult the Genshi documentation on Internationalization and Localization 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:

<html xmlns:i18n="">
    <title i18n:msg="subtitle">Legendary Site - $title</title>

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

New in version 0.5.

Table Of Contents

Related Topics