Skip to content

Commit 4494d4e

Browse files
feat: prefer language, add docs
1 parent 03e53e3 commit 4494d4e

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

docs/usage/index.md

+12
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ with the `handler` option:
5858
handler: python
5959
```
6060

61+
## Internationalization (i18n)
62+
63+
The Python handler of *mkdocstrings* supports changing the output language.
64+
65+
The following languages can be used by enabling in [mkdocstrings configuration](https://mkdocstrings.github.io/usage/#internationalization-i18n):
66+
67+
Currently supported languages:
68+
69+
- :flag_us: `en`: English (default)
70+
- :flag_cn: `zh`: Chinese (Simplified)
71+
- :flag_jp: `ja`: Japanese
72+
6173
## Configuration
6274

6375
When installed, the Python handler becomes the default *mkdocstrings* handler.

src/mkdocstrings_handlers/python/handler.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def __init__(
189189
*args: Any,
190190
config_file_path: str | None = None,
191191
paths: list[str] | None = None,
192-
locale: str = "en",
192+
language: str = "en",
193193
load_external_modules: bool = False,
194194
**kwargs: Any,
195195
) -> None:
@@ -199,7 +199,7 @@ def __init__(
199199
*args: Handler name, theme and custom templates.
200200
config_file_path: The MkDocs configuration file path.
201201
paths: A list of paths to use as Griffe search paths.
202-
locale: The locale to use when rendering content.
202+
language: The language to use when rendering content.
203203
load_external_modules: Load external modules when resolving aliases.
204204
**kwargs: Same thing, but with keyword arguments.
205205
"""
@@ -222,7 +222,7 @@ def __init__(
222222
self._paths = search_paths
223223
self._modules_collection: ModulesCollection = ModulesCollection()
224224
self._lines_collection: LinesCollection = LinesCollection()
225-
self._locale = locale
225+
self._language = language
226226

227227
@classmethod
228228
def load_inventory(
@@ -357,8 +357,8 @@ def render(self, data: CollectorItem, config: Mapping[str, Any]) -> str: # noqa
357357
"config": final_config,
358358
data.kind.value: data,
359359
"heading_level": heading_level,
360+
"language": self._language,
360361
"root": True,
361-
"locale": self._locale,
362362
},
363363
)
364364

@@ -431,7 +431,7 @@ def get_handler(
431431
custom_templates: str | None = None,
432432
config_file_path: str | None = None,
433433
paths: list[str] | None = None,
434-
locale: str = "en",
434+
language: str = "en",
435435
load_external_modules: bool = False,
436436
**config: Any, # noqa: ARG001
437437
) -> PythonHandler:
@@ -442,7 +442,7 @@ def get_handler(
442442
custom_templates: Directory containing custom templates.
443443
config_file_path: The MkDocs configuration file path.
444444
paths: A list of paths to use as Griffe search paths.
445-
locale: The locale to use when rendering content.
445+
language: The language to use when rendering content.
446446
load_external_modules: Load external modules when resolving aliases.
447447
**config: Configuration passed to the handler.
448448
@@ -455,6 +455,6 @@ def get_handler(
455455
custom_templates=custom_templates,
456456
config_file_path=config_file_path,
457457
paths=paths,
458-
locale=locale,
458+
language=language,
459459
load_external_modules=load_external_modules,
460460
)

src/mkdocstrings_handlers/python/templates/material/language.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!-- Import translations for given language and fallback -->
2-
{% set lang_pth = "languages/" ~ locale ~ ".html" %}
2+
{% set lang_pth = "languages/" ~ language ~ ".html" %}
33
{% if lang_pth is existing_template %}
44
{% import lang_pth as lang %}
55
{% import "languages/en.html" as fallback %}

0 commit comments

Comments
 (0)