Skip to content

Commit 04dd092

Browse files
committed
Merge branch 'master' of github.com:mkdocstrings/python
2 parents 7d5b665 + b053b29 commit 04dd092

31 files changed

+281
-74
lines changed

src/mkdocstrings_handlers/python/handler.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ def __init__(
182182
*args: Any,
183183
config_file_path: str | None = None,
184184
paths: list[str] | None = None,
185+
locale: str = "en",
185186
**kwargs: Any,
186187
) -> None:
187188
"""Initialize the handler.
@@ -190,6 +191,7 @@ def __init__(
190191
*args: Handler name, theme and custom templates.
191192
config_file_path: The MkDocs configuration file path.
192193
paths: A list of paths to use as Griffe search paths.
194+
locale: The locale to use when rendering content.
193195
**kwargs: Same thing, but with keyword arguments.
194196
"""
195197
super().__init__(*args, **kwargs)
@@ -210,6 +212,7 @@ def __init__(
210212
self._paths = search_paths
211213
self._modules_collection: ModulesCollection = ModulesCollection()
212214
self._lines_collection: LinesCollection = LinesCollection()
215+
self._locale = locale
213216

214217
@classmethod
215218
def load_inventory(
@@ -323,7 +326,13 @@ def render(self, data: CollectorItem, config: Mapping[str, Any]) -> str: # noqa
323326
final_config["signature_crossrefs"] = False
324327

325328
return template.render(
326-
**{"config": final_config, data.kind.value: data, "heading_level": heading_level, "root": True},
329+
**{
330+
"config": final_config,
331+
data.kind.value: data,
332+
"heading_level": heading_level,
333+
"root": True,
334+
"locale": self._locale,
335+
},
327336
)
328337

329338
def update_env(self, md: Markdown, config: dict) -> None: # noqa: D102 (ignore missing docstring)
@@ -339,6 +348,7 @@ def update_env(self, md: Markdown, config: dict) -> None: # noqa: D102 (ignore
339348
self.env.filters["filter_objects"] = rendering.do_filter_objects
340349
self.env.filters["stash_crossref"] = lambda ref, length: ref
341350
self.env.filters["get_template"] = rendering.do_get_template
351+
self.env.tests["existing_template"] = lambda template_name: template_name in self.env.list_templates()
342352

343353
def get_anchors(self, data: CollectorItem) -> set[str]: # noqa: D102 (ignore missing docstring)
344354
try:
@@ -352,6 +362,7 @@ def get_handler(
352362
custom_templates: str | None = None,
353363
config_file_path: str | None = None,
354364
paths: list[str] | None = None,
365+
locale: str = "en",
355366
**config: Any, # noqa: ARG001
356367
) -> PythonHandler:
357368
"""Simply return an instance of `PythonHandler`.
@@ -361,6 +372,7 @@ def get_handler(
361372
custom_templates: Directory containing custom templates.
362373
config_file_path: The MkDocs configuration file path.
363374
paths: A list of paths to use as Griffe search paths.
375+
locale: The locale to use when rendering content.
364376
**config: Configuration passed to the handler.
365377
366378
Returns:
@@ -372,4 +384,5 @@ def get_handler(
372384
custom_templates=custom_templates,
373385
config_file_path=config_file_path,
374386
paths=paths,
387+
locale=locale,
375388
)

src/mkdocstrings_handlers/python/templates/material/_base/docstring/attributes.html

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
{{ log.debug("Rendering attributes section") }}
2+
3+
{% import "language.html" as lang with context %}
4+
25
{% if config.docstring_section_style == "table" %}
36
{% block table_style %}
4-
<p><strong>{{ section.title or "Attributes:" }}</strong></p>
7+
<p><strong>{{ section.title or lang.t("Attributes:") }}</strong></p>
58
<table>
69
<thead>
710
<tr>
8-
<th>Name</th>
9-
<th>Type</th>
10-
<th>Description</th>
11+
<th>{{ lang.t("Name") }}</th>
12+
<th>{{ lang.t("Type") }}</th>
13+
<th>{{ lang.t("Description") }}</th>
1114
</tr>
1215
</thead>
1316
<tbody>
@@ -33,7 +36,7 @@
3336
{% endblock table_style %}
3437
{% elif config.docstring_section_style == "list" %}
3538
{% block list_style %}
36-
<p>{{ section.title or "Attributes:" }}</p>
39+
<p>{{ section.title or lang.t("Attributes:") }}</p>
3740
<ul>
3841
{% for attribute in section.value %}
3942
<li class="field-body">
@@ -56,8 +59,8 @@
5659
<table>
5760
<thead>
5861
<tr>
59-
<th><b>{{ (section.title or "ATTRIBUTE").rstrip(":").upper() }}</b></th>
60-
<th><b>DESCRIPTION</b></th>
62+
<th><b>{{ (section.title or lang.t("ATTRIBUTE")).rstrip(":").upper() }}</b></th>
63+
<th><b>{{ lang.t("DESCRIPTION") }}</b></th>
6164
</tr>
6265
</thead>
6366
<tbody>

src/mkdocstrings_handlers/python/templates/material/_base/docstring/examples.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{{ log.debug("Rendering examples section") }}
2-
<p><strong>{{ section.title or "Examples:" }}</strong></p>
2+
3+
{% import "language.html" as lang with context %}
4+
5+
<p><strong>{{ section.title or lang.t("Examples:") }}</strong></p>
36
{% for section_type, sub_section in section.value %}
47
{% if section_type.value == "text" %}
58
{{ sub_section|convert_markdown(heading_level, html_id) }}

src/mkdocstrings_handlers/python/templates/material/_base/docstring/other_parameters.html

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
{{ log.debug("Rendering other parameters section") }}
2+
3+
{% import "language.html" as lang with context %}
4+
25
{% if config.docstring_section_style == "table" %}
36
{% block table_style %}
4-
<p><strong>{{ section.title or "Other Parameters:" }}</strong></p>
7+
<p><strong>{{ section.title or lang.t("Other Parameters:") }}</strong></p>
58
<table>
69
<thead>
710
<tr>
8-
<th>Name</th>
9-
<th>Type</th>
10-
<th>Description</th>
11+
<th>{{ lang.t("Name") }}</th>
12+
<th>{{ lang.t("Type") }}</th>
13+
<th>{{ lang.t("Description") }}</th>
1114
</tr>
1215
</thead>
1316
<tbody>
@@ -33,7 +36,7 @@
3336
{% endblock table_style %}
3437
{% elif config.docstring_section_style == "list" %}
3538
{% block list_style %}
36-
<p>{{ section.title or "Other Parameters:" }}</p>
39+
<p>{{ section.title or lang.t("Other Parameters:") }}</p>
3740
<ul>
3841
{% for parameter in section.value %}
3942
<li class="field-body">
@@ -56,8 +59,8 @@
5659
<table>
5760
<thead>
5861
<tr>
59-
<th><b>{{ (section.title or "PARAMETER").rstrip(":").upper() }}</b></th>
60-
<th><b>DESCRIPTION</b></th>
62+
<th><b>{{ (section.title or lang.t("PARAMETER")).rstrip(":").upper() }}</b></th>
63+
<th><b>{{ lang.t("DESCRIPTION") }}</b></th>
6164
</tr>
6265
</thead>
6366
<tbody>
@@ -71,7 +74,7 @@
7174
<p>
7275
{% if parameter.annotation %}
7376
<span class="doc-param-annotation">
74-
<b>TYPE:</b>
77+
<b>{{ lang.t("TYPE:") }}</b>
7578
{% with expression = parameter.annotation %}
7679
<code>{% include "expression.html" with context %}</code>
7780
{% endwith %}

src/mkdocstrings_handlers/python/templates/material/_base/docstring/parameters.html

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
{{ log.debug("Rendering parameters section") }}
2+
3+
{% import "language.html" as lang with context %}
4+
25
{% if config.docstring_section_style == "table" %}
36
{% block table_style %}
4-
<p><strong>{{ section.title or "Parameters:" }}</strong></p>
7+
<p><strong>{{ section.title or lang.t("Parameters:") }}</strong></p>
58
<table>
69
<thead>
710
<tr>
8-
<th>Name</th>
9-
<th>Type</th>
10-
<th>Description</th>
11-
<th>Default</th>
11+
<th>{{ lang.t("Name") }}</th>
12+
<th>{{ lang.t("Type") }}</th>
13+
<th>{{ lang.t("Description") }}</th>
14+
<th>{{ lang.t("Default") }}</th>
1215
</tr>
1316
</thead>
1417
<tbody>
@@ -33,7 +36,7 @@
3336
<code>{% include "expression.html" with context %}</code>
3437
{% endwith %}
3538
{% else %}
36-
<em>required</em>
39+
<em>{{ lang.t("required") }}</em>
3740
{% endif %}
3841
</td>
3942
</tr>
@@ -43,7 +46,7 @@
4346
{% endblock table_style %}
4447
{% elif config.docstring_section_style == "list" %}
4548
{% block list_style %}
46-
<p>{{ section.title or "Parameters:" }}</p>
49+
<p>{{ section.title or lang.t("Parameters:") }}</p>
4750
<ul>
4851
{% for parameter in section.value %}
4952
<li class="field-body">
@@ -66,8 +69,8 @@
6669
<table>
6770
<thead>
6871
<tr>
69-
<th><b>{{ (section.title or "PARAMETER").rstrip(":").upper() }}</b></th>
70-
<th><b>DESCRIPTION</b></th>
72+
<th><b>{{ (section.title or lang.t("PARAMETER")).rstrip(":").upper() }}</b></th>
73+
<th><b> {{ lang.t("DESCRIPTION") }}</b></th>
7174
</tr>
7275
</thead>
7376
<tbody>
@@ -81,15 +84,15 @@
8184
<p>
8285
{% if parameter.annotation %}
8386
<span class="doc-param-annotation">
84-
<b>TYPE:</b>
87+
<b>{{ lang.t("TYPE:") }}</b>
8588
{% with expression = parameter.annotation %}
8689
<code>{% include "expression.html" with context %}</code>
8790
{% endwith %}
8891
</span>
8992
{% endif %}
9093
{% if parameter.default %}
9194
<span class="doc-param-default">
92-
<b>DEFAULT:</b>
95+
<b>{{ lang.t("DEFAULT:") }}</b>
9396
{% with expression = parameter.default %}
9497
<code>{% include "expression.html" with context %}</code>
9598
{% endwith %}

src/mkdocstrings_handlers/python/templates/material/_base/docstring/raises.html

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
{{ log.debug("Rendering raises section") }}
2+
3+
{% import "language.html" as lang with context %}
4+
25
{% if config.docstring_section_style == "table" %}
36
{% block table_style %}
4-
<p><strong>{{ section.title or "Raises:" }}</strong></p>
7+
<p><strong>{{ section.title or lang.t("Raises:") }}</strong></p>
58
<table>
69
<thead>
710
<tr>
8-
<th>Type</th>
9-
<th>Description</th>
11+
<th>{{ lang.t("Type") }}</th>
12+
<th>{{ lang.t("Description") }}</th>
1013
</tr>
1114
</thead>
1215
<tbody>
@@ -31,7 +34,7 @@
3134
{% endblock table_style %}
3235
{% elif config.docstring_section_style == "list" %}
3336
{% block list_style %}
34-
<p>{{ section.title or "Raises:" }}</p>
37+
<p>{{ lang.t(section.title) or lang.t("Raises:") }}</p>
3538
<ul>
3639
{% for raises in section.value %}
3740
<li class="field-body">
@@ -53,8 +56,8 @@
5356
<table>
5457
<thead>
5558
<tr>
56-
<th><b>{{ (section.title or "RAISES").rstrip(":").upper() }}</b></th>
57-
<th><b>DESCRIPTION</b></th>
59+
<th><b>{{ (section.title or lang.t("RAISES")).rstrip(":").upper() }}</b></th>
60+
<th><b>{{ lang.t("DESCRIPTION") }}</b></th>
5861
</tr>
5962
</thead>
6063
<tbody>

src/mkdocstrings_handlers/python/templates/material/_base/docstring/receives.html

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
{{ log.debug("Rendering receives section") }}
2+
3+
{% import "language.html" as lang with context %}
4+
25
{% if config.docstring_section_style == "table" %}
36
{% block table_style %}
47
{% set name_column = section.value|selectattr("name")|any %}
5-
<p><strong>{{ section.title or "Receives:" }}</strong></p>
8+
<p><strong>{{ section.title or lang.t("Receives:") }}</strong></p>
69
<table>
710
<thead>
811
<tr>
9-
{% if name_column %}<th>Name</th>{% endif %}
10-
<th>Type</th>
11-
<th>Description</th>
12+
{% if name_column %}<th>{{ lang.t("Name") }}</th>{% endif %}
13+
<th>{{ lang.t("Type") }}</th>
14+
<th>{{ lang.t("Description") }}</th>
1215
</tr>
1316
</thead>
1417
<tbody>
@@ -34,7 +37,7 @@
3437
{% endblock table_style %}
3538
{% elif config.docstring_section_style == "list" %}
3639
{% block list_style %}
37-
<p>{{ section.title or "Receives:" }}</p>
40+
<p>{{ section.title or lang.t("Receives:") }}</p>
3841
<ul>
3942
{% for receives in section.value %}
4043
<li class="field-body">
@@ -59,8 +62,8 @@
5962
<table>
6063
<thead>
6164
<tr>
62-
<th><b>{{ (section.title or "RECEIVES").rstrip(":").upper() }}</b></th>
63-
<th><b>DESCRIPTION</b></th>
65+
<th><b>{{ (section.title or lang.t("RECEIVES")).rstrip(":").upper()) }}</b></th>
66+
<th><b>{{ lang.t("DESCRIPTION") }}</b></th>
6467
</tr>
6568
</thead>
6669
<tbody>
@@ -84,7 +87,7 @@
8487
{% if receives.name and receives.annotation %}
8588
<p>
8689
<span class="doc-receives-annotation">
87-
<b>TYPE:</b>
90+
<b>{{ lang.t("TYPE:") }}</b>
8891
{% with expression = receives.annotation %}
8992
<code>{% include "expression.html" with context %}</code>
9093
{% endwith %}

src/mkdocstrings_handlers/python/templates/material/_base/docstring/returns.html

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
{{ log.debug("Rendering returns section") }}
2+
3+
{% import "language.html" as lang with context %}
4+
25
{% if config.docstring_section_style == "table" %}
36
{% block table_style %}
47
{% set name_column = section.value|selectattr("name")|any %}
5-
<p><strong>{{ section.title or "Returns:" }}</strong></p>
8+
<p><strong>{{ section.title or lang.t("Returns:") }}</strong></p>
69
<table>
710
<thead>
811
<tr>
9-
{% if name_column %}<th>Name</th>{% endif %}
10-
<th>Type</th>
11-
<th>Description</th>
12+
{% if name_column %}<th>{{ lang.t("Name") }}</th>{% endif %}
13+
<th>{{ lang.t("Type") }}</th>
14+
<th>{{ lang.t("Description") }}</th>
1215
</tr>
1316
</thead>
1417
<tbody>
@@ -34,7 +37,7 @@
3437
{% endblock table_style %}
3538
{% elif config.docstring_section_style == "list" %}
3639
{% block list_style %}
37-
<p>{{ section.title or "Returns:" }}</p>
40+
<p>{{ section.title or lang.t("Returns:") }}</p>
3841
<ul>
3942
{% for returns in section.value %}
4043
<li class="field-body">
@@ -59,8 +62,8 @@
5962
<table>
6063
<thead>
6164
<tr>
62-
<th><b>{{ (section.title or "RETURNS").rstrip(":").upper() }}</b></th>
63-
<th><b>DESCRIPTION</b></th>
65+
<th><b>{{ (section.title or lang.t("RETURNS")).rstrip(":").upper() }}</b></th>
66+
<th><b>{{ lang.t("DESCRIPTION").upper() }}</b></th>
6467
</tr>
6568
</thead>
6669
<tbody>
@@ -84,7 +87,7 @@
8487
{% if returns.name and returns.annotation %}
8588
<p>
8689
<span class="doc-returns-annotation">
87-
<b>TYPE:</b>
90+
<b>{{ lang.t("TYPE:") }}</b>
8891
{% with expression = returns.annotation %}
8992
<code>{% include "expression.html" with context %}</code>
9093
{% endwith %}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy