File changeset_r1242.diff of Package python-Genshi

Index: /trunk/genshi/filters/tests/i18n.py
===================================================================
--- /trunk/genshi/filters/tests/i18n.py	(revision 1177)
+++ /trunk/genshi/filters/tests/i18n.py	(revision 1242)
@@ -928,4 +928,16 @@
           """</p></html>""",
           tmpl.generate(first="FIRST", second="SECOND").render())
+
+    def test_translate_i18n_msg_ticket_404_regression(self):
+        tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"
+            xmlns:i18n="http://genshi.edgewall.org/i18n">
+          <h1 i18n:msg="name">text <a>$name</a></h1>
+        </html>""")
+        gettext = lambda s: u'head [1:%(name)s] tail'
+        translator = Translator(gettext)
+        translator.setup(tmpl)
+        self.assertEqual("""<html>
+          <h1>head <a>NAME</a> tail</h1>
+        </html>""", tmpl.generate(name='NAME').render())
 
 
Index: /trunk/genshi/filters/i18n.py
===================================================================
--- /trunk/genshi/filters/i18n.py	(revision 1177)
+++ /trunk/genshi/filters/i18n.py	(revision 1242)
@@ -1049,5 +1049,11 @@
         while parts:
             order, string = parts.pop(0)
-            events = self.events[order].pop(0)
+            events = self.events[order]
+            if events:
+                events = events.pop(0)
+            else:
+                # create a dummy empty text event so any remaining
+                # part of the translation can be processed.
+                events = [(TEXT, "", (None, -1, -1))]
             parts_counter[order].pop()