edgewall / genshi

Python toolkit for generation of output for the web
http://genshi.edgewall.org
Other
86 stars 35 forks source link

i18n:msg for nested and repeated tags incorrectly translates message #69

Open jun66j5 opened 1 year ago

jun66j5 commented 1 year ago
>>> import genshi
>>> genshi.__version__
'0.7.7'
>>> from genshi.template import MarkupTemplate
>>> from genshi.filters.i18n import Translator, extract
>>> html = """<html xmlns:py="http://genshi.edgewall.org/"
...     xmlns:i18n="http://genshi.edgewall.org/i18n"
...     py:strip="">
...   <i18n:msg>
...     <ul><li>First</li><li>Second</li></ul>
...   </i18n:msg>
... </html>"""
>>>
>>> tmpl = MarkupTemplate(html)
>>> translator = Translator()
>>> tmpl.add_directives(Translator.NAMESPACE, translator)
>>> result = list(translator.extract(tmpl.stream))
>>> msg = result[0][2]
>>> msg
'[1:[2:First][3:Second]]'
>>>
>>> tmpl = MarkupTemplate(html)
>>> translator = Translator(lambda s: msg)
>>> translator.setup(tmpl)
>>> tmpl.generate().render()
'\n  <ul><li>First</li></ul><li>Second</li>\n'
#                      ^^^^^           ^^^^
#    <ul><li>First</li><li>Second</li></ul>
hodgestar commented 1 year ago

Thanks for reporting this. So the closing end tag is being placed before the last sub-element rather than after it.