    Translation
    -----------

    This document contains functional template tests.

    We use a generic render-method for convenience.

      >>> def render(body, translator, **kwargs):
      ...    source, _globals = translator(body)
      ...    _locals = {}
      ...    exec source in _globals, _locals
      ...    return _locals['render'](**kwargs)

    TAL templates
    -------------

      >>> from z3c.pt.translation import translate_xml

    For the functional testing of TAL templates we provide a complex
    template that covers most cases. It's been developed alongside
    development and is not meant to be easy on the eye.

      >>> body = """\
      ...
... ...

...
- ... ...
...

... ... ... ... ...

No paragraph here.

...

No paragraph here either.

...

A paragraph here.

... Hello Universe! ... ... ... ... ... ... inter${'pol' + 'ati'}onis ${int('test') | 'convenient'}! ... ... ... ... ... ${unicode('La Pe\xc3\xb1a', 'utf-8')} ... ... ...
... """ >>> print render(body, translate_xml)
abcghi

- Item 0)
- Item 1)
- Item 2)
- Item 3)
- Item 4)

Hello World! Hello World! 0 1 2 3 4 No paragraph here. No paragraph here either.

A paragraph here.

Hello World! World
La Peña interpolationis convenient! La Peña
    Text templates
    --------------

      >>> from z3c.pt.translation import translate_text

    An example with a CSS stylesheet document:

      >>> css = """\
      ... #some-region {
      ...    background: url(${'http://nohost/plone'}/logo.gif) no-repeat;
      ... }"""

      >>> print render(css, translate_text)
      #some-region {
         background: url(http://nohost/plone/logo.gif) no-repeat;
      }

    A javascript document that prints out HTML:

      >>> js = """\
      ... print '
Hello ${'World!'}
    ';"""

      >>> print render(js, translate_text)
      print '
Hello World!
'; Error handling -------------- This section demonstrates how the package handles templates that contain errors. No default namespace declaration: A default namespace must be explicitly declared for the parser to work. >>> body = '
    '
      >>> render(body, translate_xml)
      Traceback (most recent call last):
        ...
      ValueError: Must set default namespace.

    Bad XML
      We expect the xml-parser to raise an exception.

      >>> body = '
>> render(body, translate_xml) Traceback (most recent call last): ... XMLSyntaxError: line 1: Couldn't find end of Start Tag div line 1 Missing namespace definition: We expect the engine to render the attributes as static. >>> body = """\ ...
... """ >>> print render(body, translate_xml)