Skip to content

Commit

Permalink
Add i18n support
Browse files Browse the repository at this point in the history
  • Loading branch information
dalance committed Oct 26, 2023
1 parent 6709bee commit 72a6860
Show file tree
Hide file tree
Showing 5 changed files with 445 additions and 2 deletions.
35 changes: 34 additions & 1 deletion .github/workflows/rbe.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
name: CI
on: [push, pull_request]

env:
# Update the language picker in index.hbs to link new languages.
LANGUAGES:

jobs:
test:
name: Run tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v4
with:
# We need the full history below.
fetch-depth: 0

- name: Update rustup
run: rustup self update
Expand All @@ -23,6 +30,10 @@ jobs:
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
echo "$(pwd)/bin" >> ${GITHUB_PATH}
- name: Install mdbook-i18n-helpers
run: |
cargo install --git https://github.com/google/mdbook-i18n-helpers mdbook-i18n-helpers
- name: Report versions
run: |
rustup --version
Expand All @@ -41,6 +52,28 @@ jobs:
https://raw.githubusercontent.com/rust-lang/rust/master/src/tools/linkchecker/linkcheck.sh
sh linkcheck.sh --all rust-by-example
- name: Build all translations
run: |
for po_lang in ${{ env.LANGUAGES }}; do
POT_CREATION_DATE=$(grep --max-count 1 '^"POT-Creation-Date:' po/$po_lang.po | sed -E 's/".*: (.*)\\n"/\1/')
if [[ $POT_CREATION_DATE == "" ]]; then
POT_CREATION_DATE=now
fi
echo "::group::Building $po_lang translation as of $POT_CREATION_DATE"
rm -r src/
git restore --source "$(git rev-list -n 1 --before "$POT_CREATION_DATE" @)" src/
# Set language and adjust site URL. Clear the redirects
# since they are in sync with the source files, not the
# translation.
MDBOOK_BOOK__LANGUAGE=$po_lang \
MDBOOK_OUTPUT__HTML__SITE_URL=/rust-by-example/$po_lang/ \
MDBOOK_OUTPUT__HTML__REDIRECT='{}' \
mdbook build -d book/$po_lang
echo "::endgroup::"
done
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
book

po/messages.pot

# Auto-generated files from macOS
.DS_Store
.DS_Store
9 changes: 9 additions & 0 deletions book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ enable = true

[output.html]
git-repository-url = "https://github.com/rust-lang/rust-by-example"
additional-css = [
"theme/css/language-picker.css",
]

[rust]
edition = "2021"

[build]
extra-watch-dirs = ["po"]

[preprocessor.gettext]
after = ["links"]
13 changes: 13 additions & 0 deletions theme/css/language-picker.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#language-list {
left: auto;
right: 10px;
}

[dir="rtl"] #language-list {
left: 10px;
right: auto;
}

#language-list a {
color: inherit;
}
Loading

0 comments on commit 72a6860

Please sign in to comment.