    Internationalization
    --------------------

    Page templates support the i18n attribute language. The implementation
    is based on this document:

      * http://wiki.zope.org/zope3/ZPTInternationalizationSupport

    With the exception of i18n:data and i18n:source, the implementation is
    complete.

    To get set started, let's provide German mock translations for all
    msgids:

      >>> from zope import component
      >>> from zope import interface

      >>> from zope.i18n.interfaces import ITranslationDomain
      >>> class MockTranslationDomain(object):
      ...     interface.implements(ITranslationDomain)
      ...
      ...     def translate(self, msgid, mapping=None, context=None,
      ...                   target_language=None, default=None):
      ...         if target_language != 'de':
      ...             return default
      ...
      ...         return "Mock translation of '%s'." % msgid

      >>> td = MockTranslationDomain()
      >>> component.provideUtility(td, ITranslationDomain, name="test")

    Translation of tag contents
    ---------------------------

    First, a simple example:

      >>> body = """\
      ...
... ... Default ... ...
""" First we need to turn the template into a callable: >>> from chameleon.zpt.template import PageTemplate >>> template = PageTemplate(body) Let's try rendering this template without passing a target language. >>> print template.render()
Default
Now we'll render the template again---passing German as the language. >>> print template.render(target_language='de')
Mock translation of 'test_msgid'.
Let's try infering the translation message id from the tag body. >>> body = """\ ...
... ... Default ... ...
    """

    Not passing a language:

      >>> template = PageTemplate(body)
      >>> print template.render()
Default
Passing German: >>> print template.render(target_language='de')
Mock translation of 'Default'.
We could also add a named block inside the tag. >>> body = """\ ...
...

... 18 bananas. ...

...
    """

      >>> template = PageTemplate(body)
      >>> print template.render()

18 bananas.

>>> print template.render(target_language='de')

Mock translation of '${count} bananas.'.

Translation of tag attributes ----------------------------- A simple example to start with. >>> body = """\ ...
... ... Default ... ...
    """

    Not passing a language:

      >>> template = PageTemplate(body)
      >>> print template.render()
Default
Passing German: >>> print template.render(target_language='de')
Default
Use an explicit msgid: >>> body = """\ ...
... ... Default ... ...
    """

    Not passing a language:

      >>> template = PageTemplate(body)
      >>> print template.render()
Default
Passing German: >>> print template.render(target_language='de')
Default
Use an explicit msgid with a trailing semicolon. >>> body = """\ ...
... ... Default ... ...
    """

    Not passing a language:

      >>> template = PageTemplate(body)
      >>> print template.render()
Default
Passing German: >>> print template.render(target_language='de')
Default
Use multiple attributes on the same tag. >>> body = """\ ...
... ... Default ... ...
    """

    Not passing a language:

      >>> template = PageTemplate(body)
      >>> print template.render()
Default
Passing German: >>> print template.render(target_language='de')
Default
Translation of tag content and tag attributes --------------------------------------------- A simple example to start with. >>> body = """\ ...
... ... Default, "default", 'default' ... ... ... Default, "default", 'default' ... ...
    """

    Not passing a language:

      >>> template = PageTemplate(body)
      >>> print template.render()
Default, "default", 'default' tid
Passing German: >>> print template.render(target_language='de')
Mock translation of 'tid'. Mock translation of 'tid'.