Skip to content

Commit

Permalink
Sync src/ with date in PO file when publishing (#1243)
Browse files Browse the repository at this point in the history
Before, we always used the latest English source files when
publishing. This means that translations become outdated as soon as
anything is changed in the source.

This PR changes will instead freeze translations in place: they will
keep using the same English source files until a new POT file is
merged into the translation. We do this by relying on the
POT-Creation-Date field in the PO files.

We still use up-to-date versions of all other files: this allows us to
fix things in the theme, for example. So the assumption here is that
never versions of our infrastructure remains compatible with old
versions of the Markdown files.

This approach has a problem: when files are moved, the English
translation will link to the new name. This name will not exist in the
old translations. We might be able to disable these links somehow.

Part of google/mdbook-i18n-helpers#16. The
logic here should eventually be moved to somewhere in
mdbook-i18n-helpers, most likely to the renderer that @sakex is
building in google/mdbook-i18n-helpers#84.
  • Loading branch information
goldenpath1109 authored and DannyRavi committed Sep 25, 2023
1 parent fff8f5c commit 5183639
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
with:
# We need the full history below.
fetch-depth: 0

- name: Setup Rust cache
uses: ./.github/workflows/setup-rust-cache
Expand All @@ -46,9 +49,20 @@ jobs:
- name: Build all translations
run: |
for po_lang in ${{ env.LANGUAGES }}; do
echo "::group::Building $po_lang translation"
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=/comprehensive-rust/$po_lang/ \
MDBOOK_OUTPUT__HTML__REDIRECT='{}' \
mdbook build -d book/$po_lang
(cd book/$po_lang/exerciser && zip --recurse-paths ../html/comprehensive-rust-exercises.zip comprehensive-rust-exercises/)
mv book/$po_lang/html book/html/$po_lang
Expand Down

0 comments on commit 5183639

Please sign in to comment.