From dfcb5d2f4c20f46a6d440b2c92b16ac692c3c53d Mon Sep 17 00:00:00 2001 From: Jean Abou Samra Date: Sun, 16 Jan 2022 00:37:13 +0100 Subject: [PATCH] Categorize warnings for inconsistent references in i18n This allows suppressing them using the suppress_warnings configuration variable. --- doc/usage/configuration.rst | 14 ++++++++++---- sphinx/transforms/i18n.py | 10 +++++----- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/doc/usage/configuration.rst b/doc/usage/configuration.rst index 737e22823..aaa3c8231 100644 --- a/doc/usage/configuration.rst +++ b/doc/usage/configuration.rst @@ -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`` @@ -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*. @@ -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 diff --git a/sphinx/transforms/i18n.py b/sphinx/transforms/i18n.py index fb2824fe0..198a63427 100644 --- a/sphinx/transforms/i18n.py +++ b/sphinx/transforms/i18n.py @@ -309,7 +309,7 @@ class Locale(SphinxTransform): 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) @@ -352,7 +352,7 @@ class Locale(SphinxTransform): 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)) @@ -380,7 +380,7 @@ class Locale(SphinxTransform): 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: @@ -399,7 +399,7 @@ class Locale(SphinxTransform): 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: @@ -419,7 +419,7 @@ class Locale(SphinxTransform): 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"]