diff --git a/CHANGES b/CHANGES index 97db2fc43..b48699ed2 100644 --- a/CHANGES +++ b/CHANGES @@ -21,6 +21,7 @@ Features added :confval:`suppress_warnings` * C, added scope control directives, :rst:dir:`c:namespace`, :rst:dir:`c:namespace-push`, and :rst:dir:`c:namespace-pop`. +* #7466: autosummary: headings in generated documents are not translated Bugs fixed ---------- diff --git a/sphinx/ext/autosummary/generate.py b/sphinx/ext/autosummary/generate.py index 7b128bea5..91628b3f2 100644 --- a/sphinx/ext/autosummary/generate.py +++ b/sphinx/ext/autosummary/generate.py @@ -124,6 +124,11 @@ class AutosummaryRenderer: self.env.filters['e'] = rst.escape self.env.filters['underline'] = _underline + if builder: + if builder.app.translator: + self.env.add_extension("jinja2.ext.i18n") + self.env.install_gettext_translations(builder.app.translator) # type: ignore + def exists(self, template_name: str) -> bool: """Check if template file exists.""" try: diff --git a/sphinx/ext/autosummary/templates/autosummary/class.rst b/sphinx/ext/autosummary/templates/autosummary/class.rst index 8861b79a9..0f7d6f32e 100644 --- a/sphinx/ext/autosummary/templates/autosummary/class.rst +++ b/sphinx/ext/autosummary/templates/autosummary/class.rst @@ -8,7 +8,7 @@ .. automethod:: __init__ {% if methods %} - .. rubric:: Methods + .. rubric:: {{ _('Methods') }} .. autosummary:: {% for item in methods %} @@ -19,7 +19,7 @@ {% block attributes %} {% if attributes %} - .. rubric:: Attributes + .. rubric:: {{ _('Attributes') }} .. autosummary:: {% for item in attributes %} diff --git a/sphinx/ext/autosummary/templates/autosummary/module.rst b/sphinx/ext/autosummary/templates/autosummary/module.rst index 6ec89e05e..db3bee8b7 100644 --- a/sphinx/ext/autosummary/templates/autosummary/module.rst +++ b/sphinx/ext/autosummary/templates/autosummary/module.rst @@ -4,7 +4,7 @@ {% block functions %} {% if functions %} - .. rubric:: Functions + .. rubric:: {{ _('Functions') }} .. autosummary:: {% for item in functions %} @@ -15,7 +15,7 @@ {% block classes %} {% if classes %} - .. rubric:: Classes + .. rubric:: {{ _('Classes') }} .. autosummary:: {% for item in classes %} @@ -26,7 +26,7 @@ {% block exceptions %} {% if exceptions %} - .. rubric:: Exceptions + .. rubric:: {{ _('Exceptions') }} .. autosummary:: {% for item in exceptions %}