Commits

Takayuki Shimizukawa committed b3e09bb

fix: roles' reftarget ware swapped if there are some roles in 1 line and translation exchange rthat roles position. refs #1090

Comments (0)

Files changed (5)

sphinx/transforms.py

 
             # Original pending_xref['reftarget'] contain not-translated
             # target name, new pending_xref must use original one.
+            # This code restricts to change ref-targets in the translation.
             old_refs = node.traverse(addnodes.pending_xref)
             new_refs = patch.traverse(addnodes.pending_xref)
+            xref_reftarget_map = {}
             if len(old_refs) != len(new_refs):
                 env.warn_node('inconsistent term references in '
                               'translated message', node)
-            for old, new in zip(old_refs, new_refs):
-                new['reftarget'] = old['reftarget']
+            for old in old_refs:
+                key = old["reftype"], old["refdomain"]
+                xref_reftarget_map[key] = old["reftarget"]
+            for new in new_refs:
+                key = new["reftype"], new["refdomain"]
+                if key in xref_reftarget_map:
+                    new['reftarget'] = xref_reftarget_map[key]
 
             # update leaves
             for child in patch.children:

tests/roots/test-intl/contents.txt

+CONTENTS
+========
+
 .. toctree::
    :maxdepth: 2
    :numbered:

tests/roots/test-intl/role_xref.po

+# 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-02-04 14: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 role xref"
+msgstr "I18N ROCK'N ROLE XREF"
+
+msgid "link to :term:`Some term`, :ref:`i18n-role-xref`, :doc:`contents`."
+msgstr "LINK TO :ref:`i18n-role-xref`, :doc:`contents`, :term:`SOME NEW TERM`."

tests/roots/test-intl/role_xref.txt

+:tocdepth: 2
+
+.. _i18n-role-xref:
+
+i18n role xref
+==============
+
+link to :term:`Some term`, :ref:`i18n-role-xref`, :doc:`contents`.
+

tests/test_intl.py

 
 
 @with_intl_app(buildername='text', warning=warnfile)
+def test_i18n_role_xref(app):
+    # regression test for #1090
+    app.builddir.rmtree(True)  #for warnings acceleration
+    app.builder.build(['role_xref'])
+    result = (app.outdir / 'role_xref.txt').text(encoding='utf-8')
+    expect = (u"\nI18N ROCK'N ROLE XREF"
+              u"\n*********************\n"
+              u"\nLINK TO *I18N ROCK'N ROLE XREF*, *CONTENTS*, *SOME NEW TERM*.\n")
+
+    warnings = warnfile.getvalue().replace(os.sep, '/')
+    assert 'term not in glossary' not in warnings
+    assert 'undefined label' not in warnings
+    assert 'unknown document' not in warnings
+
+    assert result == expect
+
+
+@with_intl_app(buildername='text', warning=warnfile)
 def test_i18n_glossary_terms_inconsistency(app):
     # regression test for #1090
     app.builddir.rmtree(True)  #for warnings acceleration