Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add partial Simplified Chinese support to MkDocs static i18n documentation #298

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions docs/getting-started/installation.zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# 安装

将 `mkdocs-static-i18n` 添加到你的 `pyproject.toml` 或 `requirements.txt` 文件中,或者直接使用 `pip` 安装。 该插件会自动寻找并安装与 `mkdocs` 兼容的版本。

```bash
$ pip install mkdocs-static-i18n
```

*如果您担心会出现破坏性的更改,建议您锁定插件的版本。*.

如果你在使用 mkdocs-material,也可以选择将该插件与其兼容的最小版本 `mkdocs-material` 一起安装,就像这样:

```bash
$ pip install mkdocs-static-i18n[material]
```
2 changes: 1 addition & 1 deletion docs/getting-started/quick-start.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Quick Start

!!! warning
This documentation applies from `mkdocs-static-i18n` **version 1.0.0**.
This documentation applies from `mkdocs-static-i18n` **above version 1.0.0**.
Users of older versions should check the [previous version 0.56 documentation](https://github.com/ultrabug/mkdocs-static-i18n/tree/0.56#readme).

After you [installed](installation.md) the plugin there are a few steps to get started.
Expand Down
117 changes: 117 additions & 0 deletions docs/getting-started/quick-start.zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# 快速开始

!!! Warning
本文档适用于 `mkdocs-static-i18n` **1.0.0 版本及以上**。
如果你在使用0.56或更旧的版本请看[这份文档](https://github.com/ultrabug/mkdocs-static-i18n/tree/0.56#readme).


当[安装](installation.md)完插件后按照以下步骤开始。

## 选择您的本地化文档架构

该插件允许您选择如何管理你的本地化页面文档。


- 使用 `suffix` 文档结构 (默认), 你可以在你的文件后面加后缀 `.<language>.<extension>` (类似 `index.zh.md`)。
- 使用 `folder` 文档结构, 你将为你的每一种语言的文档创建一个文件夹 (类似 `zh/` 和 `en/` 等),并将您的本地化页面放在这些文件夹里面。

以下是两种结构的示例,您可以自行决定选择哪一种,构建输出的结果一致。

### 后缀文件结构 (默认)

```
./docs_suffix_structure
├── assets
│   └── image_non_localized.png
├── image.en.png
├── image.zh.png
├── index.zh.md
├── index.en.md
├── topic1
│   ├── index.en.md
│   └── index.zh.md
└── topic2
│   ├── index.en.md
│   └── index.zh.md
```

### 文件夹文件结构

```
./docs_folder_structure
├── assets
│   └── image_non_localized.png
├── en
│   ├── image.png
│   ├── index.md
│   ├── topic1
│   │   └── index.md
│   └── topic2
│   └── index.md
└── zh
├── image.png
├── index.md
├── topic1
│   └── index.md
└── topic2
└── index.md
```

## 在您的mkdocs.yml文件中配置该插件

一旦您选择使用哪种结构(这里我们选择`suffix`结构),就可以添加插件并进行最低要求的配置,以支持您所期望的语言,同时**选择默认语言**。

不要担心缺少非默认语言 (此处为`zh`) 的页面: 默认情况下,它们将使用默认版本 (`en`) (您可以使用`fallback_to_default`选项配置)。

```yaml
plugins:
- i18n:
docs_structure: suffix
languages:
- locale: en
default: true
name: English
build: true
- locale: zh
name: zhançais
build: true
```

## 构建和测试您本地化后的网站

恭喜,您已经可以看到您的本地化网站,因为该插件将为每种语言生成一个URL路径:

- 使用默认 (`en`) 语言URL会显示根目录 `/` 。
- 本地化后的 (`zh`) 汉语路径URL会显示为 `/zh/` 中。

```bash
$ mkdocs serve
```
该插件将生成如下的网站结构:

```
site
├── 404.html
├── assets
│   ├── image_non_localized.png

[...]

├── zh
│   ├── image.png
│   ├── index.html
│   ├── topic1
│   │   └── index.html
│   └── topic2
│   └── index.html
├── image.png
├── index.html
├── search
│   └── search_index.json
├── sitemap.xml
├── sitemap.xml.gz
├── topic1
│   └── index.html
└── topic2
└── index.html
```
6 changes: 6 additions & 0 deletions docs/index.zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
template: home.zh.html
title: MkDocs static i18n plugin
---

# MkDocs static i18n plugin
47 changes: 47 additions & 0 deletions docs/overrides/home.zh.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{% extends "main.html" %}
{% block tabs %}
{{ super() }}
<style>
.md-header{position:initial}
.md-main__inner{margin:0}
.md-content{display:none}
.mdx-hero{
padding-left: 0.6rem;
padding-right: 0.6rem;
}
@media screen and (min-width: 60em) {
.md-sidebar--primary{display:none}
.md-sidebar--secondary{display:none}
.md-sidebar--secondary:not([hidden]){display:none}
}
@media screen and (min-width:76.25em){
.md-sidebar--primary{display:none}
.md-sidebar--secondary{display:none}
.md-sidebar--secondary:not([hidden]){display:none}
}
</style>
<section class="mdx-container">
<div class="md-grid md-typeset">
<div class="mdx-hero">
<div class="mdx-hero__image">
<img src="../assets/logo_by_maxicons.png" alt="" draggable="false">
</div>
<div class="mdx-hero__content">
<h1>让MkDocs本地化变得更简单</h1>
<p>通过 <code>mkdocs-static-i18n</code> 插件, 您可以在现有文档页面中添加静态翻译文件,从而支持<b>多语言文档</b>。</p>
<p>MkDocs static i18n插件尽可能地简单易用,它会生成网站的默认语言版本 + 其他语言的版本,每个版本对应一种配置语言,对应语言的版本将放置在<code>&lt;language&gt;/</code>路径下。</p>
<p>更棒的是,<code>mkdocs-static-i18n</code>还允许您构建和提供<b>任何文件的本地化版本</b>,以显示多语言版本的图片、媒体和资源,并支持自动回退到默认语言的页面和资源。</p>
<p style="margin: 0 0 2.25em"><b>注重于翻译本身</b>,而不是花费太多精力和时间去更新与每种本地化语言相关的资源和链接。</p>
<a href="{{ 'zh/getting-started/quick-start' | url }}" title="Quick Start" class="md-button md-button--primary">
快速开始
</a>
<a href="{{ 'zh/setup/' | url }}" title="" class="md-button">
配置选项
</a>
</div>
</div>
</div>
</section>
{% endblock %}
{% block content %}{% endblock %}
{% block footer %}{% endblock %}
13 changes: 13 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,16 @@ plugins:
Home: Accueil
Getting Started: Démarrage Rapide
Plugins Compatibility: Compatibilité des plugins
- locale: zh
name: 汉语
build: true
site_name: "MkDocs static i18n 插件文档 (汉语)"
theme:
palette:
primary: teal
nav_translations:
Home: 首页
Getting Started: 快速开始
Configuration: 配置选项
Plugins Compatibility: 插件兼容性
Changelog: 更新日志