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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ walrus
examples/CONFIG/bin/walrus
./client_config.yaml
examples/CONFIG/config_dir/client_config.yaml

book/
po/*.po~
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,19 @@ 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 version
lispking marked this conversation as resolved.
Show resolved Hide resolved

If there is a translated resource in `po/` directory, it can be specified through `MDBOOK_BOOK__LANGUAGE` like below:

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

## Get help and report issues

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

## Translation workflow

### Preparation

RBE uses [mdbook-i18n-helpers](https://github.com/google/mdbook-i18n-helpers) as a translation framework.
lispking marked this conversation as resolved.
Show resolved Hide resolved
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](https://github.com/google/mdbook-i18n-helpers/blob/main/i18n-helpers/USAGE.md) file for the detailed usage of mdbook-i18n-helpers.
The summarized command list is below:

#### Generating a message template

The generated message templete `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

`xx` is [ISO 639](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) language code.

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

#### Updating the 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
```
6 changes: 5 additions & 1 deletion book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ src = "docs"
title = "Walrus"

[build]
build-dir = "build"
# build-dir = "build"
lispking marked this conversation as resolved.
Show resolved Hide resolved
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