Skip to content

Commit

Permalink
update add doc "more"
Browse files Browse the repository at this point in the history
  • Loading branch information
Neutree committed Feb 3, 2023
1 parent c65b3db commit 8984f23
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 27 deletions.
45 changes: 31 additions & 14 deletions docs/get_started/en/usage/i18n.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,33 +51,48 @@ If you need manual translation, you need to configure the `translate` keyword in
```json
"route": {
"docs": {
"/get_started/zh/": "docs/get_started/zh",
"/develop/zh/": "docs/develop/zh",
"/more/": "docs/more"
}
},
"translate": {
"docs": {
"/more/": [ {
"url": "/more/en/",
"src": "docs/more/en"
}
]
}
},
```

This configuration means that the `html` files of the documents under the `docs/more` directory will be generated in the `out/more/` directory (that is, the `url` [/more/](/more/));
The English source file is in the `docs/more/en` directory, and the generated web page `url` is in [/more/en/](/more/en/).
The advantage of this is that the translated documents can use relative paths to reference the resource files of the main documents, such as `../assets/`, whether it is a local editor preview or the final generated web page can be previewed normally. Don't worry about the path problem.

On the other hand, you may want to put the Chinese and English translations separately, such as the `docs/get_started/zh` and `docs/get_started/en` directories, and share the resource files of `docs/get_started/assets`. It will be a little more complicated, and it is no longer recommended to use it in this way:

```json
"route": {
"docs": {
"/get_started/zh/": "docs/get_started/zh"
},
"pages": {
"/": "pages/index/zh",
},
"assets": {
"/static/": "static",
"/get_started/assets/": "docs/get_started/assets"
},
"/blog/": "blog"
}
},
"translate": {
"docs": {
"/get_started/zh/": [{
"/get_started/zh/": [ {
"url": "/get_started/en/",
"src": "docs/get_started/en"
}
],
"/develop/zh/": [{
"url": "/develop/en/",
"src": "docs/develop/en"
}
]
},
"pages": {
"/": [{
"/": [ {
"url": "/en/",
"src": "pages/index/en"
}
Expand All @@ -86,8 +101,10 @@ If you need manual translation, you need to configure the `translate` keyword in
},
```

There are two documents `"/get_started/zh/"` and `"/develop/zh/"`, and the page `"/"`, both of which are Chinese documents.
Now we need to add English translations for their three documents, respectively add translations under `translate` -> `docs`, the translated documents need to specify `url` (generated path, end with `/`) and `src` (translation The root directory of the document, the end of `/` is not required)
The Doc `"/get_started/zh/"` and the page `"/"` are both Chinese documents.
Now we need to add English translations for them. Add translations under `translate` -> `docs`, and specify `url` (the generated path, which needs to end with `/`) and `src` (the root directory of the translation document, which does not need to end with `/`)

As you can see, we manually specify a resource file `"assets"` that is shared by Chinese and English documents, so that we can use relative paths `../assets` in the documents to reference the resource files, and preview them in the local editor.

Then
* Copy `config` (`config.yaml` or `config.json`) and `sidebar` (`sidebar.yaml` or `sidebar.json`) to the translation document directory. For example, here is `"docs/get_started /en"`,
Expand Down
38 changes: 27 additions & 11 deletions docs/get_started/zh/usage/i18n.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,43 @@ pybabel --list-locales
```json
"route": {
"docs": {
"/get_started/zh/": "docs/get_started/zh",
"/develop/zh/": "docs/develop/zh",
"/more/": "docs/more"
}
},
"translate": {
"docs": {
"/more/": [ {
"url": "/more/en/",
"src": "docs/more/en"
}
]
}
},
```

这样配置就是 `docs/more` 目录下的文档生成的 `html` 文件会在 `out/more/` 目录下(也就是 `url` [/more/](/more/));
英文源文件在`docs/more/en` 目录下,生成的网页页面`url`[/more/en/](/more/en/)下。
这样做的好处就是翻译文档里面可以直接使用相对路径引用主文档的资源文件,比如`../assets/`,不论是本地编辑器预览还是最终生成的网页都能正常预览图片,不用担心路径问题。

另外,你可能想将中英文翻译分开放置,比如`docs/get_started/zh``docs/get_started/en`目录,并且共用`docs/get_started/assets`的资源文件,会复杂一点,现已不建议这样使用:
```json
"route": {
"docs": {
"/get_started/zh/": "docs/get_started/zh"
},
"pages": {
"/": "pages/index/zh",
},
"assets": {
"/static/": "static",
"/get_started/assets/": "docs/get_started/assets"
},
"/blog/": "blog"
}
},
"translate": {
"docs": {
"/get_started/zh/": [ {
"url": "/get_started/en/",
"src": "docs/get_started/en"
}
],
"/develop/zh/": [ {
"url": "/develop/en/",
"src": "docs/develop/en"
}
]
},
"pages": {
Expand All @@ -86,9 +100,11 @@ pybabel --list-locales
},
```

这里有两份文档`"/get_started/zh/"``"/develop/zh/"`, 以及页面`"/"`, 都是中文文档.
这里有份文档`"/get_started/zh/"`, 以及页面`"/"`, 都是中文文档.
现在我们需要为他们三份文档添加英文翻译, 分别在`translate` -> `docs`下添加翻译, 翻译文档需要指定`url`(生成的路径, 需要`/`结尾)和`src`(翻译文档的根目录, 不需要`/`结尾)

可以看到这里手动指定了一个中英文文档共同使用的资源文件`"assets"`, 这样在文档里面都可以用相对路径`../assets`来引用资源文件了并且在本地编辑器也可以预览。

然后
*`config`(`config.yaml``config.json`) 和 `sidebar`(`sidebar.yaml``sidebar.json`) 复制一份到 翻译文档目录比如这里是`"docs/get_started/en"`
* 修改`config``locale`值为`en`, 在`navbar`添加语言选项, `type` 指定为`language`
Expand Down
9 changes: 9 additions & 0 deletions docs/more/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: 这是主要的语言文档
date: 2023-02-2
---


这是主要的语言文档,url 是 `more/`


4 changes: 4 additions & 0 deletions docs/more/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"import": "config_zh",
"name": "主要语言文档"
}
7 changes: 7 additions & 0 deletions docs/more/en/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: English translation doc
date: 2023-02-2
---

This is English translation doc, with url `more/en/`.

4 changes: 4 additions & 0 deletions docs/more/en/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"import": "config_en",
"name": "English doc"
}
3 changes: 3 additions & 0 deletions docs/more/en/sidebar.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
items:
- label: Brief
file: README.md
3 changes: 3 additions & 0 deletions docs/more/sidebar.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
items:
- label: 简介
file: README.md
10 changes: 8 additions & 2 deletions site_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"route": {
"docs": {
"/get_started/zh/": "docs/get_started/zh",
"/develop/zh/": "docs/develop/zh"
"/develop/zh/": "docs/develop/zh",
"/more/": "docs/more"
},
"pages": {
"/": "pages/index/zh"
Expand All @@ -33,7 +34,12 @@
"url": "/develop/en/",
"src": "docs/develop/en"
}
]
],
"/more/": [ {
"url": "/more/en/",
"src": "docs/more/en"
}
]
},
"pages": {
"/": [ {
Expand Down

0 comments on commit 8984f23

Please sign in to comment.