|
| 1 | +# Rust by Example translation guidelines |
| 2 | + |
| 3 | +Please see the [CONTRIBUTING.md] file for general contribution guidelines. |
| 4 | +This file describes about the translation workflow. |
| 5 | + |
| 6 | +[CONTRIBUTING.md]: https://github.com/rust-lang/rust-by-example/blob/master/CONTRIBUTING.md |
| 7 | + |
| 8 | +## Translation workflow |
| 9 | + |
| 10 | +### Preparation |
| 11 | + |
| 12 | +RBE uses [mdbook-i18n-helpers](https://github.com/google/mdbook-i18n-helpers) as a translation framework. |
| 13 | +The following tools are required. |
| 14 | + |
| 15 | +* GNU gettext utilities ( `msgmerge` and `msgcat` ) |
| 16 | +* mdbook-i18n-helpers ( `cargo install mdbook-i18n-helpers` ) |
| 17 | + |
| 18 | +### Creating and Updating Translations |
| 19 | + |
| 20 | +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. |
| 21 | +The summarized command list is below: |
| 22 | + |
| 23 | +#### Generating a message template |
| 24 | + |
| 25 | +The generated message templete `po/messages.pot` is required to create or update translations. |
| 26 | + |
| 27 | +```bash |
| 28 | +MDBOOK_OUTPUT='{"xgettext": {"pot-file": "messages.pot"}}' \ |
| 29 | + mdbook build -d po |
| 30 | +``` |
| 31 | + |
| 32 | +#### Creating a new translation resource |
| 33 | + |
| 34 | +`xx` is [ISO 639](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) language code. |
| 35 | + |
| 36 | +```bash |
| 37 | +msginit -i po/messages.pot -l xx -o po/xx.po |
| 38 | +``` |
| 39 | + |
| 40 | +#### Updating the exising translation resource |
| 41 | + |
| 42 | +```bash |
| 43 | +msgmerge --update po/xx.po po/messages.pot |
| 44 | +``` |
| 45 | + |
| 46 | +### Editing translation resources |
| 47 | + |
| 48 | +After generating a translation resource `po/xx.po`, you can write translation messages in `msgstr` entry of `po/xx.po`. |
| 49 | +To build a translated book, the following command can be used. |
| 50 | + |
| 51 | +```bash |
| 52 | +MDBOOK_BOOK__LANGUAGE=xx mdbook build |
| 53 | +MDBOOK_BOOK__LANGUAGE=xx mdbook serve |
| 54 | +``` |
| 55 | + |
| 56 | +### Add a language entry |
| 57 | + |
| 58 | +Please add a language entry in `.github/workflows/rbe.yml` and `theme/index.hbs` like below: |
| 59 | + |
| 60 | +* `rbe.yml` |
| 61 | + |
| 62 | +```yml |
| 63 | +env: |
| 64 | + # Update the language picker in index.hbs to link new languages. |
| 65 | + LANGUAGES: xx yy zz |
| 66 | +``` |
| 67 | +
|
| 68 | +* `index.hbs` |
| 69 | + |
| 70 | +```html |
| 71 | +<ul id="language-list" class="theme-popup" aria-label="Languages" role="menu"> |
| 72 | + <li role="none"><button role="menuitem" class="theme"> |
| 73 | + <a id="en">English</a> |
| 74 | + </button></li> |
| 75 | + <li role="none"><button role="menuitem" class="theme"> |
| 76 | + <a id="xx">XX language</a> |
| 77 | + </button></li> |
| 78 | + <li role="none"><button role="menuitem" class="theme"> |
| 79 | + <a id="yy">YY language</a> |
| 80 | + </button></li> |
| 81 | + <li role="none"><button role="menuitem" class="theme"> |
| 82 | + <a id="zz">ZZ language</a> |
| 83 | + </button></li> |
| 84 | +</ul> |
| 85 | +``` |
0 commit comments