Merge pull request #4125 from cocoatomo/translation-inconsistency-warning

Display reference texts of original and translated passages
This commit is contained in:
Takeshi KOMIYA
2017-10-10 19:58:06 +09:00
committed by GitHub
2 changed files with 50 additions and 10 deletions

View File

@@ -273,7 +273,11 @@ class Locale(SphinxTransform):
old_foot_refs = node.traverse(is_autonumber_footnote_ref)
new_foot_refs = patch.traverse(is_autonumber_footnote_ref)
if len(old_foot_refs) != len(new_foot_refs):
logger.warning('inconsistent footnote references in translated message',
old_foot_ref_rawsources = [ref.rawsource for ref in old_foot_refs]
new_foot_ref_rawsources = [ref.rawsource for ref in new_foot_refs]
logger.warning('inconsistent footnote references in translated message.' +
' original: {0}, translated: {1}'
.format(old_foot_ref_rawsources, new_foot_ref_rawsources),
location=node)
old_foot_namerefs = {} # type: Dict[unicode, List[nodes.footnote_reference]]
for r in old_foot_refs:
@@ -309,7 +313,11 @@ class Locale(SphinxTransform):
old_refs = node.traverse(is_refnamed_ref)
new_refs = patch.traverse(is_refnamed_ref)
if len(old_refs) != len(new_refs):
logger.warning('inconsistent references in translated message',
old_ref_rawsources = [ref.rawsource for ref in old_refs]
new_ref_rawsources = [ref.rawsource for ref in new_refs]
logger.warning('inconsistent references in translated message.' +
' original: {0}, translated: {1}'
.format(old_ref_rawsources, new_ref_rawsources),
location=node)
old_ref_names = [r['refname'] for r in old_refs]
new_ref_names = [r['refname'] for r in new_refs]
@@ -336,7 +344,11 @@ class Locale(SphinxTransform):
new_foot_refs = patch.traverse(is_refnamed_footnote_ref)
refname_ids_map = {}
if len(old_foot_refs) != len(new_foot_refs):
logger.warning('inconsistent footnote references in translated message',
old_foot_ref_rawsources = [ref.rawsource for ref in old_foot_refs]
new_foot_ref_rawsources = [ref.rawsource for ref in new_foot_refs]
logger.warning('inconsistent footnote references in translated message.' +
' original: {0}, translated: {1}'
.format(old_foot_ref_rawsources, new_foot_ref_rawsources),
location=node)
for old in old_foot_refs:
refname_ids_map[old["refname"]] = old["ids"]
@@ -354,7 +366,11 @@ class Locale(SphinxTransform):
new_cite_refs = patch.traverse(is_citation_ref)
refname_ids_map = {}
if len(old_cite_refs) != len(new_cite_refs):
logger.warning('inconsistent citation references in translated message',
old_cite_ref_rawsources = [ref.rawsource for ref in old_cite_refs]
new_cite_ref_rawsources = [ref.rawsource for ref in new_cite_refs]
logger.warning('inconsistent citation references in translated message.' +
' original: {0}, translated: {1}'
.format(old_cite_ref_rawsources, new_cite_ref_rawsources),
location=node)
for old in old_cite_refs:
refname_ids_map[old["refname"]] = old["ids"]
@@ -370,7 +386,11 @@ class Locale(SphinxTransform):
new_refs = patch.traverse(addnodes.pending_xref)
xref_reftarget_map = {}
if len(old_refs) != len(new_refs):
logger.warning('inconsistent term references in translated message',
old_ref_rawsources = [ref.rawsource for ref in old_refs]
new_ref_rawsources = [ref.rawsource for ref in new_refs]
logger.warning('inconsistent term references in translated message.' +
' original: {0}, translated: {1}'
.format(old_ref_rawsources, new_ref_rawsources),
location=node)
def get_ref_key(node):

View File

@@ -192,11 +192,29 @@ def test_text_inconsistency_warnings(app, warning):
warnings = getwarning(warning)
warning_fmt = u'.*/refs_inconsistency.txt:\\d+: ' \
u'WARNING: inconsistent %s in translated message\n'
u'WARNING: inconsistent %(reftype)s in translated message.' \
u' original: %(original)s, translated: %(translated)s\n'
expected_warning_expr = (
warning_fmt % 'footnote references' +
warning_fmt % 'references' +
warning_fmt % 'references')
warning_fmt % {
u'reftype': u'footnote references',
u'original': u"\[u?'\[#\]_'\]",
u'translated': u"\[\]"
} +
warning_fmt % {
u'reftype': u'footnote references',
u'original': u"\[u?'\[100\]_'\]",
u'translated': u"\[\]"
} +
warning_fmt % {
u'reftype': u'references',
u'original': u"\[u?'reference_'\]",
u'translated': u"\[u?'reference_', u?'reference_'\]"
} +
warning_fmt % {
u'reftype': u'references',
u'original': u"\[\]",
u'translated': u"\[u?'`I18N WITH REFS INCONSISTENCY`_'\]"
})
assert_re_search(expected_warning_expr, warnings)
expected_citation_warning_expr = (
@@ -281,7 +299,9 @@ def test_text_glossary_term_inconsistencies(app, warning):
warnings = getwarning(warning)
expected_warning_expr = (
u'.*/glossary_terms_inconsistency.txt:\\d+: '
u'WARNING: inconsistent term references in translated message\n')
u'WARNING: inconsistent term references in translated message.'
u" original: \[u?':term:`Some term`', u?':term:`Some other term`'\],"
u" translated: \[u?':term:`SOME NEW TERM`'\]\n")
assert_re_search(expected_warning_expr, warnings)