Fix i18n: crash when translating section name that is pointed from named target. Closes #1265

This commit is contained in:
Takayuki Shimizukawa 2013-09-23 19:53:22 +09:00
parent c7114f704b
commit 7682f477dc
5 changed files with 49 additions and 2 deletions

16
CHANGES
View File

@ -1,3 +1,19 @@
Release 1.2 (in development)
============================
Features added
--------------
Incompatible changes
--------------------
Bugs fixed
----------
* #1265: Fix i18n: crash when translating section name that is pointed from
named target.
Release 1.2 beta2 (released Sep 17, 2013) Release 1.2 beta2 (released Sep 17, 2013)
========================================= =========================================

View File

@ -242,6 +242,13 @@ class Locale(Transform):
self.document.note_implicit_target( self.document.note_implicit_target(
section_node, section_node) section_node, section_node)
# replace target's refname to new target name
def is_named_target(node):
return isinstance(node, nodes.target) and \
node.get('refname') == old_name
for old_target in self.document.traverse(is_named_target):
old_target['refname'] = new_name
processed = True processed = True
# glossary terms update refid # glossary terms update refid

View File

@ -50,3 +50,9 @@ msgid ""
msgstr "" msgstr ""
"`X DUPLICATED SUB SECTION`_ IS BROKEN LINK." "`X DUPLICATED SUB SECTION`_ IS BROKEN LINK."
msgid "label bridged target section"
msgstr "X LABEL BRIDGED TARGET SECTION"
msgid "`bridge label`_ is not translatable but linked to translated section title."
msgstr "X `bridge label`_ IS NOT TRANSLATABLE BUT LINKED TO TRANSLATED SECTION TITLE."

View File

@ -47,8 +47,18 @@ duplicated sub section
------------------------ ------------------------
.. This section have no label, but the section was a duplicate name. .. This section have no label, but the section was a duplicate name.
.. THis case, a duplicated target id is generated by docutils. .. This case, a duplicated target id is generated by docutils.
.. There is no way to link to this section's duplicated id like ``id2`` by .. There is no way to link to this section's duplicated id like ``id2`` by
.. using formal reStructuredText markup. .. using formal reStructuredText markup.
.. _bridge label: `label bridged target section`_
label bridged target section
=============================
.. This section is targeted through label definition.
`bridge label`_ is not translatable but linked to translated section title.

View File

@ -420,7 +420,7 @@ def test_i18n_role_xref(app):
@with_intl_app(buildername='xml', warning=warnfile) @with_intl_app(buildername='xml', warning=warnfile)
def test_i18n_label_target(app): def test_i18n_label_target(app):
# regression test for #1193 # regression test for #1193, #1265
app.builder.build(['label_target']) app.builder.build(['label_target'])
et = ElementTree.parse(app.outdir / 'label_target.xml') et = ElementTree.parse(app.outdir / 'label_target.xml')
secs = et.findall('section') secs = et.findall('section')
@ -455,6 +455,14 @@ def test_i18n_label_target(app):
texts=['`X DUPLICATED SUB SECTION`_', 'IS BROKEN LINK.'], texts=['`X DUPLICATED SUB SECTION`_', 'IS BROKEN LINK.'],
refs=[]) refs=[])
para3 = secs[3].findall('paragraph')
assert_elem(
para3[0],
texts=['X', 'bridge label',
'IS NOT TRANSLATABLE BUT LINKED TO TRANSLATED ' +
'SECTION TITLE.'],
refs=['label-bridged-target-section'])
@with_intl_app(buildername='text', warning=warnfile) @with_intl_app(buildername='text', warning=warnfile)
def test_i18n_glossary_terms_inconsistency(app): def test_i18n_glossary_terms_inconsistency(app):