mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Divide validation code between refnamed footnote and citation
This commit is contained in:
parent
1f0c3ce875
commit
aad52ebd09
@ -258,10 +258,11 @@ class Locale(SphinxTransform):
|
||||
(nodes.paragraph,) + LITERAL_TYPE_NODES + IMAGE_TYPE_NODES):
|
||||
continue # skip for now
|
||||
|
||||
# foot note reference should use original 'ids'.
|
||||
def is_footnote_ref(node):
|
||||
# auto-numbered foot note reference should use original 'ids'.
|
||||
def is_autonumber_footnote_ref(node):
|
||||
# type: (nodes.Node) -> bool
|
||||
return isinstance(node, nodes.footnote_reference)
|
||||
return isinstance(node, nodes.footnote_reference) and \
|
||||
node.get('auto') == 1
|
||||
|
||||
def list_replace_or_append(lst, old, new):
|
||||
# type: (List, Any, Any) -> None
|
||||
@ -269,8 +270,8 @@ class Locale(SphinxTransform):
|
||||
lst[lst.index(old)] = new
|
||||
else:
|
||||
lst.append(new)
|
||||
old_foot_refs = node.traverse(is_footnote_ref)
|
||||
new_foot_refs = patch.traverse(is_footnote_ref)
|
||||
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',
|
||||
location=node)
|
||||
@ -326,6 +327,42 @@ class Locale(SphinxTransform):
|
||||
|
||||
self.document.note_refname(new)
|
||||
|
||||
# refnamed footnote should use original 'ids'.
|
||||
def is_refnamed_footnote_ref(node):
|
||||
# type: (nodes.Node) -> bool
|
||||
return isinstance(node, nodes.footnote_reference) and \
|
||||
'refname' in node
|
||||
old_foot_refs = node.traverse(is_refnamed_footnote_ref)
|
||||
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',
|
||||
location=node)
|
||||
for old in old_foot_refs:
|
||||
refname_ids_map[old["refname"]] = old["ids"]
|
||||
for new in new_foot_refs:
|
||||
refname = new["refname"]
|
||||
if refname in refname_ids_map:
|
||||
new["ids"] = refname_ids_map[refname]
|
||||
|
||||
# citation should use original 'ids'.
|
||||
def is_citation_ref(node):
|
||||
# type: (nodes.Node) -> bool
|
||||
return isinstance(node, nodes.citation_reference) and \
|
||||
'refname' in node
|
||||
old_cite_refs = node.traverse(is_citation_ref)
|
||||
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',
|
||||
location=node)
|
||||
for old in old_cite_refs:
|
||||
refname_ids_map[old["refname"]] = old["ids"]
|
||||
for new in new_cite_refs:
|
||||
refname = new["refname"]
|
||||
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.
|
||||
# This code restricts to change ref-targets in the translation.
|
||||
|
Loading…
Reference in New Issue
Block a user