Takayuki Shimizukawa avatar Takayuki Shimizukawa committed a61abe6

Closes #940: Fix gettext does not extract figure caption.

This is docutils issue.
see also: https://sourceforge.net/tracker/?func=detail&aid=3599485&group_id=38414&atid=422032

Comments (0)

Files changed (7)

 Release 1.2 (in development)
 ============================
 
+* #940: Fix gettext does not extract figure caption.
+
 * #1067: Improve the ordering of the JavaScript search results: matches in titles
   come before matches in full text, and object results are better categorized.
   Also implement a pluggable search scorer.

sphinx/util/nodes.py

                 node.line = definition_list_item.line - 1
                 node.rawsource = definition_list_item.\
                                  rawsource.split("\n", 2)[0]
+        # workaround: nodes.caption doesn't have source, line.
+        # this issue was filed to Docutils tracker:
+        # https://sourceforge.net/tracker/?func=detail&aid=3599485&group_id=38414&atid=422032
+        if isinstance(node, nodes.caption) and not node.source:
+            node.source = node.parent.source
+            node.line = ''  #need fix docutils to get `node.line`
    1. Takayuki Shimizukawa author

      I can not get correct line number because docutils' Figure dispose the information. I chose the '' in the selection of None, 0 and an empty string.

      These are generated pot file comment line patterns.

      1. line = None generate #: ..\..\index.rst:None
      2. line = 0 generate #: ..\..\index.rst:0
      3. line = '' generate #: ..\..\index.rst:

      Is it better to use 0 instead of a empty string?

        1. Jon Waltman

          Docutils seems to expect it to be an integer or None in some places. I don't know if that happens after this point or not.

          You could just punt the problem to docutils.utils.get_source_line which returns the source info for the node or its closest ancestor. It returns (None, None) if it lookup fails.

+
         if not node.source:
             continue # built-in message
         if isinstance(node, IGNORED_NODES):

tests/root/i18n/figure_caption.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-01-04 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 figure caption"
+msgstr "I18N WITH FIGURE CAPTION"
+
+msgid "My caption of the figure"
+msgstr "MY CAPTION OF THE FIGURE"
+
+msgid "My description paragraph1 of the figure."
+msgstr "MY DESCRIPTION PARAGRAPH1 OF THE FIGURE."
+
+msgid "My description paragraph2 of the figure."
+msgstr "MY DESCRIPTION PARAGRAPH2 OF THE FIGURE."

tests/root/i18n/figure_caption.txt

+:tocdepth: 2
+
+i18n with figure caption
+========================
+
+.. figure:: i18n.png
+
+   My caption of the figure
+
+   My description paragraph1 of the figure.
+
+   My description paragraph2 of the figure.
Add a comment to this file

tests/root/i18n/i18n.png

Added
New image

tests/root/i18n/index.txt

    refs_inconsistency
    literalblock
    definition_terms
+   figure_caption

tests/test_intl.py

               u"\n   THE CORRESPONDING DEFINITION #2\n")
 
     assert result == expect
+
+
+@with_app(buildername='text',
+          confoverrides={'language': 'xx', 'locale_dirs': ['.'],
+                         'gettext_compact': False})
+def test_i18n_figure_caption(app):
+    # regression test for #940
+    app.builder.build(['i18n/figure_caption'])
+    result = (app.outdir / 'i18n' / 'figure_caption.txt').text(encoding='utf-8')
+    expect = (u"\nI18N WITH FIGURE CAPTION"
+              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")
+
+    assert result == expect
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.