Fix #3370: the caption of code-block is not picked up for translation

This commit is contained in:
Takeshi KOMIYA 2017-01-26 01:57:22 +09:00
parent cf2061dfad
commit 1a2488610d
5 changed files with 30 additions and 2 deletions

View File

@ -13,6 +13,8 @@ Features added
Bugs fixed
----------
* #3370: the caption of code-block is not picked up for translation
Testing
--------

View File

@ -73,8 +73,8 @@ def container_wrapper(directive, literal_node, caption):
raise ValueError(parsed[0])
caption_node = nodes.caption(parsed[0].rawsource, '',
*parsed[0].children)
caption_node.source = parsed[0].source
caption_node.line = parsed[0].line
caption_node.source = literal_node.source
caption_node.line = literal_node.line
container_node += caption_node
container_node += literal_node
return container_node

View File

@ -28,6 +28,9 @@ msgstr "MISSING LITERAL BLOCK::"
msgid "That's all."
msgstr "THAT'S ALL."
msgid "included raw.txt"
msgstr "INCLUDED RAW.TXT"
msgid "code blocks"
msgstr "CODE-BLOCKS"
@ -40,6 +43,9 @@ msgstr ""
" 'RESULT'\n"
"end"
msgid "example of C language"
msgstr "EXAMPLE OF C LANGUAGE"
msgid ""
"#include <stdlib.h>\n"
"int main(int argc, char** argv)\n"

View File

@ -12,6 +12,9 @@ Missing literal block::
That's all.
.. literalinclude:: raw.txt
:caption: included raw.txt
code blocks
==============
@ -32,6 +35,7 @@ code blocks
}
.. code-block:: c
:caption: example of C language
#include <stdio.h>
int main(int argc, char** argv)

View File

@ -452,6 +452,22 @@ def test_gettext_glossary_term_inconsistencies(app):
assert expect_msg.id in [m.id for m in actual if m.id]
@sphinx_intl
@pytest.mark.sphinx('gettext')
@pytest.mark.test_params(shared_result='test_intl_gettext')
def test_gettext_literalblock(app):
app.build()
# --- gettext builder always ignores ``only`` directive
expect = read_po(app.srcdir / 'literalblock.po')
actual = read_po(app.outdir / 'literalblock.pot')
for expect_msg in [m for m in expect if m.id]:
if len(expect_msg.id.splitlines()) == 1:
# compare tranlsations only labels
assert expect_msg.id in [m.id for m in actual if m.id]
else:
pass # skip code-blocks and literalblocks
@sphinx_intl
@pytest.mark.sphinx('gettext')
@pytest.mark.test_params(shared_result='test_intl_gettext')