Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Make the documentation truly multilingual #160

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/actions/build-mdbook/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,12 @@ runs:
env:
RUST_LOG: INFO
shell: bash

- name: Install mdbook-i18n-helpers
run: cargo install mdbook-i18n-helpers --locked --version 0.3.5
shell: bash

- name: Install i18n-report
run: cargo install i18n-report --locked --version 0.2.0
shell: bash

26 changes: 26 additions & 0 deletions .github/workflows/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
set -Eeuo pipefail

# Usage: build.sh <book-lang> <dest-dir>
#
# Build the course as of the date specified specified in the
# POT-Creation-Date header of po/$book_lang.po. The output can be
# found in $dest_dir.
#

book_lang=${1:?"Usage: $0 <book-lang> <dest-dir>"}
dest_dir=${2:?"Usage: $0 <book-lang> <dest-dir>"}

if [ "$book_lang" = "en" ]; then
echo "::group::Building English course"
else
pot_creation_date=$(grep --max-count 1 '^"POT-Creation-Date:' "po/$book_lang.po" | sed -E 's/".*: (.*)\\n"/\1/')
pot_creation_date=${pot_creation_date:-now}
echo "::group::Building $book_lang translation as of $pot_creation_date"

export MDBOOK_BOOK__LANGUAGE=$book_lang
fi

mdbook build -d "$dest_dir"

echo "::endgroup::"
29 changes: 29 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,40 @@ jobs:
env:
# Colors don't seem to work properly with the multiline commands.
NO_COLOR: 1
# Update the language picker in index.hbs to link new languages.
LANGUAGES: zh_CN
steps:
- uses: actions/checkout@v4

- name: Install Gettext
run: |
sudo apt update
sudo apt install gettext

- uses: ./.github/actions/build-mdbook
with:
with_linkcheck: "false"

- name: Build course in English
run: .github/workflows/build.sh en build

- name: Build all translations
run: |
for po_lang in ${{ env.LANGUAGES }}; do
.github/workflows/build.sh $po_lang build/$po_lang
mv build/$po_lang/html build/html/$po_lang
done

- name: Build translation report
run: i18n-report report build/html/translation-report.html po/*.po

- name: Build synced translation report
run: |
cp -r po synced-po
MDBOOK_OUTPUT='{"xgettext": {"pot-file": "messages.pot", "granularity": 0}}' mdbook build -d synced-po
for file in synced-po/*.po; do msgmerge --update $file synced-po/messages.pot ; done
i18n-report report build/html/synced-translation-report.html synced-po/*.po

- uses: ./.github/actions/set-up-walrus
with:
SUI_ADDRESS: "${{ vars.SUI_ADDRESS }}"
Expand Down
5 changes: 4 additions & 1 deletion book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ extra-watch-dirs = ["po"]

[output.html]
theme = "theme"
additional-css = ["./mdbook-admonish.css"]
additional-css = [
"theme/css/mdbook-admonish.css",
"theme/css/language-picker.css",
]

[output.linkcheck]
optional = true
Expand Down
16 changes: 8 additions & 8 deletions po/zh_CN.po
Original file line number Diff line number Diff line change
Expand Up @@ -1743,7 +1743,7 @@ msgid ""
"The encoding is _systematic_, meaning that some storage nodes hold part of "
"the original blob, allowing for fast random-access reads."
msgstr ""
"编码是_系统化_的,这意味着一些存储节点持有原始blob的一部分,从而允许快速随机"
"编码是 _系统化_ 的,这意味着一些存储节点持有原始blob的一部分,从而允许快速随机"
"访问读取。"

#: docs/design/encoding.md:17
Expand Down Expand Up @@ -2368,7 +2368,7 @@ msgstr ""

#: docs/design/properties.md:3
msgid "Walrus assurance and security properties"
msgstr "基本架构和安全假设"
msgstr "Walrus 保证和安全属性"

#: docs/design/properties.md:5
msgid ""
Expand Down Expand Up @@ -6797,7 +6797,7 @@ msgid ""
"Assume the developer uses the SuiNS name `dapp.sui` to point to the object "
"ID of the created Walrus Site."
msgstr ""
"** 站点发布 **(步骤 0):站点开发人员使用 [`site-builder`](#the-site-"
"**站点发布**(步骤 0):站点开发人员使用 [`site-builder`](#the-site-"
"builder) 或利用发布器发布 Walrus 站点。假设开发人员使用 SuiNS 名称 `dapp."
"sui` 指向创建的 Walrus 站点的对象 ID。"

Expand All @@ -6806,7 +6806,7 @@ msgid ""
"**Browsing starts** (step 1): A client browses `dapp.walrus.site/index.html` "
"in their browser."
msgstr ""
"** 浏览开始 **(步骤 1):客户端在其浏览器中浏览 `dapp.walrus.site/index."
"**浏览开始**(步骤 1):客户端在其浏览器中浏览 `dapp.walrus.site/index."
"html`。"

#: docs/walrus-sites/overview.md:123
Expand All @@ -6816,7 +6816,7 @@ msgid ""
"service worker for `dapp.walrus.site`. The page is refreshed to activate the "
"service worker."
msgstr ""
"** 服务工作线程安装 **(步骤 2-6):浏览器连接到托管在 `walrus.site` 的门户,"
"**服务工作线程安装**(步骤 2-6):浏览器连接到托管在 `walrus.site` 的门户,"
"该门户响应一个页面,该页面为 `dapp.walrus.site` 安装服务工作线程。页面刷新以"
"激活服务工作线程。"

Expand All @@ -6830,7 +6830,7 @@ msgid ""
"index.html`, and extracts its Walrus blob ID and headers (see the [advanced "
"section on headers](./routing.md))."
msgstr ""
"** 站点解析 **(步骤 7-10):现在安装的服务工作线程解释其 _来源_ `dapp."
"**站点解析**(步骤 7-10):现在安装的服务工作线程解释其 _来源_ `dapp."
"walrus.site`,并进行 `dapp.sui` 的 SuiNS 解析,获取相关的对象 ID。使用对象 "
"ID,然后获取对象的动态字段(还检查 [重定向](./portal.md))。从动态字段中,它"
"选择 `index.html` 的字段,并提取其 Walrus blob ID 和头信息(请参阅 [头信息高"
Expand All @@ -6841,7 +6841,7 @@ msgid ""
"**Blob fetch** (steps 11-14): Given the blob ID, the service worker queries "
"a Walrus aggregator for the blob."
msgstr ""
"** Blob 获取 **(步骤 11-14):给定 blob ID,服务工作线程会向 Walrus 聚合器查"
"**Blob 获取**(步骤 11-14):给定 blob ID,服务工作线程会向 Walrus 聚合器查"
"询 blob。"

#: docs/walrus-sites/overview.md:133
Expand All @@ -6850,7 +6850,7 @@ msgid ""
"the bytes for `/index.html`, and its headers, it can craft a response that "
"is then rendered by the browser."
msgstr ""
"** 返回响应 **(步骤 15-16):现在服务工作线程已经获取了 `/index.html` 的字节"
"**返回响应**(步骤 15-16):现在服务工作线程已经获取了 `/index.html` 的字节"
"及其头信息,它可以构建一个响应,然后由浏览器渲染。"

#: docs/walrus-sites/overview.md:137
Expand Down
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;
}
File renamed without changes.
Loading