Skip to content

Commit

Permalink
📝 自举生成文档(bushi)
Browse files Browse the repository at this point in the history
  • Loading branch information
snowykami committed Aug 29, 2024
1 parent 89afbcf commit c0417fd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 90 deletions.
60 changes: 7 additions & 53 deletions docs/api/i18n.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,10 @@ title: litedoc.i18n

**Description**: Flatten i18n_dict.

**Examples**:
- ```python
> **docs.input**:
> **docs.output**:
- {
> **docs.input**:
> **docs.output**:
- "en"
> **docs.input**: {
> **docs.output**:
- "docs"
> **docs.input**: {
> **docs.output**:
- "key1"
> **docs.input**: "val1",
> **docs.output**:
- "key2"
> **docs.input**: "val2",
> **docs.output**:
- }
> **docs.input**:
> **docs.output**:
- }
> **docs.input**:
> **docs.output**:
- }
> **docs.input**:
> **docs.output**:
- ```
> **docs.input**:
> **docs.output**:
**Arguments**:
> - data: i18n_dict
**Return**: dict: flatten dict


<details>
Expand All @@ -47,29 +20,10 @@ title: litedoc.i18n
def flat_i18n_dict(data: dict[str, NestedDict]) -> dict[str, dict[str, str]]:
"""
Flatten i18n_dict.
Examples:
```python
{
"en": {
"docs": {
"key1": "val1",
"key2": "val2",
}
}
}
```
to
```python
{
"en": {
"docs.key1": "val1",
"docs.key2": "val2",
}
}
```
Args:
data: i18n_dict
Returns:
dict: flatten dict
"""
ret: dict[str, dict[str, str]] = {}

Expand Down
1 change: 1 addition & 0 deletions docs/api/style/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def generate(parser: AstParser, lang: str, frontmatter: Optional[dict]=None, sty
'遍历变量'
for var in parser.variables:
if var.docs is not None and litedoc_hide not in var.docs:
print(var.docs)
md += f'### ***var*** `{var.name} = {var.value}`\n\n'
if var.type != TypeHint.NO_TYPEHINT:
md += f"- **{get_text(lang, 'type')}**: `{var.type}`\n\n"
Expand Down
55 changes: 18 additions & 37 deletions litedoc/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

NestedDict: TypeAlias = dict[str, 'str | NestedDict']

i18n_dict: dict[str, NestedDict] = {
"""@litedoc-hide"""
i18n_dict: dict[str, NestedDict] = { # @litedoc-hide
"en" : {
"docstring": {
"args" : "Arguments",
Expand All @@ -16,9 +17,9 @@
"example" : "Examples",
"yields" : "Yields",
},
"src": "Source code",
"desc": "Description",
"type": "Type",
"src" : "Source code",
"desc" : "Description",
"type" : "Type",
},
"zh-Hans": {
"docstring": {
Expand All @@ -29,9 +30,9 @@
"example" : "示例",
"yields" : "产出",
},
"src": "源代码",
"desc": "说明",
"type": "类型",
"src" : "源代码",
"desc" : "说明",
"type" : "类型",
},
"zh-Hant": {
"docstring": {
Expand All @@ -42,9 +43,9 @@
"example" : "範例",
"yields" : "產出",
},
"src": "源碼",
"desc": "説明",
"type": "類型",
"src" : "源碼",
"desc" : "説明",
"type" : "類型",
},
"ja" : {
"docstring": {
Expand All @@ -55,40 +56,20 @@
"example" : "例",
"yields" : "生成",
},
"src": "ソースコード",
"desc": "説明",
"type": "タイプ",
"src" : "ソースコード",
"desc" : "説明",
"type" : "タイプ",
},
}
"""@litedoc-hide"""
} # @litedoc-hide


def flat_i18n_dict(data: dict[str, NestedDict]) -> dict[str, dict[str, str]]:
"""
Flatten i18n_dict.
Examples:
```python
{
"en": {
"docs": {
"key1": "val1",
"key2": "val2",
}
}
}
```
to
```python
{
"en": {
"docs.key1": "val1",
"docs.key2": "val2",
}
}
```
Args:
data: i18n_dict
Returns:
dict: flatten dict
"""
ret: dict[str, dict[str, str]] = {}

Expand Down

0 comments on commit c0417fd

Please sign in to comment.