@@ -71,7 +74,7 @@
{% if parameter.annotation %}
- TYPE:
+ {{ lang.t("TYPE:") }}
{% with expression = parameter.annotation %}
{% include "expression.html" with context %}
{% endwith %}
diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/docstring/parameters.html b/src/mkdocstrings_handlers/python/templates/material/_base/docstring/parameters.html
index b2b57509..515be812 100644
--- a/src/mkdocstrings_handlers/python/templates/material/_base/docstring/parameters.html
+++ b/src/mkdocstrings_handlers/python/templates/material/_base/docstring/parameters.html
@@ -1,14 +1,17 @@
{{ log.debug("Rendering parameters section") }}
+
+{% import "language.html" as lang with context %}
+
{% if config.docstring_section_style == "table" %}
{% block table_style %}
- {{ section.title or "Parameters:" }}
+ {{ section.title or lang.t("Parameters:") }}
- | Name |
- Type |
- Description |
- Default |
+ {{ lang.t("Name") }} |
+ {{ lang.t("Type") }} |
+ {{ lang.t("Description") }} |
+ {{ lang.t("Default") }} |
@@ -33,7 +36,7 @@
{% include "expression.html" with context %}
{% endwith %}
{% else %}
- required
+ {{ lang.t("required") }}
{% endif %}
@@ -43,7 +46,7 @@
{% endblock table_style %}
{% elif config.docstring_section_style == "list" %}
{% block list_style %}
- {{ section.title or "Parameters:" }}
+ {{ section.title or lang.t("Parameters:") }}
{% for parameter in section.value %}
-
@@ -66,8 +69,8 @@
- | {{ (section.title or "PARAMETER").rstrip(":").upper() }} |
- DESCRIPTION |
+ {{ (section.title or lang.t("PARAMETER")).rstrip(":").upper() }} |
+ {{ lang.t("DESCRIPTION") }} |
@@ -81,7 +84,7 @@
{% if parameter.annotation %}
- TYPE:
+ {{ lang.t("TYPE:") }}
{% with expression = parameter.annotation %}
{% include "expression.html" with context %}
{% endwith %}
@@ -89,7 +92,7 @@
{% endif %}
{% if parameter.default %}
- DEFAULT:
+ {{ lang.t("DEFAULT:") }}
{% with expression = parameter.default %}
{% include "expression.html" with context %}
{% endwith %}
diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/docstring/raises.html b/src/mkdocstrings_handlers/python/templates/material/_base/docstring/raises.html
index 45832d1c..e4edc66a 100644
--- a/src/mkdocstrings_handlers/python/templates/material/_base/docstring/raises.html
+++ b/src/mkdocstrings_handlers/python/templates/material/_base/docstring/raises.html
@@ -1,12 +1,15 @@
{{ log.debug("Rendering raises section") }}
+
+{% import "language.html" as lang with context %}
+
{% if config.docstring_section_style == "table" %}
{% block table_style %}
- {{ section.title or "Raises:" }}
+ {{ section.title or lang.t("Raises:") }}
- | Type |
- Description |
+ {{ lang.t("Type") }} |
+ {{ lang.t("Description") }} |
@@ -31,7 +34,7 @@
{% endblock table_style %}
{% elif config.docstring_section_style == "list" %}
{% block list_style %}
- {{ section.title or "Raises:" }}
+ {{ lang.t(section.title) or lang.t("Raises:") }}
{% for raises in section.value %}
-
@@ -53,8 +56,8 @@
- | {{ (section.title or "RAISES").rstrip(":").upper() }} |
- DESCRIPTION |
+ {{ (section.title or lang.t("RAISES")).rstrip(":").upper() }} |
+ {{ lang.t("DESCRIPTION") }} |
diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/docstring/receives.html b/src/mkdocstrings_handlers/python/templates/material/_base/docstring/receives.html
index 03b241cb..09b8caed 100644
--- a/src/mkdocstrings_handlers/python/templates/material/_base/docstring/receives.html
+++ b/src/mkdocstrings_handlers/python/templates/material/_base/docstring/receives.html
@@ -1,14 +1,17 @@
{{ log.debug("Rendering receives section") }}
+
+{% import "language.html" as lang with context %}
+
{% if config.docstring_section_style == "table" %}
{% block table_style %}
{% set name_column = section.value|selectattr("name")|any %}
- {{ section.title or "Receives:" }}
+ {{ section.title or lang.t("Receives:") }}
- {% if name_column %}| Name | {% endif %}
- Type |
- Description |
+ {% if name_column %}{{ lang.t("Name") }} | {% endif %}
+ {{ lang.t("Type") }} |
+ {{ lang.t("Description") }} |
@@ -34,7 +37,7 @@
{% endblock table_style %}
{% elif config.docstring_section_style == "list" %}
{% block list_style %}
- {{ section.title or "Receives:" }}
+ {{ section.title or lang.t("Receives:") }}
{% for receives in section.value %}
-
@@ -59,8 +62,8 @@
- | {{ (section.title or "RECEIVES").rstrip(":").upper() }} |
- DESCRIPTION |
+ {{ (section.title or lang.t("RECEIVES")).rstrip(":").upper()) }} |
+ {{ lang.t("DESCRIPTION") }} |
@@ -84,7 +87,7 @@
{% if receives.name and receives.annotation %}
- TYPE:
+ {{ lang.t("TYPE:") }}
{% with expression = receives.annotation %}
{% include "expression.html" with context %}
{% endwith %}
diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/docstring/returns.html b/src/mkdocstrings_handlers/python/templates/material/_base/docstring/returns.html
index ad63db83..374f8de4 100644
--- a/src/mkdocstrings_handlers/python/templates/material/_base/docstring/returns.html
+++ b/src/mkdocstrings_handlers/python/templates/material/_base/docstring/returns.html
@@ -1,14 +1,17 @@
{{ log.debug("Rendering returns section") }}
+
+{% import "language.html" as lang with context %}
+
{% if config.docstring_section_style == "table" %}
{% block table_style %}
{% set name_column = section.value|selectattr("name")|any %}
- {{ section.title or "Returns:" }}
+ {{ section.title or lang.t("Returns:") }}
- {% if name_column %}| Name | {% endif %}
- Type |
- Description |
+ {% if name_column %}{{ lang.t("Name") }} | {% endif %}
+ {{ lang.t("Type") }} |
+ {{ lang.t("Description") }} |
@@ -34,7 +37,7 @@
{% endblock table_style %}
{% elif config.docstring_section_style == "list" %}
{% block list_style %}
- {{ section.title or "Returns:" }}
+ {{ section.title or lang.t("Returns:") }}
{% for returns in section.value %}
-
@@ -59,8 +62,8 @@
- | {{ (section.title or "RETURNS").rstrip(":").upper() }} |
- DESCRIPTION |
+ {{ (section.title or lang.t("RETURNS")).rstrip(":").upper() }} |
+ {{ lang.t("DESCRIPTION").upper() }} |
@@ -84,7 +87,7 @@
{% if returns.name and returns.annotation %}
- TYPE:
+ {{ lang.t("TYPE:") }}
{% with expression = returns.annotation %}
{% include "expression.html" with context %}
{% endwith %}
diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/docstring/warns.html b/src/mkdocstrings_handlers/python/templates/material/_base/docstring/warns.html
index 49ae4380..cf1cc4a6 100644
--- a/src/mkdocstrings_handlers/python/templates/material/_base/docstring/warns.html
+++ b/src/mkdocstrings_handlers/python/templates/material/_base/docstring/warns.html
@@ -1,12 +1,15 @@
{{ log.debug("Rendering warns section") }}
+
+{% import "language.html" as lang with context %}
+
{% if config.docstring_section_style == "table" %}
{% block table_style %}
- {{ section.title or "Warns:" }}
+ {{ section.title or lang.t("Warns:") }}
- | Type |
- Description |
+ {{ lang.t("Type") }} |
+ {{ lang.t("Description") }} |
@@ -31,7 +34,7 @@
{% endblock table_style %}
{% elif config.docstring_section_style == "list" %}
{% block list_style %}
- {{ section.title or "Warns:" }}
+ {{ section.title or lang.t("Warns:") }}
{% for warns in section.value %}
-
@@ -53,8 +56,8 @@
- | {{ (section.title or "WARNS").rstrip(":").upper() }} |
- DESCRIPTION |
+ {{ (section.title or lang.t("WARNS")).rstrip(":").upper() }} |
+ {{ lang.t("DESCRIPTION") }} |
diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/docstring/yields.html b/src/mkdocstrings_handlers/python/templates/material/_base/docstring/yields.html
index 93b3cfd2..9a0db29c 100644
--- a/src/mkdocstrings_handlers/python/templates/material/_base/docstring/yields.html
+++ b/src/mkdocstrings_handlers/python/templates/material/_base/docstring/yields.html
@@ -1,14 +1,17 @@
{{ log.debug("Rendering yields section") }}
+
+{% import "language.html" as lang with context %}
+
{% if config.docstring_section_style == "table" %}
{% block table_style %}
{% set name_column = section.value|selectattr("name")|any %}
- {{ section.title or "Yields:" }}
+ {{ section.title or lang.t("Yields:") }}
- {% if name_column %}| Name | {% endif %}
- Type |
- Description |
+ {% if name_column %}{{ lang.t("Name") }} | {% endif %}
+ {{ lang.t("Type") }} |
+ {{ lang.t("Description") }} |
@@ -34,7 +37,7 @@
{% endblock table_style %}
{% elif config.docstring_section_style == "list" %}
{% block list_style %}
- {{ section.title or "Yields:" }}
+ {{ section.title or lang.t("Yields:") }}
{% for yields in section.value %}
-
@@ -59,8 +62,8 @@
- | {{ (section.title or "YIELDS").rstrip(":").upper() }} |
- DESCRIPTION |
+ {{ (section.title or lang.t("YIELDS")).rstrip(":").upper() }} |
+ {{ lang.t("DESCRIPTION") }} |
@@ -84,7 +87,7 @@
{% if yields.name and yields.annotation %}
- TYPE:
+ {{ lang.t("TYPE:") }}:
{% with expression = yields.annotation %}
{% include "expression.html" with context %}
{% endwith %}
diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/function.html b/src/mkdocstrings_handlers/python/templates/material/_base/function.html
index 70c26892..4290b115 100644
--- a/src/mkdocstrings_handlers/python/templates/material/_base/function.html
+++ b/src/mkdocstrings_handlers/python/templates/material/_base/function.html
@@ -1,5 +1,7 @@
{{ log.debug("Rendering " + function.path) }}
+{% import "language.html" as lang with context %}
+
{% with html_id = function.path %}
@@ -21,26 +23,32 @@
class="doc doc-heading",
toc_label=function.name ~ "()") %}
- {% if config.separate_signature %}
-
{% if show_full_path %}{{ function.path }}{% else %}{{ function.name }}{% endif %}
- {% else %}
- {% filter highlight(language="python", inline=True) %}
- {% if show_full_path %}{{ function.path }}{% else %}{{ function.name }}{% endif %}
- {% include "signature.html" with context %}
- {% endfilter %}
- {% endif %}
+ {% block heading scoped %}
+ {% if config.separate_signature %}
+
{% if show_full_path %}{{ function.path }}{% else %}{{ function.name }}{% endif %}
+ {% else %}
+ {% filter highlight(language="python", inline=True) %}
+ {% if show_full_path %}{{ function.path }}{% else %}{{ function.name }}{% endif %}
+ {% include "signature.html" with context %}
+ {% endfilter %}
+ {% endif %}
+ {% endblock heading %}
- {% with labels = function.labels %}
- {% include "labels.html" with context %}
- {% endwith %}
+ {% block labels scoped %}
+ {% with labels = function.labels %}
+ {% include "labels.html" with context %}
+ {% endwith %}
+ {% endblock labels %}
{% endfilter %}
- {% if config.separate_signature %}
- {% filter format_signature(function, config.line_length, crossrefs=config.signature_crossrefs) %}
- {% if show_full_path %}{{ function.path }}{% else %}{{ function.name }}{% endif %}
- {% endfilter %}
- {% endif %}
+ {% block signature scoped %}
+ {% if config.separate_signature %}
+ {% filter format_signature(function, config.line_length, crossrefs=config.signature_crossrefs) %}
+ {% if show_full_path %}{{ function.path }}{% else %}{{ function.name }}{% endif %}
+ {% endfilter %}
+ {% endif %}
+ {% endblock signature %}
{% else %}
{% if config.show_root_toc_entry %}
@@ -55,16 +63,22 @@
{% endif %}
- {% with docstring_sections = function.docstring.parsed %}
- {% include "docstring.html" with context %}
- {% endwith %}
+ {% block contents scoped %}
+ {% block docstring scoped %}
+ {% with docstring_sections = function.docstring.parsed %}
+ {% include "docstring.html" with context %}
+ {% endwith %}
+ {% endblock docstring %}
- {% if config.show_source and function.source %}
-
- Source code in {{ function.relative_filepath }}
- {{ function.source|highlight(language="python", linestart=function.lineno, linenums=True) }}
-
- {% endif %}
+ {% block source scoped %}
+ {% if config.show_source and function.source %}
+
+ {{ lang.t("Source code in") }} {{ function.relative_filepath }}
+ {{ function.source|highlight(language="python", linestart=function.lineno, linenums=True) }}
+
+ {% endif %}
+ {% endblock source %}
+ {% endblock contents %}
{% endwith %}
diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/labels.html b/src/mkdocstrings_handlers/python/templates/material/_base/labels.html
index 4f2f72d9..0c84067a 100644
--- a/src/mkdocstrings_handlers/python/templates/material/_base/labels.html
+++ b/src/mkdocstrings_handlers/python/templates/material/_base/labels.html
@@ -1,7 +1,7 @@
{% if labels %}
{{ log.debug("Rendering labels") }}
- {% for label in labels %}
+ {% for label in labels|sort %}
{{ label }}
{% endfor %}
diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/languages/en.html b/src/mkdocstrings_handlers/python/templates/material/_base/languages/en.html
new file mode 100644
index 00000000..5836cccf
--- /dev/null
+++ b/src/mkdocstrings_handlers/python/templates/material/_base/languages/en.html
@@ -0,0 +1,28 @@
+
+{% macro t(key) %}{{ {
+ "ATTRIBUTE": "ATTRIBUTE",
+ "Attributes:": "Attributes:",
+ "DEFAULT:": "DEFAULT:",
+ "Default": "Default",
+ "DESCRIPTION": "DESCRIPTION",
+ "Description": "Description",
+ "Examples:": "Examples:",
+ "Name": "Name",
+ "Other Parameters:": "Other Parameters:",
+ "PARAMETER": "PARAMETER",
+ "Parameters:": "Parameters:",
+ "RAISES": "RAISES",
+ "Raises:" : "Raises:",
+ "RECEIVES": "RECEIVES",
+ "Receives:": "Receives:",
+ "required": "required",
+ "RETURNS": "RETURNS",
+ "Returns:": "Returns:",
+ "Source code in": "Source code in",
+ "TYPE:": "TYPE:",
+ "Type": "Type",
+ "WARNS": "WARNS",
+ "Warns:": "Warns:",
+ "YIELDS": "YIELDS",
+ "Yields:": "Yields:",
+ }[key] }}{% endmacro %}
\ No newline at end of file
diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/languages/ja.html b/src/mkdocstrings_handlers/python/templates/material/_base/languages/ja.html
new file mode 100644
index 00000000..6b52ebcd
--- /dev/null
+++ b/src/mkdocstrings_handlers/python/templates/material/_base/languages/ja.html
@@ -0,0 +1,28 @@
+
+{% macro t(key) %}{{ {
+ "ATTRIBUTE": "属性",
+ "Attributes:": "属性:",
+ "DEFAULT:": "デフォルト:",
+ "Default": "デフォルト",
+ "DESCRIPTION": "デスクリプション",
+ "Description": "デスクリプション",
+ "Examples:": "例:",
+ "Name": "名前",
+ "Other Parameters:": "他の引数:",
+ "PARAMETER": "引数",
+ "Parameters:": "引数:",
+ "RAISES": "発生",
+ "Raises:" : "発生:",
+ "RECEIVES": "取得",
+ "Receives:": "取得:",
+ "required": "必須",
+ "RETURNS": "戻り値",
+ "Returns:": "戻り値:",
+ "Source code in": "ソースコード位置:",
+ "TYPE:": "タイプ:",
+ "Type": "タイプ",
+ "WARNS": "警告",
+ "Warns:": "警告:",
+ "YIELDS": "返す",
+ "Yields:": "返す:",
+}[key] }}{% endmacro %}
\ No newline at end of file
diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/languages/zh.html b/src/mkdocstrings_handlers/python/templates/material/_base/languages/zh.html
new file mode 100644
index 00000000..a1516f15
--- /dev/null
+++ b/src/mkdocstrings_handlers/python/templates/material/_base/languages/zh.html
@@ -0,0 +1,28 @@
+
+{% macro t(key) %}{{ {
+ "ATTRIBUTE": "属性",
+ "Attributes:": "属性:",
+ "DEFAULT:": "默认:",
+ "Default": "默认",
+ "DESCRIPTION": "描述",
+ "Description": "描述",
+ "Examples:": "示例:",
+ "Name": "名称",
+ "Other Parameters:": "其他参数:",
+ "PARAMETER": "参数",
+ "Parameters:": "参数:",
+ "RAISES": "引发",
+ "Raises:" : "引发:",
+ "Receives:": "接收:",
+ "RECEIVES": "接收",
+ "required": "必需",
+ "RETURNS": "返回",
+ "Returns:": "返回:",
+ "Source code in": "源代码位于:",
+ "TYPE:": "类型:",
+ "Type": "类型",
+ "Warns:": "警告:",
+ "WARNS": "警告",
+ "YIELDS": "产生",
+ "Yields:": "产生:",
+ }[key] }}{% endmacro %}
\ No newline at end of file
diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/module.html b/src/mkdocstrings_handlers/python/templates/material/_base/module.html
index 8e14d354..299b4941 100644
--- a/src/mkdocstrings_handlers/python/templates/material/_base/module.html
+++ b/src/mkdocstrings_handlers/python/templates/material/_base/module.html
@@ -21,17 +21,21 @@
class="doc doc-heading",
toc_label=module.name) %}
- {% with module_name = module.path if show_full_path else module.name %}
- {% if config.separate_signature %}
-
{{ module_name }}
- {% else %}
-
{{ module_name }}
- {% endif %}
- {% endwith %}
-
- {% with labels = module.labels %}
- {% include "labels.html" with context %}
- {% endwith %}
+ {% block heading scoped %}
+ {% with module_name = module.path if show_full_path else module.name %}
+ {% if config.separate_signature %}
+
{{ module_name }}
+ {% else %}
+
{{ module_name }}
+ {% endif %}
+ {% endwith %}
+ {% endblock heading %}
+
+ {% block labels scoped %}
+ {% with labels = module.labels %}
+ {% include "labels.html" with context %}
+ {% endwith %}
+ {% endblock labels %}
{% endfilter %}
@@ -48,15 +52,21 @@
{% endif %}
- {% with docstring_sections = module.docstring.parsed %}
- {% include "docstring.html" with context %}
- {% endwith %}
-
- {% with obj = module %}
- {% set root = False %}
- {% set heading_level = heading_level + 1 %}
- {% include "children.html" with context %}
- {% endwith %}
+ {% block contents scoped %}
+ {% block docstring scoped %}
+ {% with docstring_sections = module.docstring.parsed %}
+ {% include "docstring.html" with context %}
+ {% endwith %}
+ {% endblock docstring %}
+
+ {% block children scoped %}
+ {% with obj = module %}
+ {% set root = False %}
+ {% set heading_level = heading_level + 1 %}
+ {% include "children.html" with context %}
+ {% endwith %}
+ {% endblock children %}
+ {% endblock contents %}
{% endwith %}
diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/signature.html b/src/mkdocstrings_handlers/python/templates/material/_base/signature.html
index ea642f51..3ea0f91e 100644
--- a/src/mkdocstrings_handlers/python/templates/material/_base/signature.html
+++ b/src/mkdocstrings_handlers/python/templates/material/_base/signature.html
@@ -55,7 +55,10 @@
{%- endif -%}
{%- endfor -%}
)
- {%- if config.show_signature_annotations and function.annotation %} -> {% if config.separate_signature and config.signature_crossrefs -%}
+ {%- if config.show_signature_annotations
+ and function.annotation
+ and not (config.merge_init_into_class and function.name == "__init__" )
+ %} -> {% if config.separate_signature and config.signature_crossrefs -%}
{%- with expression = function.annotation %}{% include "expression.html" with context %}{%- endwith -%}
{%- else -%}
{{ function.annotation|safe }}
diff --git a/src/mkdocstrings_handlers/python/templates/material/language.html b/src/mkdocstrings_handlers/python/templates/material/language.html
new file mode 100644
index 00000000..26647ff3
--- /dev/null
+++ b/src/mkdocstrings_handlers/python/templates/material/language.html
@@ -0,0 +1,10 @@
+
+{% set lang_pth = "languages/" ~ locale ~ ".html" %}
+{% if lang_pth is existing_template %}
+ {% import lang_pth as lang %}
+ {% import "languages/en.html" as fallback %}
+ {% macro t(key) %}{{ lang.t(key) or fallback.t(key) }}{% endmacro %}
+{% else %}
+ {% import "languages/en.html" as lang %}
+ {% macro t(key) %}{{ lang.t(key) }}{% endmacro %}
+{% endif %}
diff --git a/src/mkdocstrings_handlers/python/templates/material/languages/en.html b/src/mkdocstrings_handlers/python/templates/material/languages/en.html
new file mode 100644
index 00000000..eab0a3f3
--- /dev/null
+++ b/src/mkdocstrings_handlers/python/templates/material/languages/en.html
@@ -0,0 +1 @@
+{% extends "_base/languages/en.html" %}
\ No newline at end of file
diff --git a/src/mkdocstrings_handlers/python/templates/material/languages/ja.html b/src/mkdocstrings_handlers/python/templates/material/languages/ja.html
new file mode 100644
index 00000000..0463322d
--- /dev/null
+++ b/src/mkdocstrings_handlers/python/templates/material/languages/ja.html
@@ -0,0 +1 @@
+{% extends "_base/languages/ja.html" %}
\ No newline at end of file
diff --git a/src/mkdocstrings_handlers/python/templates/material/languages/zh.html b/src/mkdocstrings_handlers/python/templates/material/languages/zh.html
new file mode 100644
index 00000000..90aeae6f
--- /dev/null
+++ b/src/mkdocstrings_handlers/python/templates/material/languages/zh.html
@@ -0,0 +1 @@
+{% extends "_base/languages/zh.html" %}
\ No newline at end of file
diff --git a/src/mkdocstrings_handlers/python/templates/readthedocs/docstring/attributes.html b/src/mkdocstrings_handlers/python/templates/readthedocs/docstring/attributes.html
index 3ed566d5..6f597cd1 100644
--- a/src/mkdocstrings_handlers/python/templates/readthedocs/docstring/attributes.html
+++ b/src/mkdocstrings_handlers/python/templates/readthedocs/docstring/attributes.html
@@ -1,4 +1,7 @@
{{ log.debug() }}
+
+{% import "language.html" as lang with context %}
+
@@ -6,7 +9,7 @@
- | {{ section.title or "Attributes:" }} |
+ {{ section.title or lang.t("Attributes:") }} |
{% for attribute in section.value %}
diff --git a/src/mkdocstrings_handlers/python/templates/readthedocs/docstring/other_parameters.html b/src/mkdocstrings_handlers/python/templates/readthedocs/docstring/other_parameters.html
index c5b4b039..d37bc8cb 100644
--- a/src/mkdocstrings_handlers/python/templates/readthedocs/docstring/other_parameters.html
+++ b/src/mkdocstrings_handlers/python/templates/readthedocs/docstring/other_parameters.html
@@ -1,4 +1,7 @@
{{ log.debug() }}
+
+{% import "language.html" as lang with context %}
+
@@ -6,7 +9,7 @@
- | {{ section.title or "Other parameters:" }} |
+ {{ section.title or lang.t("Other parameters:") }} |
{% for parameter in section.value %}
diff --git a/src/mkdocstrings_handlers/python/templates/readthedocs/docstring/parameters.html b/src/mkdocstrings_handlers/python/templates/readthedocs/docstring/parameters.html
index b05733a7..461fe2a1 100644
--- a/src/mkdocstrings_handlers/python/templates/readthedocs/docstring/parameters.html
+++ b/src/mkdocstrings_handlers/python/templates/readthedocs/docstring/parameters.html
@@ -1,4 +1,7 @@
{{ log.debug() }}
+
+{% import "language.html" as lang with context %}
+
@@ -6,7 +9,7 @@
- | {{ section.title or "Parameters:" }} |
+ {{ section.title or lang.t("Parameters:") }} |
{% for parameter in section.value %}
diff --git a/src/mkdocstrings_handlers/python/templates/readthedocs/docstring/raises.html b/src/mkdocstrings_handlers/python/templates/readthedocs/docstring/raises.html
index b744df22..f82437dd 100644
--- a/src/mkdocstrings_handlers/python/templates/readthedocs/docstring/raises.html
+++ b/src/mkdocstrings_handlers/python/templates/readthedocs/docstring/raises.html
@@ -1,4 +1,7 @@
{{ log.debug() }}
+
+{% import "language.html" as lang with context %}
+
@@ -6,7 +9,7 @@
- | {{ section.title or "Raises:" }} |
+ {{ section.title or lang.t("Raises:") }} |
{% for raises in section.value %}
diff --git a/src/mkdocstrings_handlers/python/templates/readthedocs/docstring/receives.html b/src/mkdocstrings_handlers/python/templates/readthedocs/docstring/receives.html
index 127bcd3c..f112351d 100644
--- a/src/mkdocstrings_handlers/python/templates/readthedocs/docstring/receives.html
+++ b/src/mkdocstrings_handlers/python/templates/readthedocs/docstring/receives.html
@@ -1,4 +1,7 @@
{{ log.debug() }}
+
+{% import "language.html" as lang with context %}
+
@@ -6,7 +9,7 @@
- | {{ section.title or "Receives:" }} |
+ {{ section.title or lang.t("Receives:") }} |
{% for receives in section.value %}
diff --git a/src/mkdocstrings_handlers/python/templates/readthedocs/docstring/returns.html b/src/mkdocstrings_handlers/python/templates/readthedocs/docstring/returns.html
index 92f29e31..28b83774 100644
--- a/src/mkdocstrings_handlers/python/templates/readthedocs/docstring/returns.html
+++ b/src/mkdocstrings_handlers/python/templates/readthedocs/docstring/returns.html
@@ -1,4 +1,7 @@
{{ log.debug() }}
+
+{% import "language.html" as lang with context %}
+
@@ -6,7 +9,7 @@
- | {{ section.title or "Returns:" }} |
+ {{ section.title or lang.t("Returns:") }} |
{% for returns in section.value %}
diff --git a/src/mkdocstrings_handlers/python/templates/readthedocs/docstring/warns.html b/src/mkdocstrings_handlers/python/templates/readthedocs/docstring/warns.html
index 12631784..35aff0b1 100644
--- a/src/mkdocstrings_handlers/python/templates/readthedocs/docstring/warns.html
+++ b/src/mkdocstrings_handlers/python/templates/readthedocs/docstring/warns.html
@@ -1,4 +1,7 @@
{{ log.debug() }}
+
+{% import "language.html" as lang with context %}
+
@@ -6,7 +9,7 @@
- | {{ section.title or "Warns:" }} |
+ {{ section.title or lang.t("Warns:") }} |
{% for warns in section.value %}
diff --git a/src/mkdocstrings_handlers/python/templates/readthedocs/docstring/yields.html b/src/mkdocstrings_handlers/python/templates/readthedocs/docstring/yields.html
index 86e8ff7b..7838a66a 100644
--- a/src/mkdocstrings_handlers/python/templates/readthedocs/docstring/yields.html
+++ b/src/mkdocstrings_handlers/python/templates/readthedocs/docstring/yields.html
@@ -1,4 +1,7 @@
{{ log.debug() }}
+
+{% import "language.html" as lang with context %}
+
@@ -6,7 +9,7 @@
- | {{ section.title or "Yields:" }} |
+ {{ section.title or lang.t("Yields:") }} |
{% for yields in section.value %}
diff --git a/src/mkdocstrings_handlers/python/templates/readthedocs/language.html b/src/mkdocstrings_handlers/python/templates/readthedocs/language.html
new file mode 100644
index 00000000..26647ff3
--- /dev/null
+++ b/src/mkdocstrings_handlers/python/templates/readthedocs/language.html
@@ -0,0 +1,10 @@
+
+{% set lang_pth = "languages/" ~ locale ~ ".html" %}
+{% if lang_pth is existing_template %}
+ {% import lang_pth as lang %}
+ {% import "languages/en.html" as fallback %}
+ {% macro t(key) %}{{ lang.t(key) or fallback.t(key) }}{% endmacro %}
+{% else %}
+ {% import "languages/en.html" as lang %}
+ {% macro t(key) %}{{ lang.t(key) }}{% endmacro %}
+{% endif %}
diff --git a/src/mkdocstrings_handlers/python/templates/readthedocs/languages/en.html b/src/mkdocstrings_handlers/python/templates/readthedocs/languages/en.html
new file mode 100644
index 00000000..acc6d5a7
--- /dev/null
+++ b/src/mkdocstrings_handlers/python/templates/readthedocs/languages/en.html
@@ -0,0 +1,11 @@
+
+{% macro t(key) %}{{ {
+ "Attributes:": "Attributes:",
+ "Other parameters:": "Other parameters:",
+ "Parameters:": "Parameters:",
+ "Raises:" : "Raises:",
+ "Receives:": "Receives:",
+ "Returns:": "Returns:",
+ "Warns:": "Warns:",
+ "Yields:": "Yields:",
+ }[key] }}{% endmacro %}
\ No newline at end of file
diff --git a/src/mkdocstrings_handlers/python/templates/readthedocs/languages/ja.html b/src/mkdocstrings_handlers/python/templates/readthedocs/languages/ja.html
new file mode 100644
index 00000000..9ae4a568
--- /dev/null
+++ b/src/mkdocstrings_handlers/python/templates/readthedocs/languages/ja.html
@@ -0,0 +1,11 @@
+
+{% macro t(key) %}{{ {
+ "Attributes:": "属性:",
+ "Other Parameters:": "他の引数:",
+ "Parameters:": "引数:",
+ "Raises:" : "発生:",
+ "Receives:": "取得:",
+ "Returns:": "戻り値:",
+ "Warns:": "警告:",
+ "Yields:": "返す:",
+ }[key] }}{% endmacro %}
\ No newline at end of file
diff --git a/src/mkdocstrings_handlers/python/templates/readthedocs/languages/zh.html b/src/mkdocstrings_handlers/python/templates/readthedocs/languages/zh.html
new file mode 100644
index 00000000..42184f9c
--- /dev/null
+++ b/src/mkdocstrings_handlers/python/templates/readthedocs/languages/zh.html
@@ -0,0 +1,11 @@
+
+{% macro t(key) %}{{ {
+ "Attributes:": "属性:",
+ "Other Parameters:": "其他参数:",
+ "Parameters:": "参数:",
+ "Raises:" : "引发:",
+ "Receives:": "接收:",
+ "Returns:": "返回:",
+ "Warns:": "警告:",
+ "Yields:": "产生:",
+ }[key] }}{% endmacro %}
\ No newline at end of file
diff --git a/tests/conftest.py b/tests/conftest.py
index 5a34bd77..b4f3e42e 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -18,6 +18,9 @@
from mkdocstrings_handlers.python.handler import PythonHandler
+pytest_plugins = ["griffe.tests"]
+
+
@pytest.fixture(name="mkdocs_conf")
def fixture_mkdocs_conf(request: pytest.FixtureRequest, tmp_path: Path) -> Iterator[config.Config]:
"""Yield a MkDocs configuration object.
@@ -41,7 +44,7 @@ def fixture_mkdocs_conf(request: pytest.FixtureRequest, tmp_path: Path) -> Itera
**getattr(request, "param", {}),
}
# Re-create it manually as a workaround for https://github.com/mkdocs/mkdocs/issues/2289
- mdx_configs: dict[str, Any] = dict(ChainMap(*conf_dict.get("markdown_extensions", []))) # type: ignore[arg-type]
+ mdx_configs: dict[str, Any] = dict(ChainMap(*conf_dict.get("markdown_extensions", [])))
conf.load_dict(conf_dict)
assert conf.validate() == ([], [])
diff --git a/tests/test_handler.py b/tests/test_handler.py
index fc31942c..4971e132 100644
--- a/tests/test_handler.py
+++ b/tests/test_handler.py
@@ -63,7 +63,8 @@ def test_render_docstring_examples_section(handler: PythonHandler) -> None:
],
)
template = handler.env.get_template("docstring/examples.html")
- rendered = template.render(section=section)
+ rendered = template.render(section=section, locale="en")
+ template.render(section=section, locale="not_existing")
assert "This is an example. " in rendered
assert "print" in rendered
assert "Hello" in rendered
diff --git a/tests/test_rendering.py b/tests/test_rendering.py
index c504d4d0..5d35c121 100644
--- a/tests/test_rendering.py
+++ b/tests/test_rendering.py
@@ -7,6 +7,8 @@
from typing import TYPE_CHECKING, Any
import pytest
+from griffe.collections import ModulesCollection
+from griffe.tests import temporary_visited_module
from mkdocstrings_handlers.python import rendering
@@ -48,6 +50,7 @@ def test_format_signature(name: Markup, signature: str) -> None:
@dataclass
class _FakeObject:
name: str
+ inherited: bool = False
@pytest.mark.parametrize(
@@ -69,3 +72,62 @@ def test_filter_objects(names: list[str], filter_params: dict[str, Any], expecte
filtered = rendering.do_filter_objects(objects, **filter_params) # type: ignore[arg-type]
filtered_names = {obj.name for obj in filtered}
assert set(filtered_names) == set(expected_names)
+
+
+@pytest.mark.parametrize(
+ ("members", "inherited_members", "expected_names"),
+ [
+ (True, True, {"base", "main"}),
+ (True, False, {"main"}),
+ (True, ["base"], {"base", "main"}),
+ (True, [], {"main"}),
+ (False, True, {"base"}),
+ (False, False, set()),
+ (False, ["base"], {"base"}),
+ (False, [], set()),
+ ([], True, {"base"}),
+ ([], False, set()),
+ ([], ["base"], {"base"}),
+ ([], [], set()),
+ (None, True, {"base", "main"}),
+ (None, False, {"main"}),
+ (None, ["base"], {"base", "main"}),
+ (None, [], {"main"}),
+ (["base"], True, {"base"}),
+ (["base"], False, set()),
+ (["base"], ["base"], {"base"}),
+ (["base"], [], set()),
+ (["main"], True, {"main"}),
+ (["main"], False, {"main"}),
+ (["main"], ["base"], {"base", "main"}),
+ (["main"], [], {"main"}),
+ ],
+)
+def test_filter_inherited_members(
+ members: bool | list[str] | None,
+ inherited_members: bool | list[str],
+ expected_names: list[str],
+) -> None:
+ """Test inherited members filtering.
+
+ Parameters:
+ members: Members option (parametrized).
+ inherited_members: Inherited members option (parametrized).
+ expected_names: The expected result as a list of member names.
+ """
+ collection = ModulesCollection()
+ with temporary_visited_module(
+ """
+ class Base:
+ def base(self): ...
+
+ class Main(Base):
+ def main(self): ...
+ """,
+ modules_collection=collection,
+ ) as module:
+ collection["module"] = module
+ objects = module["Main"].all_members
+ filtered = rendering.do_filter_objects(objects, members_list=members, inherited_members=inherited_members)
+ names = {obj.name for obj in filtered}
+ assert names == expected_names
| | | | | | | |