Skip to content

Commit 35d2738

Browse files
authored
GH-97950: Allow translation of index directive content (#104000)
1 parent 9885677 commit 35d2738

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

Doc/conf.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@
9191
# Avoid a warning with Sphinx >= 2.0
9292
master_doc = 'contents'
9393

94+
# Allow translation of index directives
95+
gettext_additional_targets = [
96+
'index',
97+
]
98+
9499
# Options for HTML output
95100
# -----------------------
96101

Doc/tools/extensions/pyspecific.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,34 @@ def process_audit_events(app, doctree, fromdocname):
674674
node.replace_self(table)
675675

676676

677+
def patch_pairindextypes(app) -> None:
678+
if app.builder.name != 'gettext':
679+
return
680+
681+
# allow translating deprecated index entries
682+
try:
683+
from sphinx.domains.python import pairindextypes
684+
except ImportError:
685+
pass
686+
else:
687+
# Sphinx checks if a 'pair' type entry on an index directive is one of
688+
# the Sphinx-translated pairindextypes values. As we intend to move
689+
# away from this, we need Sphinx to believe that these values don't
690+
# exist, by deleting them when using the gettext builder.
691+
692+
# pairindextypes.pop('module', None)
693+
# pairindextypes.pop('keyword', None)
694+
# pairindextypes.pop('operator', None)
695+
# pairindextypes.pop('object', None)
696+
# pairindextypes.pop('exception', None)
697+
# pairindextypes.pop('statement', None)
698+
# pairindextypes.pop('builtin', None)
699+
700+
# there needs to be at least one statement in this block, will be
701+
# removed when the first of the below is uncommented.
702+
pass
703+
704+
677705
def setup(app):
678706
app.add_role('issue', issue_role)
679707
app.add_role('gh', gh_issue_role)
@@ -695,6 +723,7 @@ def setup(app):
695723
app.add_directive_to_domain('py', 'awaitablemethod', PyAwaitableMethod)
696724
app.add_directive_to_domain('py', 'abstractmethod', PyAbstractMethod)
697725
app.add_directive('miscnews', MiscNews)
726+
app.connect('builder-inited', patch_pairindextypes)
698727
app.connect('doctree-resolved', process_audit_events)
699728
app.connect('env-merge-info', audit_events_merge)
700729
app.connect('env-purge-doc', audit_events_purge)

0 commit comments

Comments
 (0)