From 9ed4c1abb147d59f77ad34b5d345d8ec1800c0f6 Mon Sep 17 00:00:00 2001 From: snowy Date: Wed, 21 Aug 2024 18:05:04 +0800 Subject: [PATCH] =?UTF-8?q?:memo:=20=E6=96=87=E6=A1=A3=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E6=BA=90=E4=BB=A3=E7=A0=81=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- liteyuki/mkdoc.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/liteyuki/mkdoc.py b/liteyuki/mkdoc.py index fb179473..7463eca2 100644 --- a/liteyuki/mkdoc.py +++ b/liteyuki/mkdoc.py @@ -209,13 +209,14 @@ def get_module_info_normal(file_path: str, ignore_private: bool = True) -> Modul return module_info -def generate_markdown(module_info: ModuleInfo, front_matter=None) -> str: +def generate_markdown(module_info: ModuleInfo, front_matter=None, lang: str = "zh-CN") -> str: """ 生成模块的Markdown 你可在此自定义生成的Markdown格式 Args: module_info: 模块信息 front_matter: 自定义选项title, index, icon, category + lang: 语言 Returns: Markdown 字符串 """ @@ -261,7 +262,13 @@ def generate_markdown(module_info: ModuleInfo, front_matter=None) -> str: method.docstring = method.docstring.replace("\n", "\n\n") content += f" {method.docstring}\n\n" # 函数源代码可展开区域 - content += f"
\n源代码\n\n```python\n{method.source_code}\n```\n
\n\n" + + if lang == "zh-CN": + TEXT_SOURCE_CODE = "源代码" + else: + TEXT_SOURCE_CODE = "Source Code" + + content += f"
\n{TEXT_SOURCE_CODE}\n\n```python\n{method.source_code}\n```\n
\n\n" for attr in cls.attributes: content += f"###   ***attr*** `{attr.name}: {attr.type}`\n\n" @@ -278,7 +285,7 @@ def generate_markdown(module_info: ModuleInfo, front_matter=None) -> str: return content -def generate_docs(module_folder: str, output_dir: str, with_top: bool = False, ignored_paths=None): +def generate_docs(module_folder: str, output_dir: str, with_top: bool = False, lang: str = "zh-CN", ignored_paths=None): """ 生成文档 Args: @@ -286,6 +293,7 @@ def generate_docs(module_folder: str, output_dir: str, with_top: bool = False, i output_dir: 输出文件夹 with_top: 是否包含顶层文件夹 False时例如docs/api/module_a, docs/api/module_b, True时例如docs/api/module/module_a.md, docs/api/module/module_b.md ignored_paths: 忽略的路径 + lang: 语言 """ if ignored_paths is None: ignored_paths = [] @@ -345,5 +353,5 @@ def generate_docs(module_folder: str, output_dir: str, with_top: bool = False, i # 入口脚本 if __name__ == '__main__': # 这里填入你的模块路径 - generate_docs('liteyuki', 'docs/dev/api', with_top=False, ignored_paths=["liteyuki/plugins"]) - generate_docs('liteyuki', 'docs/en/dev/api', with_top=False, ignored_paths=["liteyuki/plugins"]) + generate_docs('liteyuki', 'docs/dev/api', with_top=False, ignored_paths=["liteyuki/plugins"], lang="zh-CN") + generate_docs('liteyuki', 'docs/en/dev/api', with_top=False, ignored_paths=["liteyuki/plugins"], lang="en")