]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-97950: Allow translation of index directive content (#104000)
authorAdam Turner <9087854+AA-Turner@users.noreply.github.com>
Thu, 4 May 2023 07:11:09 +0000 (08:11 +0100)
committerGitHub <noreply@github.com>
Thu, 4 May 2023 07:11:09 +0000 (10:11 +0300)
Doc/conf.py
Doc/tools/extensions/pyspecific.py

index 6a3c01cd91a77b12f992c69b348a12a83ca8bedd..485c0bdf84df2eea661113695bfb7bb0f5d39af1 100644 (file)
@@ -91,6 +91,11 @@ smartquotes_excludes = {
 # Avoid a warning with Sphinx >= 2.0
 master_doc = 'contents'
 
+# Allow translation of index directives
+gettext_additional_targets = [
+    'index',
+]
+
 # Options for HTML output
 # -----------------------
 
index d659a4a54b9d118685c618da6fab597226662e3b..39c7c42e66f9a091a549dad6e6625eb796d2c403 100644 (file)
@@ -674,6 +674,34 @@ def process_audit_events(app, doctree, fromdocname):
         node.replace_self(table)
 
 
+def patch_pairindextypes(app) -> None:
+    if app.builder.name != 'gettext':
+        return
+
+    # allow translating deprecated index entries
+    try:
+        from sphinx.domains.python import pairindextypes
+    except ImportError:
+        pass
+    else:
+        # Sphinx checks if a 'pair' type entry on an index directive is one of
+        # the Sphinx-translated pairindextypes values. As we intend to move
+        # away from this, we need Sphinx to believe that these values don't
+        # exist, by deleting them when using the gettext builder.
+
+        # pairindextypes.pop('module', None)
+        # pairindextypes.pop('keyword', None)
+        # pairindextypes.pop('operator', None)
+        # pairindextypes.pop('object', None)
+        # pairindextypes.pop('exception', None)
+        # pairindextypes.pop('statement', None)
+        # pairindextypes.pop('builtin', None)
+
+        # there needs to be at least one statement in this block, will be
+        # removed when the first of the below is uncommented.
+        pass
+
+
 def setup(app):
     app.add_role('issue', issue_role)
     app.add_role('gh', gh_issue_role)
@@ -695,6 +723,7 @@ def setup(app):
     app.add_directive_to_domain('py', 'awaitablemethod', PyAwaitableMethod)
     app.add_directive_to_domain('py', 'abstractmethod', PyAbstractMethod)
     app.add_directive('miscnews', MiscNews)
+    app.connect('builder-inited', patch_pairindextypes)
     app.connect('doctree-resolved', process_audit_events)
     app.connect('env-merge-info', audit_events_merge)
     app.connect('env-purge-doc', audit_events_purge)