Function
zope.i18n.interpolate

Signature

interpolate(text, mapping=None)

Documentation String

Insert the data passed from mapping into the text.

First setup a test mapping:

>>> mapping = {"name": "Zope", "version": 3}

In the text we can use substitution slots like $varname or ${varname}:

>>> interpolate(u"This is $name version ${version}.", mapping) u'This is Zope version 3.'

Interpolation variables can be used more than once in the text:

>>> interpolate(u"This is $name version ${version}. ${name} $version!", ... mapping) u'This is Zope version 3. Zope 3!'

In case if the variable wasn't found in the mapping or $$ form was used no substitution will happens:

>>> interpolate(u"This is $name $version. $unknown $$name $${version}.", ... mapping) u'This is Zope 3. $unknown $$name $${version}.'

>>> interpolate(u"This is ${name}") u'This is ${name}'