Takayuki Shimizukawa avatar Takayuki Shimizukawa committed be7fe90

Fix :term: doesn't link to glossary if term text translated. refs #1090

Comments (0)

Files changed (7)

sphinx/environment.py

                 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

tests/roots/test-intl/contents.txt

    definition_terms
    figure_caption
    index_entries
+   glossary_terms
+   glossary_terms_inconsistency

tests/roots/test-intl/glossary_terms.po

 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`."

tests/roots/test-intl/glossary_terms.txt

    Some other term
       The corresponding glossary #2
 
+link to :term:`Some term`.

tests/roots/test-intl/glossary_terms_inconsistency.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-01-29 14:10\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 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`."

tests/roots/test-intl/glossary_terms_inconsistency.txt

+:tocdepth: 2
+
+i18n with glossary terms inconsistency
+======================================
+
+1. link to :term:`Some term` and :term:`Some other term`.

tests/test_intl.py

     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):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.