diff options
| author | shimizukawa <shimizukawa@gmail.com> | 2013-11-12 15:17:09 +0000 |
|---|---|---|
| committer | shimizukawa <shimizukawa@gmail.com> | 2013-11-12 15:17:09 +0000 |
| commit | ecdf03ae3a131c3de5d4e407a62b7433e594d192 (patch) | |
| tree | bb1dc3b5629f4cd076bebc2fbcf156d897094c20 | |
| parent | aa4f7e224d21bfc5328afde206e49811db29a3f8 (diff) | |
| download | sphinx-ecdf03ae3a131c3de5d4e407a62b7433e594d192.tar.gz | |
Add tests and code refine for pull request #190.
| -rw-r--r-- | CHANGES | 3 | ||||
| -rw-r--r-- | sphinx/util/nodes.py | 29 | ||||
| -rw-r--r-- | tests/roots/test-intl/figure_caption.po | 6 | ||||
| -rw-r--r-- | tests/roots/test-intl/figure_caption.txt | 14 | ||||
| -rw-r--r-- | tests/roots/test-intl/rubric.po | 29 | ||||
| -rw-r--r-- | tests/roots/test-intl/rubric.txt | 14 | ||||
| -rw-r--r-- | tests/test_intl.py | 26 |
7 files changed, 103 insertions, 18 deletions
@@ -22,6 +22,9 @@ Bugs fixed * #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) ======================================== diff --git a/sphinx/util/nodes.py b/sphinx/util/nodes.py index 9d303188..da9b4be6 100644 --- a/sphinx/util/nodes.py +++ b/sphinx/util/nodes.py @@ -41,23 +41,6 @@ IGNORED_NODES = ( 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): @@ -94,6 +77,18 @@ def extract_messages(doctree): 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): diff --git a/tests/roots/test-intl/figure_caption.po b/tests/roots/test-intl/figure_caption.po index 01b4c041..2b85aea3 100644 --- a/tests/roots/test-intl/figure_caption.po +++ b/tests/roots/test-intl/figure_caption.po @@ -27,3 +27,9 @@ msgstr "MY DESCRIPTION PARAGRAPH1 OF THE FIGURE." 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"
diff --git a/tests/roots/test-intl/figure_caption.txt b/tests/roots/test-intl/figure_caption.txt index 75567b3a..0f978b55 100644 --- a/tests/roots/test-intl/figure_caption.txt +++ b/tests/roots/test-intl/figure_caption.txt @@ -10,3 +10,17 @@ i18n with figure caption 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. + diff --git a/tests/roots/test-intl/rubric.po b/tests/roots/test-intl/rubric.po new file mode 100644 index 00000000..2c1214b7 --- /dev/null +++ b/tests/roots/test-intl/rubric.po @@ -0,0 +1,29 @@ +# 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"
diff --git a/tests/roots/test-intl/rubric.txt b/tests/roots/test-intl/rubric.txt new file mode 100644 index 00000000..f285d49c --- /dev/null +++ b/tests/roots/test-intl/rubric.txt @@ -0,0 +1,14 @@ +:tocdepth: 2 + +i18n with rubric +================ + +.. rubric:: rubric title + +rubric in the block +------------------- + +block + + .. rubric:: rubric title + diff --git a/tests/test_intl.py b/tests/test_intl.py index 405ccd39..c9822089 100644 --- a/tests/test_intl.py +++ b/tests/test_intl.py @@ -514,7 +514,31 @@ def test_i18n_figure_caption(app): 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 |
