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

This commit is contained in:
Takayuki Shimizukawa 2013-01-30 23:41:37 +09:00
parent 9735ec0a74
commit a86ea846e2
7 changed files with 75 additions and 7 deletions

View File

@ -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

View File

@ -12,3 +12,5 @@
definition_terms
figure_caption
index_entries
glossary_terms
glossary_terms_inconsistency

View File

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

View File

@ -11,3 +11,4 @@ i18n with glossary terms
Some other term
The corresponding glossary #2
link to :term:`Some term`.

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

View File

@ -0,0 +1,6 @@
:tocdepth: 2
i18n with glossary terms inconsistency
======================================
1. link to :term:`Some term` and :term:`Some other term`.

View File

@ -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):