    Translation
    ===========

    This document contains functional template tests.

    A generic render-method is used for convenience.

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

    TAL
    ---

    We use the XML translator.

      >>> from z3c.pt.translation import translate_xml

    Basic HTML:

      >>> print render("""\
      ...
... ...
""", translate_xml)
Attributes and contents: >>> print render("""\ ...
... ... Hello Universe! ... ...
""", translate_xml)
abcghi Hello World!
Repeats: >>> print render("""\ ...
...

...
...

...
""", translate_xml)

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

Comments: >>> print render("""\ ...
... ... ... ...
""", translate_xml)
Namespacing: >>> print render("""\ ...
... ... ... ...
""", translate_xml)
Hello World! Hello World! 0 1 2
Omitting tags: >>> print render("""\ ...
...

No paragraph here.

...

No paragraph here either.

...

A paragraph here.

...
""", translate_xml)
No paragraph here. No paragraph here either.

A paragraph here.

Unicode: >>> print render("""\ ...
... ...
""", translate_xml)
>>> print render("""\ ...
... ... ... ... ...
""", translate_xml)
<br /> La Peña
Interpolation: >>> print render("""\ ...
... inter${'pol' + 'ati'}onis ${int('test') | 'convenient'}! ... ... ... ...
""", translate_xml)
interpolationis convenient!
>>> print render("""\ ...
... ... ... ... ${unicode('La Pe\xc3\xb1a', 'utf-8')} ... ... ...
""", translate_xml)
La Peña
Changing default expression: >>> print render("""\ ...
... ...
... ... ... ... ...
... ... ... ... ...
""", translate_xml)
1 1 2 10
1 True 1
Pragmas: >>> print render("""\ ...
... ... ...
""", translate_xml, request=object())
    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: Couldn't find end of Start Tag div line 1, line 1, column 11 Missing namespace definition: We expect the engine to raise an exception* *) This test only passes on lxml 2.x. >>> body = """\ ...
... """ >>> print render(body, translate_xml) Traceback (most recent call last): ... XMLSyntaxError: Namespace prefix tal for content on div is not defined, line 1, column 23