Commits

Takayuki Shimizukawa  committed 86e5949

Add tests and code refine for pull request #190.

  • Participants
  • Parent commits c072494

Comments (0)

Files changed (7)

 * #1296: Fix invalid charset in HTML help generated HTML files for default
   locale.
 
+* PR#190: Fix gettext does not extract figure caption and rubric title inside
+  other blocks. Thanks to Michael Schlenker.
+
 
 Release 1.2 beta3 (released Oct 3, 2013)
 ========================================

File sphinx/util/nodes.py

     nodes.doctest_block,
     #XXX there are probably more
 )
-
-def find_source_node(node):
-    if node.source:
-        return node.source
-
-    current = node
-    while 1:
-        parent = current.parent
-        if parent.source:
-            return parent.source
-        else:
-            current = parent
-
-        if not current:
-            break
-    return None
-    
 def extract_messages(doctree):
     """Extract translatable messages from a document tree."""
     for node in doctree.traverse(nodes.TextElement):
             yield node, msg
 
 
+def find_source_node(node):
+    for pnode in traverse_parent(node):
+        if pnode.source:
+            return pnode.source
+
+
+def traverse_parent(node):
+    while node:
+        yield node
+        node = node.parent
+
+
 def traverse_translatable_index(doctree):
     """Traverse translatable index node from a document tree."""
     def is_block_index(node):

File tests/roots/test-intl/figure_caption.po

 
 msgid "My description paragraph2 of the figure."
 msgstr "MY DESCRIPTION PARAGRAPH2 OF THE FIGURE."
+
+msgid "figure in the block"
+msgstr "FIGURE IN THE BLOCK"
+
+msgid "block"
+msgstr "BLOCK"

File tests/roots/test-intl/figure_caption.txt

    My description paragraph1 of the figure.
 
    My description paragraph2 of the figure.
+
+figure in the block
+---------------------
+
+block
+
+   .. figure:: i18n.png
+
+      My caption of the figure
+
+      My description paragraph1 of the figure.
+
+      My description paragraph2 of the figure.
+

File tests/roots/test-intl/rubric.po

+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) 2012, foof
+# This file is distributed under the same license as the foo package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: sphinx 1.0\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2013-11-12 7:00\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+msgid "i18n with rubric"
+msgstr "I18N WITH RUBRIC"
+
+msgid "rubric title"
+msgstr "RUBRIC TITLE"
+
+msgid "rubric in the block"
+msgstr "RUBRIC IN THE BLOCK"
+
+msgid "block"
+msgstr "BLOCK"

File tests/roots/test-intl/rubric.txt

+:tocdepth: 2
+
+i18n with rubric
+================
+
+.. rubric:: rubric title
+
+rubric in the block
+-------------------
+
+block
+
+   .. rubric:: rubric title
+

File tests/test_intl.py

               u"\n************************\n"
               u"\n   [image]MY CAPTION OF THE FIGURE\n"
               u"\n   MY DESCRIPTION PARAGRAPH1 OF THE FIGURE.\n"
-              u"\n   MY DESCRIPTION PARAGRAPH2 OF THE FIGURE.\n")
+              u"\n   MY DESCRIPTION PARAGRAPH2 OF THE FIGURE.\n"
+              u"\n"
+              u"\nFIGURE IN THE BLOCK"
+              u"\n===================\n"
+              u"\nBLOCK\n"
+              u"\n      [image]MY CAPTION OF THE FIGURE\n"
+              u"\n      MY DESCRIPTION PARAGRAPH1 OF THE FIGURE.\n"
+              u"\n      MY DESCRIPTION PARAGRAPH2 OF THE FIGURE.\n")
+
+    assert result == expect
+
+
+@with_intl_app(buildername='text')
+def test_i18n_rubric(app):
+    # regression test for pull request #190
+    app.builder.build(['rubric'])
+    result = (app.outdir / 'rubric.txt').text(encoding='utf-8')
+    expect = (u"\nI18N WITH RUBRIC"
+              u"\n****************\n"
+              u"\n-[ RUBRIC TITLE ]-\n"
+              u"\n"
+              u"\nRUBRIC IN THE BLOCK"
+              u"\n===================\n"
+              u"\nBLOCK\n"
+              u"\n   -[ RUBRIC TITLE ]-\n")
 
     assert result == expect