Skip to content

Commit

Permalink
Categorize warnings for inconsistent references in i18n
Browse files Browse the repository at this point in the history
This allows suppressing them using the suppress_warnings configuration
variable.
  • Loading branch information
jeanas committed Jan 15, 2022
1 parent 49196d4 commit 9cecd91
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
14 changes: 10 additions & 4 deletions doc/usage/configuration.rst
Expand Up @@ -316,7 +316,11 @@ General configuration
* ``app.add_role``
* ``app.add_generic_role``
* ``app.add_source_parser``
* ``autosectionlabel.*``
* ``download.not_readable``
* ``epub.unknown_project_files``
* ``epub.duplicated_toc_entry``
* ``i18n.inconsistent_references``
* ``image.not_readable``
* ``ref.term``
* ``ref.ref``
Expand All @@ -332,11 +336,9 @@ General configuration
* ``toc.excluded``
* ``toc.not_readable``
* ``toc.secnum``
* ``epub.unknown_project_files``
* ``epub.duplicated_toc_entry``
* ``autosectionlabel.*``

You can choose from these types.
You can choose from these types. You can also give only the first
component to exclude all warnings attached to it.

Now, this option should be considered *experimental*.

Expand Down Expand Up @@ -366,6 +368,10 @@ General configuration

Added ``toc.excluded`` and ``toc.not_readable``

.. versionadded:: 4.4

Added ``i18n.inconsistent_references``

.. confval:: needs_sphinx

If set to a ``major.minor`` version string like ``'1.1'``, Sphinx will
Expand Down
10 changes: 5 additions & 5 deletions sphinx/transforms/i18n.py
Expand Up @@ -309,7 +309,7 @@ def list_replace_or_append(lst: List[N], old: N, new: N) -> None:
logger.warning(__('inconsistent footnote references in translated message.' +
' original: {0}, translated: {1}')
.format(old_foot_ref_rawsources, new_foot_ref_rawsources),
location=node)
location=node, type='i18n', subtype='inconsistent_references')
old_foot_namerefs: Dict[str, List[nodes.footnote_reference]] = {}
for r in old_foot_refs:
old_foot_namerefs.setdefault(r.get('refname'), []).append(r)
Expand Down Expand Up @@ -352,7 +352,7 @@ def list_replace_or_append(lst: List[N], old: N, new: N) -> None:
logger.warning(__('inconsistent references in translated message.' +
' original: {0}, translated: {1}')
.format(old_ref_rawsources, new_ref_rawsources),
location=node)
location=node, type='i18n', subtype='inconsistent_references')
old_ref_names = [r['refname'] for r in old_refs]
new_ref_names = [r['refname'] for r in new_refs]
orphans = list(set(old_ref_names) - set(new_ref_names))
Expand Down Expand Up @@ -380,7 +380,7 @@ def list_replace_or_append(lst: List[N], old: N, new: N) -> None:
logger.warning(__('inconsistent footnote references in translated message.' +
' original: {0}, translated: {1}')
.format(old_foot_ref_rawsources, new_foot_ref_rawsources),
location=node)
location=node, type='i18n', subtype='inconsistent_references')
for oldf in old_foot_refs:
refname_ids_map.setdefault(oldf["refname"], []).append(oldf["ids"])
for newf in new_foot_refs:
Expand All @@ -399,7 +399,7 @@ def list_replace_or_append(lst: List[N], old: N, new: N) -> None:
logger.warning(__('inconsistent citation references in translated message.' +
' original: {0}, translated: {1}')
.format(old_cite_ref_rawsources, new_cite_ref_rawsources),
location=node)
location=node, type='i18n', subtype='inconsistent_references')
for oldc in old_cite_refs:
refname_ids_map.setdefault(oldc["refname"], []).append(oldc["ids"])
for newc in new_cite_refs:
Expand All @@ -419,7 +419,7 @@ def list_replace_or_append(lst: List[N], old: N, new: N) -> None:
logger.warning(__('inconsistent term references in translated message.' +
' original: {0}, translated: {1}')
.format(old_xref_rawsources, new_xref_rawsources),
location=node)
location=node, type='i18n', subtype='inconsistent_references')

def get_ref_key(node: addnodes.pending_xref) -> Optional[Tuple[str, str, str]]:
case = node["refdomain"], node["reftype"]
Expand Down

0 comments on commit 9cecd91

Please sign in to comment.