diff --git a/sphinx/environment.py b/sphinx/environment.py index 0ddb4bfbe..2995cbbc0 100644 --- a/sphinx/environment.py +++ b/sphinx/environment.py @@ -297,6 +297,16 @@ class Locale(Transform): if refname in refname_ids_map: new["ids"] = refname_ids_map[refname] + # Original pending_xref['reftarget'] contain not-translated + # target name, new pending_xref must use original one. + old_refs = node.traverse(addnodes.pending_xref) + new_refs = patch.traverse(addnodes.pending_xref) + 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'] + # update leaves for child in patch.children: child.parent = node diff --git a/tests/roots/test-intl/contents.txt b/tests/roots/test-intl/contents.txt index 4ece2621d..a08cb0d3c 100644 --- a/tests/roots/test-intl/contents.txt +++ b/tests/roots/test-intl/contents.txt @@ -12,3 +12,5 @@ definition_terms figure_caption index_entries + glossary_terms + glossary_terms_inconsistency diff --git a/tests/roots/test-intl/glossary_terms.po b/tests/roots/test-intl/glossary_terms.po index b918c95b8..1ffcaeb20 100644 --- a/tests/roots/test-intl/glossary_terms.po +++ b/tests/roots/test-intl/glossary_terms.po @@ -20,13 +20,16 @@ msgid "i18n with glossary terms" msgstr "I18N WITH GLOSSARY TERMS" msgid "Some term" -msgstr "SOME TERM" +msgstr "SOME NEW TERM" msgid "The corresponding glossary" msgstr "THE CORRESPONDING GLOSSARY" msgid "Some other term" -msgstr "SOME OTHER TERM" +msgstr "SOME OTHER NEW TERM" msgid "The corresponding glossary #2" msgstr "THE CORRESPONDING GLOSSARY #2" + +msgid "link to :term:`Some term`." +msgstr "LINK TO :term:`SOME NEW TERM`." diff --git a/tests/roots/test-intl/glossary_terms.txt b/tests/roots/test-intl/glossary_terms.txt index 295e9e120..a6e16c948 100644 --- a/tests/roots/test-intl/glossary_terms.txt +++ b/tests/roots/test-intl/glossary_terms.txt @@ -11,3 +11,4 @@ i18n with glossary terms Some other term The corresponding glossary #2 +link to :term:`Some term`. diff --git a/tests/roots/test-intl/glossary_terms_inconsistency.po b/tests/roots/test-intl/glossary_terms_inconsistency.po new file mode 100644 index 000000000..5e3016578 --- /dev/null +++ b/tests/roots/test-intl/glossary_terms_inconsistency.po @@ -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 , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: sphinx 1.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2013-01-29 14:10\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +msgid "i18n with glossary terms inconsistency" +msgstr "I18N WITH GLOSSARY TERMS INCONSISTENCY" + +msgid "link to :term:`Some term` and :term:`Some other term`." +msgstr "LINK TO :term:`SOME NEW TERM`." diff --git a/tests/roots/test-intl/glossary_terms_inconsistency.txt b/tests/roots/test-intl/glossary_terms_inconsistency.txt new file mode 100644 index 000000000..837411b6f --- /dev/null +++ b/tests/roots/test-intl/glossary_terms_inconsistency.txt @@ -0,0 +1,6 @@ +:tocdepth: 2 + +i18n with glossary terms inconsistency +====================================== + +1. link to :term:`Some term` and :term:`Some other term`. diff --git a/tests/test_intl.py b/tests/test_intl.py index bf73824d1..06181c3bc 100644 --- a/tests/test_intl.py +++ b/tests/test_intl.py @@ -252,20 +252,43 @@ def test_i18n_definition_terms(app): assert result == expect -@with_intl_app(buildername='text') +@with_intl_app(buildername='text', warning=warnfile) def test_i18n_glossary_terms(app): # regression test for #1090 + app.builddir.rmtree(True) #for warnings acceleration app.builder.build(['glossary_terms']) result = (app.outdir / 'glossary_terms.txt').text(encoding='utf-8') expect = (u"\nI18N WITH GLOSSARY TERMS" u"\n************************\n" - u"\nSOME TERM" + u"\nSOME NEW TERM" u"\n THE CORRESPONDING GLOSSARY\n" - u"\nSOME OTHER TERM" - u"\n THE CORRESPONDING GLOSSARY #2\n") - + u"\nSOME OTHER NEW TERM" + u"\n THE CORRESPONDING GLOSSARY #2\n" + u"\nLINK TO *SOME NEW TERM*.\n") assert result == expect + warnings = warnfile.getvalue().replace(os.sep, '/') + assert 'term not in glossary' not in warnings + + +@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 + app.builder.build(['glossary_terms_inconsistency']) + result = (app.outdir / 'glossary_terms_inconsistency.txt' + ).text(encoding='utf-8') + expect = (u"\nI18N WITH GLOSSARY TERMS INCONSISTENCY" + u"\n**************************************\n" + u"\n1. LINK TO *SOME NEW TERM*.\n") + assert result == expect + + warnings = warnfile.getvalue().replace(os.sep, '/') + expected_warning_expr = ( + u'.*/glossary_terms_inconsistency.txt:\\d+: ' + u'WARNING: inconsistent term references in translated message\n') + assert re.search(expected_warning_expr, warnings) + @with_intl_app(buildername='text') def test_seealso(app):