Control: retitle -1 Cannot build text with footnotes when using l10

Attached updated patch that is based on first one and
http://dev.sphinx-doc.org/sphinx/pull-request/86/fixed-955-footnote-i18n-translation-cause/commits
 .

Does it look better?

--
Dmitry Shachnev
=== modified file 'sphinx/environment.py'
--- sphinx/environment.py	2012-03-12 12:18:37 +0000
+++ sphinx/environment.py	2012-11-23 14:18:39 +0000
@@ -213,16 +213,30 @@
         parser = RSTParser()
 
         for node, msg in extract_messages(self.document):
-            patch = new_document(source, settings)
             msgstr = catalog.gettext(msg)
             # XXX add marker to untranslated parts
             if not msgstr or msgstr == msg: # as-of-yet untranslated
                 continue
+
+            patch = new_document(source, settings)
             parser.parse(msgstr, patch)
             patch = patch[0]
             # XXX doctest and other block markup
             if not isinstance(patch, nodes.paragraph):
                 continue # skip for now
+
+            footnote_refs = [r for r in node.children
+                             if isinstance(r, nodes.footnote_reference)
+                             and r.get('auto') == 1]
+            for i, child in enumerate(patch.children): # update leaves
+                if isinstance(child, nodes.footnote_reference) \
+                   and child.get('auto') == 1:
+                    # use original 'footnote_reference' object.
+                    # this object already registered in self.document.autofootnote_refs
+                    patch.children[i] = footnote_refs.pop(0)
+                    # Some duplicated footnote_reference in msgstr causes
+                    # IndexError by .pop(0). That is invalid msgstr.
+
             for child in patch.children: # update leaves
                 child.parent = node
             node.children = patch.children

Reply via email to