Edgewall Software

Ticket #404: i18n-msg_removes_text.py

File i18n-msg_removes_text.py, 1.3 KB (added by Martin Scharrer <martin@…>, 4 years ago)

Demonstration script

Line 
1#!/usr/bin/env python
2from genshi.template import MarkupTemplate
3from genshi.filters.i18n import Translator
4
5tempstring = """
6<html xmlns:py="http://genshi.edgewall.org/"
7      xmlns:i18n="http://genshi.edgewall.org/i18n">
8    <p class="incorrect"  i18n:msg="first,second">
9        $first <span>$second</span> REMOVED <span>Inside a tag</span> Outside a tag
10    </p>
11    <p class="correct">
12        $first <span>$second</span> NOT REMOVED <span>Inside a tag</span> Outside a tag
13    </p>
14    <p class="correct" i18n:msg="first,second">
15        $first <span>$second</span> NOT REMOVED <span>Inside a tag</span>
16    </p>
17    <p class="correct" i18n:msg="first,second">
18        <span>$first</span> <span>$second</span> NOT REMOVED <span>Inside a tag</span> Outside a tag
19    </p>
20    <p class="correct" i18n:msg="first,second">
21        $first <span>$second</span> NOT REMOVED
22    </p>
23    <p class="correct" i18n:msg="first,second">
24        <span>$first</span> <span>$second</span> NOT REMOVED
25    </p>
26</html>"""
27tmpl = MarkupTemplate(tempstring)
28translator = Translator()
29translator.setup(tmpl)
30
31print "Template text:"
32print tempstring
33
34print ""
35print "Extracted messages:"
36for t in list(translator.extract(tmpl.stream)):
37    print t
38
39print ""
40print "Generated XHTML:"
41print tmpl.generate(first='FIRST',second='SECOND')
42