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

feat: support zh_CN translate #154

Merged
merged 15 commits into from
Oct 31, 2024
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ indent_size = 2
max_line_length = 150

# Ignore paths
[{.git/**/*,LICENSE,**/Move.lock,mdbook-admonish.css,theme/**/*}]
[{.git/**/*,LICENSE,**/Move.lock,mdbook-admonish.css,theme/**/*,po/*}]
charset = unset
end_of_line = unset
indent_size = unset
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ __pycache__/
config.yml
working_dir
*.log
*~

# Walrus binary and configuration
walrus
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,24 @@ You can also build and access the documentation locally (assuming you have Rust
cargo install mdbook
cargo install [email protected] --locked
cargo install [email protected] --locked
cargo install mdbook-i18n-helpers --locked
mdbook serve
```

### Using translated versions

If there is a translated resource in `po/` directory, it can be specified through the
`MDBOOK_BOOK__LANGUAGE` environment variable. For example, to build or serve the Chinese
translation:

```bash
MDBOOK_BOOK__LANGUAGE=zh_CN mdbook build
MDBOOK_BOOK__LANGUAGE=zh_CN mdbook serve
```

Please consult [TRANSLATING.md](./TRANSLATING.md) for further information on how to create and
maintain translations.

## Get help and report issues

If you have general questions or require help on how to use Walrus, please check for [existing
Expand Down
52 changes: 52 additions & 0 deletions TRANSLATING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Translation Guidelines

The Walrus documentation uses [mdbook-i18n-helpers] as a translation framework.

## Preparation

The following tools are required:

- GNU gettext utilities (`msgmerge` and `msgcat`)
- mdbook-i18n-helpers (`cargo install mdbook-i18n-helpers`)

## Creating and updating translations

Please see the [mdbook-i18n-helpers USAGE] file for the detailed usage of mdbook-i18n-helpers.
We summarize the most important commands below.

### Generating a message template

The generated message template `po/messages.pot` is required to create or update translations.

```bash
MDBOOK_OUTPUT='{"xgettext": {"pot-file": "messages.pot"}}' mdbook build -d po
```

### Creating a new translation resource

In the following, replace `xx` by the [ISO 639][iso_639] language code.

```bash
msginit -i po/messages.pot -l xx -o po/xx.po
```

### Updating an existing translation resource

```bash
msgmerge --update po/xx.po po/messages.pot
```

## Editing translation resources

After generating a translation resource `po/xx.po`, you can write translation messages
in `msgstr` entry of `po/xx.po`.
To build a translated book, the following command can be used.

```bash
MDBOOK_BOOK__LANGUAGE=xx mdbook build
MDBOOK_BOOK__LANGUAGE=xx mdbook serve
```

[mdbook-i18n-helpers]: https://github.com/google/mdbook-i18n-helpers
[mdbook-i18n-helpers USAGE]: https://github.com/google/mdbook-i18n-helpers/blob/main/i18n-helpers
[iso_639]: https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
4 changes: 4 additions & 0 deletions book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ title = "Walrus"

[build]
build-dir = "build"
extra-watch-dirs = ["po"]

[output.html]
theme = "theme"
Expand Down Expand Up @@ -34,3 +35,6 @@ assets_version = "3.0.2" # do not edit: managed by `mdbook-admonish install`
# Using `\(` and `\)` for inline math and `\[` and `\]` for math blocks.
block-delimiter = { left = "\\[", right = "\\]" }
inline-delimiter = { left = "\\(", right = "\\)" }

[preprocessor.gettext]
after = ["links"]
Loading
Loading