Fix #2198,#2205: `make gettext` generate broken msgid for definition lists. It's a regression by #1855.

This commit is contained in:
shimizukawa 2016-01-09 15:33:43 +09:00
parent e7fa8a6c2b
commit ac28f9b271
5 changed files with 40 additions and 11 deletions

View File

@ -43,6 +43,7 @@ Bugs fixed
* Fix Sphinx crashes if mecab initialization failed
* #2160: Fix broken TOC of PDFs if section includes an image
* #2172: Fix dysfunctional admonition \py@lightbox in sphinx.sty. Thanks to jfbu.
* #2198,#2205: ``make gettext`` generate broken msgid for definition lists.
Release 1.3.3 (released Dec 2, 2015)
====================================

View File

@ -47,8 +47,10 @@ def apply_source_workaround(node):
node.line = definition_list_item.line - 1
node.rawsource = node.astext() # set 'classifier1' (or 'classifier2')
if isinstance(node, nodes.term):
# overwrite: ``term : classifier1 : classifier2`` -> ``term text``
node.rawsource = node.astext()
# strip classifier from rawsource of term
for classifier in reversed(node.parent.traverse(nodes.classifier)):
node.rawsource = re.sub(
'\s*:\s*%s' % classifier.astext(), '', node.rawsource)
# workaround: recommonmark-0.2.0 doesn't set rawsource attribute
if not node.rawsource:

View File

@ -25,14 +25,14 @@ msgstr "SOME TERM"
msgid "The corresponding definition"
msgstr "THE CORRESPONDING DEFINITION"
msgid "Some other term"
msgstr "SOME OTHER TERM"
msgid "Some *term* `with link <http://sphinx-doc.org/>`__"
msgstr "SOME *TERM* `WITH LINK <http://sphinx-doc.org/>`__"
msgid "The corresponding definition #2"
msgstr "THE CORRESPONDING DEFINITION #2"
msgid "Some term with"
msgstr "SOME TERM WITH"
msgid "Some **term** with"
msgstr "SOME **TERM** WITH"
msgid "classifier1"
msgstr "CLASSIFIER1"

View File

@ -6,9 +6,9 @@ i18n with definition terms
Some term
The corresponding definition
Some other term
Some *term* `with link <http://sphinx-doc.org/>`__
The corresponding definition #2
Some term with : classifier1 : classifier2
Some **term** with : classifier1 : classifier2
The corresponding definition

View File

@ -16,6 +16,7 @@ import re
from subprocess import Popen, PIPE
from xml.etree import ElementTree
from babel.messages import pofile
from nose.tools import assert_equal
from six import string_types
@ -175,16 +176,16 @@ def test_text_builder(app, status, warning):
u'WARNING: Literal block expected; none found.'
yield assert_re_search, expected_warning_expr, warnings
# --- definition terms: regression test for #975
# --- definition terms: regression test for #975, #2198, #2205
result = (app.outdir / 'definition_terms.txt').text(encoding='utf-8')
expect = (u"\nI18N WITH DEFINITION TERMS"
u"\n**************************\n"
u"\nSOME TERM"
u"\n THE CORRESPONDING DEFINITION\n"
u"\nSOME OTHER TERM"
u"\nSOME *TERM* WITH LINK"
u"\n THE CORRESPONDING DEFINITION #2\n"
u"\nSOME TERM WITH : CLASSIFIER1 : CLASSIFIER2"
u"\nSOME **TERM** WITH : CLASSIFIER1 : CLASSIFIER2"
u"\n THE CORRESPONDING DEFINITION\n"
)
yield assert_equal, result, expect
@ -304,6 +305,31 @@ def test_text_builder(app, status, warning):
yield assert_in, d.upper() + " BODY", result
@gen_with_intl_app('gettext', freshenv=True)
def test_gettext_builder(app, status, warning):
app.builder.build_all()
# --- definition terms: regression test for #2198, #2205
expect = pofile.read_po((app.srcdir / 'definition_terms.po').open())
actual = pofile.read_po((app.outdir / 'definition_terms.pot').open())
for expect_msg in [m for m in expect if m.id]:
yield assert_in, expect_msg.id, [m.id for m in actual if m.id]
# --- glossary terms: regression test for #1090
expect = pofile.read_po((app.srcdir / 'glossary_terms.po').open())
actual = pofile.read_po((app.outdir / 'glossary_terms.pot').open())
for expect_msg in [m for m in expect if m.id]:
yield assert_in, expect_msg.id, [m.id for m in actual if m.id]
warnings = warning.getvalue().replace(os.sep, '/')
yield assert_not_in, 'term not in glossary', warnings
# --- glossary term inconsistencies: regression test for #1090
expect = pofile.read_po((app.srcdir / 'glossary_terms_inconsistency.po').open())
actual = pofile.read_po((app.outdir / 'glossary_terms_inconsistency.pot').open())
for expect_msg in [m for m in expect if m.id]:
yield assert_in, expect_msg.id, [m.id for m in actual if m.id]
@gen_with_intl_app('html', freshenv=True)
def test_html_builder(app, status, warning):
app.builder.build_all()