1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-04-25 08:53:01 +02:00

Include xgettext as optional output (#2244)

Instead of asking the translators to run a complicated command to
generate the `messages.pot` file, we now simply include the
configuration in the versioned `book.toml` file.

This makes it much easier for us to update the configuration: we just
push a new version of `book.toml`. It also makes life easier for the
translators.
This commit is contained in:
Martin Geisler 2024-07-23 10:51:13 +02:00 committed by GitHub
parent 95eb00be5d
commit ad9b41cd6c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 20 deletions

1
.gitignore vendored
View File

@ -4,7 +4,6 @@ target/
*.bin *.bin
# Translation artifacts # Translation artifacts
po/messages.pot
po/*.mo po/*.mo
po/*.po~ po/*.po~

View File

@ -39,37 +39,38 @@ need the `msgmerge` and `msgcat` Gettext tool installed. Please see our
First, you need to know how to update the `.pot` and `.po` files. First, you need to know how to update the `.pot` and `.po` files.
You should never touch the auto-generated `po/messages.pot` file. You should You should never touch the auto-generated `book/xgettext/messages.pot` file. You
also not never the `msgid` entries in a `po/xx.po` file. If you find mistakes, should also not never the `msgid` entries in a `po/xx.po` file. If you find
you need to update the original English text instead. The fixes to the English mistakes, you need to update the original English text instead. The fixes to the
text will flow into the `.po` files the next time the translators update them. English text will flow into the `.po` files the next time the translators update
them.
> **Tip:** See our [style guide](STYLE.md) for some things to keep in mind when > **Tip:** See our [style guide](STYLE.md) for some things to keep in mind when
> writing the translation. > writing the translation.
### Generating the PO Template ### Generating the PO Template
To extract the original English text and generate a `messages.pot` file, you run To extract the original English text and generate a `messages.pot` file, you
`mdbook` with a special renderer: build the book. This will automatically invoke the `mdbook-xgettext` renderer:
```shell ```shell
MDBOOK_OUTPUT='{"xgettext": {"pot-file": "messages.pot", "granularity": 0}}' \ mdbook build
mdbook build -d po
``` ```
You will find the generated POT file as `po/messages.pot`. You will find the generated POT file as `book/xgettext/messages.pot`.
### Initialize a New Translation ### Initialize a New Translation
To start a new translation, first generate the `po/messages.pot` file. Then use To start a new translation, first generate the `book/xgettext/messages.pot`
`msginit` to create a `xx.po` file for the fictional `xx` language: file. Then use `msginit` to create a `xx.po` file for the fictional `xx`
language:
```shell ```shell
msginit -i po/messages.pot -l xx -o po/xx.po msginit -i book/xgettext/messages.pot -l xx -o po/xx.po
``` ```
You can also simply copy `po/messages.pot` to `po/xx.po`. Then update the file You can also simply copy `book/xgettext/messages.pot` to `po/xx.po`. Then update
header (the first entry with `msgid ""`) to the correct language. the file header (the first entry with `msgid ""`) to the correct language.
> **Tip:** You can use the > **Tip:** You can use the
> [`cloud-translate`](https://github.com/mgeisler/cloud-translate) tool to > [`cloud-translate`](https://github.com/mgeisler/cloud-translate) tool to
@ -98,10 +99,10 @@ translations contain a POT-Creation-Date header which tells you when they were
last updated with new English messages. last updated with new English messages.
To update the `po/xx.po` file with new messages, first extract the English text To update the `po/xx.po` file with new messages, first extract the English text
into a `po/messages.pot` template file. Then run into a `book/xgettext/messages.pot` template file. Then run
```shell ```shell
msgmerge --update po/xx.po po/messages.pot msgmerge --update po/xx.po book/xgettext/messages.pot
``` ```
Notice that the POT-Creation-Date field is updated to the current time and date. Notice that the POT-Creation-Date field is updated to the current time and date.
@ -162,9 +163,8 @@ To use the `po/xx.po` file for your output, run the following command:
MDBOOK_BOOK__LANGUAGE=xx mdbook build -d book/xx MDBOOK_BOOK__LANGUAGE=xx mdbook build -d book/xx
``` ```
This will update the book's language to `xx`, it will make the `mdbook-gettext` This will tell the `mdbook-gettext` preprocessor to translate the book using the
preprocessor become active and tell it to use the `po/xx.po` file, and finally `po/xx.po` file. The HTML output can be found in `book/xx/html/`.
it will redirect the output to `book/xx`.
### Serving a Translation ### Serving a Translation

View File

@ -22,6 +22,11 @@ class = "bob"
[preprocessor.course] [preprocessor.course]
verbose = false # Report timing information. verbose = false # Report timing information.
[output.xgettext]
optional = true
pot-file = "messages.pot"
granularity = 0
[output.pandoc] [output.pandoc]
optional = true optional = true
disabled = true disabled = true