Fix i18n: missing python domain's cross-references with currentmodule directive or currentclass directive. refs #1363

* node attributes 'py:module', 'py:class' is provided from environment (e.x. currentmodule directive is provided on previous line, not on node)
* Because translation nodes are parsed in independently, 'provided attributes by environment' are not exist.
* For a pending_xref nodes, all attributes of a translated xref node should be same as original xref node in current test cases.
* For the above reasons, I overwrite all attributes from origonal node to new translated xref node.
This commit is contained in:
Takayuki Shimizukawa 2014-03-23 23:01:15 +09:00
parent b751d5db52
commit 43a9881c4b
5 changed files with 65 additions and 3 deletions

View File

@ -6,6 +6,8 @@ Bugs fixed
* #1419: Generated i18n sphinx.js files are missing message catalog entries
from '.js_t' and '.html'. The issue was introduced from Sphinx-1.1
* #1363: Fix i18n: missing python domain's cross-references with currentmodule
directive or currentclass directive.
Release 1.2.2 (released Mar 2, 2014)

View File

@ -416,11 +416,17 @@ class Locale(Transform):
for old in old_refs:
key = get_ref_key(old)
if key:
xref_reftarget_map[key] = old["reftarget"]
xref_reftarget_map[key] = old.attributes
for new in new_refs:
key = get_ref_key(new)
if key in xref_reftarget_map:
new['reftarget'] = xref_reftarget_map[key]
# Copy attributes to keep original node behavior. Especially
# copying 'reftarget', 'py:module', 'py:class' are needed.
for k, v in xref_reftarget_map.get(key, {}).items():
# Note: This implementation overwrite all attributes.
# if some attributes `k` should not be overwritten,
# you should provide exclude list as:
# `if k not in EXCLUDE_LIST: new[k] = v`
new[k] = v
# update leaves
for child in patch.children:

View File

@ -0,0 +1,25 @@
#
msgid ""
msgstr ""
"Project-Id-Version: issue1363 1363\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2014-03-16 19:34+0900\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"
#: ..\..\index.rst:4
msgid "i18n with python domain refs"
msgstr "I18N WITH PYTHON DOMAIN REFS"
#: ..\..\index.rst:8
msgid "See this decorator: :func:`sensitive_variables`."
msgstr "SEE THIS DECORATOR: :func:`sensitive_variables`."
#: ..\..\index.rst:12
msgid "Some description"
msgstr "SOME DESCRIPTION"

View File

@ -0,0 +1,15 @@
:tocdepth: 2
i18n with python domain refs
=============================
.. currentmodule:: sensitive
See this decorator: :func:`sensitive_variables`.
.. function:: sensitive_variables(*variables)
Some description
.. currentmodule:: reporting

View File

@ -206,6 +206,20 @@ def test_i18n_footnote_backlink(app):
assert refid2id[ids] == backrefs
@with_intl_app(buildername='xml', warning=warnfile)
def test_i18n_refs_python_domain(app):
app.builder.build(['refs_python_domain'])
et = ElementTree.parse(app.outdir / 'refs_python_domain.xml')
secs = et.findall('section')
# regression test for fix #1363
para0 = secs[0].findall('paragraph')
assert_elem(
para0[0],
texts=['SEE THIS DECORATOR:', 'sensitive_variables()', '.'],
refs=['sensitive.sensitive_variables'])
@with_intl_app(buildername='text', warning=warnfile, cleanenv=True)
def test_i18n_warn_for_number_of_references_inconsistency(app):
app.builddir.rmtree(True)