Skip to content

Commit 72a6860

Browse files
committed
Add i18n support
1 parent 6709bee commit 72a6860

File tree

5 files changed

+445
-2
lines changed

5 files changed

+445
-2
lines changed

.github/workflows/rbe.yml

+34-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
name: CI
22
on: [push, pull_request]
33

4+
env:
5+
# Update the language picker in index.hbs to link new languages.
6+
LANGUAGES:
7+
48
jobs:
59
test:
610
name: Run tests
711
runs-on: ubuntu-latest
812
steps:
9-
- uses: actions/checkout@master
13+
- uses: actions/checkout@v4
14+
with:
15+
# We need the full history below.
16+
fetch-depth: 0
1017

1118
- name: Update rustup
1219
run: rustup self update
@@ -23,6 +30,10 @@ jobs:
2330
curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.4.15/mdbook-v0.4.15-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=bin
2431
echo "$(pwd)/bin" >> ${GITHUB_PATH}
2532
33+
- name: Install mdbook-i18n-helpers
34+
run: |
35+
cargo install --git https://github.com/google/mdbook-i18n-helpers mdbook-i18n-helpers
36+
2637
- name: Report versions
2738
run: |
2839
rustup --version
@@ -41,6 +52,28 @@ jobs:
4152
https://raw.githubusercontent.com/rust-lang/rust/master/src/tools/linkchecker/linkcheck.sh
4253
sh linkcheck.sh --all rust-by-example
4354
55+
- name: Build all translations
56+
run: |
57+
for po_lang in ${{ env.LANGUAGES }}; do
58+
POT_CREATION_DATE=$(grep --max-count 1 '^"POT-Creation-Date:' po/$po_lang.po | sed -E 's/".*: (.*)\\n"/\1/')
59+
if [[ $POT_CREATION_DATE == "" ]]; then
60+
POT_CREATION_DATE=now
61+
fi
62+
63+
echo "::group::Building $po_lang translation as of $POT_CREATION_DATE"
64+
rm -r src/
65+
git restore --source "$(git rev-list -n 1 --before "$POT_CREATION_DATE" @)" src/
66+
67+
# Set language and adjust site URL. Clear the redirects
68+
# since they are in sync with the source files, not the
69+
# translation.
70+
MDBOOK_BOOK__LANGUAGE=$po_lang \
71+
MDBOOK_OUTPUT__HTML__SITE_URL=/rust-by-example/$po_lang/ \
72+
MDBOOK_OUTPUT__HTML__REDIRECT='{}' \
73+
mdbook build -d book/$po_lang
74+
echo "::endgroup::"
75+
done
76+
4477
- name: Upload Artifact
4578
uses: actions/upload-artifact@v3
4679
with:

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
book
22

3+
po/messages.pot
4+
35
# Auto-generated files from macOS
4-
.DS_Store
6+
.DS_Store

book.toml

+9
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ enable = true
1313

1414
[output.html]
1515
git-repository-url = "https://github.com/rust-lang/rust-by-example"
16+
additional-css = [
17+
"theme/css/language-picker.css",
18+
]
1619

1720
[rust]
1821
edition = "2021"
22+
23+
[build]
24+
extra-watch-dirs = ["po"]
25+
26+
[preprocessor.gettext]
27+
after = ["links"]

theme/css/language-picker.css

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#language-list {
2+
left: auto;
3+
right: 10px;
4+
}
5+
6+
[dir="rtl"] #language-list {
7+
left: 10px;
8+
right: auto;
9+
}
10+
11+
#language-list a {
12+
color: inherit;
13+
}

0 commit comments

Comments
 (0)