Add tests and code refine for pull request #190.

This commit is contained in:
Takayuki Shimizukawa 2013-11-12 15:17:09 +00:00
parent 615fe64847
commit 63d34cca47
7 changed files with 103 additions and 18 deletions

View File

@ -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)
========================================

View File

@ -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):

View File

@ -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"

View File

@ -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.

View File

@ -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"

View File

@ -0,0 +1,14 @@
:tocdepth: 2
i18n with rubric
================
.. rubric:: rubric title
rubric in the block
-------------------
block
.. rubric:: rubric title

View File

@ -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