diff --git a/.github/actions/build-mdbook/action.yaml b/.github/actions/build-mdbook/action.yaml index 6b54628c..0007031a 100644 --- a/.github/actions/build-mdbook/action.yaml +++ b/.github/actions/build-mdbook/action.yaml @@ -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 + \ No newline at end of file diff --git a/.github/workflows/build.sh b/.github/workflows/build.sh new file mode 100755 index 00000000..43e4843f --- /dev/null +++ b/.github/workflows/build.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +set -Eeuo pipefail + +# Usage: build.sh +# +# 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 "} +dest_dir=${2:?"Usage: $0 "} + +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::" diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 5e9cbc19..b9c40216 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -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 }}" diff --git a/book.toml b/book.toml index ff00a24b..37e73bd7 100644 --- a/book.toml +++ b/book.toml @@ -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 diff --git a/po/zh_CN.po b/po/zh_CN.po index f5ae4b74..578874e4 100644 --- a/po/zh_CN.po +++ b/po/zh_CN.po @@ -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 @@ -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 "" @@ -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。" @@ -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 @@ -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` 安装服务工作线程。页面刷新以" "激活服务工作线程。" @@ -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 和头信息(请参阅 [头信息高" @@ -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 @@ -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 diff --git a/theme/css/language-picker.css b/theme/css/language-picker.css new file mode 100644 index 00000000..9847dcd1 --- /dev/null +++ b/theme/css/language-picker.css @@ -0,0 +1,13 @@ +#language-list { + left: auto; + right: 10px; + } + + [dir="rtl"] #language-list { + left: 10px; + right: auto; + } + + #language-list a { + color: inherit; + } \ No newline at end of file diff --git a/mdbook-admonish.css b/theme/css/mdbook-admonish.css similarity index 100% rename from mdbook-admonish.css rename to theme/css/mdbook-admonish.css diff --git a/theme/index.hbs b/theme/index.hbs new file mode 100644 index 00000000..7eb135e7 --- /dev/null +++ b/theme/index.hbs @@ -0,0 +1,411 @@ + + + + + + {{ title }} + {{#if is_print }} + + {{/if}} + {{#if base_url}} + + {{/if}} + + + + {{> head}} + + + + + + {{#if favicon_svg}} + + {{/if}} + {{#if favicon_png}} + + {{/if}} + + + + {{#if print_enable}} + + {{/if}} + + + + {{#if copy_fonts}} + + {{/if}} + + + + + + + + {{#each additional_css}} + + {{/each}} + + {{#if mathjax_support}} + + + {{/if}} + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ {{> header}} + + + + {{#if search_enabled}} + + {{/if}} + + + + +
+
+ {{{ content }}} +
+ + +
+
+ + + +
+ + {{#if live_reload_endpoint}} + + + {{/if}} + + {{#if google_analytics}} + + + {{/if}} + + {{#if playground_line_numbers}} + + {{/if}} + + {{#if playground_copyable}} + + {{/if}} + + {{#if playground_js}} + + + + + + {{/if}} + + {{#if search_js}} + + + + {{/if}} + + + + + + + {{#each additional_js}} + + {{/each}} + + {{#if is_print}} + {{#if mathjax_support}} + + {{else}} + + {{/if}} + {{/if}} + +
+ + \ No newline at end of file