summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshimizukawa <shimizukawa@gmail.com>2014-03-23 23:01:15 +0900
committershimizukawa <shimizukawa@gmail.com>2014-03-23 23:01:15 +0900
commitd9d7fb8957db080ef4da9c278c18801cac4bbf29 (patch)
tree34b49fa5094eddf694584e7c9c0ab5a32d11bf1d
parent27f359a1a3e20f00229644a7a76553d1887ae1bd (diff)
downloadsphinx-d9d7fb8957db080ef4da9c278c18801cac4bbf29.tar.gz
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.
-rw-r--r--CHANGES2
-rw-r--r--sphinx/transforms.py12
-rw-r--r--tests/roots/test-intl/refs_python_domain.po25
-rw-r--r--tests/roots/test-intl/refs_python_domain.txt15
-rw-r--r--tests/test_intl.py14
5 files changed, 65 insertions, 3 deletions
diff --git a/CHANGES b/CHANGES
index 538c9007..cee5275c 100644
--- a/CHANGES
+++ b/CHANGES
@@ -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)
diff --git a/sphinx/transforms.py b/sphinx/transforms.py
index e28c75f6..8919d6ce 100644
--- a/sphinx/transforms.py
+++ b/sphinx/transforms.py
@@ -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:
diff --git a/tests/roots/test-intl/refs_python_domain.po b/tests/roots/test-intl/refs_python_domain.po
new file mode 100644
index 00000000..bed87c4c
--- /dev/null
+++ b/tests/roots/test-intl/refs_python_domain.po
@@ -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"
+
diff --git a/tests/roots/test-intl/refs_python_domain.txt b/tests/roots/test-intl/refs_python_domain.txt
new file mode 100644
index 00000000..20a8bc50
--- /dev/null
+++ b/tests/roots/test-intl/refs_python_domain.txt
@@ -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
+
diff --git a/tests/test_intl.py b/tests/test_intl.py
index cdbb5f4c..ca0273c8 100644
--- a/tests/test_intl.py
+++ b/tests/test_intl.py
@@ -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)