Skip to content

Commit ad9b41c

Browse files
authored
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.
1 parent 95eb00b commit ad9b41c

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ target/
44
*.bin
55

66
# Translation artifacts
7-
po/messages.pot
87
po/*.mo
98
po/*.po~
109

TRANSLATIONS.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,37 +39,38 @@ need the `msgmerge` and `msgcat` Gettext tool installed. Please see our
3939

4040
First, you need to know how to update the `.pot` and `.po` files.
4141

42-
You should never touch the auto-generated `po/messages.pot` file. You should
43-
also not never the `msgid` entries in a `po/xx.po` file. If you find mistakes,
44-
you need to update the original English text instead. The fixes to the English
45-
text will flow into the `.po` files the next time the translators update them.
42+
You should never touch the auto-generated `book/xgettext/messages.pot` file. You
43+
should also not never the `msgid` entries in a `po/xx.po` file. If you find
44+
mistakes, you need to update the original English text instead. The fixes to the
45+
English text will flow into the `.po` files the next time the translators update
46+
them.
4647

4748
> **Tip:** See our [style guide](STYLE.md) for some things to keep in mind when
4849
> writing the translation.
4950
5051
### Generating the PO Template
5152

52-
To extract the original English text and generate a `messages.pot` file, you run
53-
`mdbook` with a special renderer:
53+
To extract the original English text and generate a `messages.pot` file, you
54+
build the book. This will automatically invoke the `mdbook-xgettext` renderer:
5455

5556
```shell
56-
MDBOOK_OUTPUT='{"xgettext": {"pot-file": "messages.pot", "granularity": 0}}' \
57-
mdbook build -d po
57+
mdbook build
5858
```
5959

60-
You will find the generated POT file as `po/messages.pot`.
60+
You will find the generated POT file as `book/xgettext/messages.pot`.
6161

6262
### Initialize a New Translation
6363

64-
To start a new translation, first generate the `po/messages.pot` file. Then use
65-
`msginit` to create a `xx.po` file for the fictional `xx` language:
64+
To start a new translation, first generate the `book/xgettext/messages.pot`
65+
file. Then use `msginit` to create a `xx.po` file for the fictional `xx`
66+
language:
6667

6768
```shell
68-
msginit -i po/messages.pot -l xx -o po/xx.po
69+
msginit -i book/xgettext/messages.pot -l xx -o po/xx.po
6970
```
7071

71-
You can also simply copy `po/messages.pot` to `po/xx.po`. Then update the file
72-
header (the first entry with `msgid ""`) to the correct language.
72+
You can also simply copy `book/xgettext/messages.pot` to `po/xx.po`. Then update
73+
the file header (the first entry with `msgid ""`) to the correct language.
7374

7475
> **Tip:** You can use the
7576
> [`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
9899
last updated with new English messages.
99100

100101
To update the `po/xx.po` file with new messages, first extract the English text
101-
into a `po/messages.pot` template file. Then run
102+
into a `book/xgettext/messages.pot` template file. Then run
102103

103104
```shell
104-
msgmerge --update po/xx.po po/messages.pot
105+
msgmerge --update po/xx.po book/xgettext/messages.pot
105106
```
106107

107108
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:
162163
MDBOOK_BOOK__LANGUAGE=xx mdbook build -d book/xx
163164
```
164165

165-
This will update the book's language to `xx`, it will make the `mdbook-gettext`
166-
preprocessor become active and tell it to use the `po/xx.po` file, and finally
167-
it will redirect the output to `book/xx`.
166+
This will tell the `mdbook-gettext` preprocessor to translate the book using the
167+
`po/xx.po` file. The HTML output can be found in `book/xx/html/`.
168168

169169
### Serving a Translation
170170

book.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ class = "bob"
2222
[preprocessor.course]
2323
verbose = false # Report timing information.
2424

25+
[output.xgettext]
26+
optional = true
27+
pot-file = "messages.pot"
28+
granularity = 0
29+
2530
[output.pandoc]
2631
optional = true
2732
disabled = true

0 commit comments

Comments
 (0)