mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
fix: roles' reftarget ware swapped if there are some roles in 1 line and translation exchange rthat roles position. refs #1090
This commit is contained in:
parent
51deccfa5c
commit
7ebd7ab2a9
@ -255,13 +255,20 @@ class Locale(Transform):
|
||||
|
||||
# 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:
|
||||
|
@ -1,3 +1,6 @@
|
||||
CONTENTS
|
||||
========
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
:numbered:
|
||||
|
23
tests/roots/test-intl/role_xref.po
Normal file
23
tests/roots/test-intl/role_xref.po
Normal file
@ -0,0 +1,23 @@
|
||||
# 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`."
|
9
tests/roots/test-intl/role_xref.txt
Normal file
9
tests/roots/test-intl/role_xref.txt
Normal file
@ -0,0 +1,9 @@
|
||||
:tocdepth: 2
|
||||
|
||||
.. _i18n-role-xref:
|
||||
|
||||
i18n role xref
|
||||
==============
|
||||
|
||||
link to :term:`Some term`, :ref:`i18n-role-xref`, :doc:`contents`.
|
||||
|
@ -293,6 +293,24 @@ def test_i18n_glossary_terms(app):
|
||||
assert 'term not in glossary' not in warnings
|
||||
|
||||
|
||||
@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
|
||||
|
Loading…
Reference in New Issue
Block a user