Skip to content
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
5 changes: 3 additions & 2 deletions .github/workflows/rbe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on: [push, pull_request]
env:
# Update the language picker in index.hbs to link new languages.
LANGUAGES: ja zh es
MDBOOK_VERSION: 0.5.1

jobs:
test:
Expand All @@ -27,12 +28,12 @@ jobs:
- name: Install mdbook
run: |
mkdir bin
curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.4.51/mdbook-v0.4.51-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=bin
curl -sSL https://github.com/rust-lang/mdBook/releases/download/v${MDBOOK_VERSION}/mdbook-v${MDBOOK_VERSION}-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=bin
echo "$(pwd)/bin" >> ${GITHUB_PATH}

- name: Install mdbook-i18n-helpers
run: |
cargo install mdbook-i18n-helpers --locked --version 0.3.4
cargo install mdbook-i18n-helpers --locked --version 0.4.0

- name: Report versions
run: |
Expand Down
3 changes: 1 addition & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ $ mdbook build
**The following warnings can be ignored safely.**

```text
[WARN] (mdbook::preprocess::cmd): The command wasn't found, is the "gettext" preprocessor installed?
[WARN] (mdbook::preprocess::cmd): Command: mdbook-gettext
WARN The command `mdbook-gettext` for preprocessor `gettext` was not found, but is marked as optional.
```

[install Rust]: http://rust-lang.org/install.html
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ read all content offline, however!
**The following warnings can be ignored safely.**

```text
[WARN] (mdbook::preprocess::cmd): The command wasn't found, is the "gettext" preprocessor installed?
[WARN] (mdbook::preprocess::cmd): Command: mdbook-gettext
WARN The command `mdbook-gettext` for preprocessor `gettext` was not found, but is marked as optional.
```

### Using translated version
Expand Down
1 change: 0 additions & 1 deletion book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ hash-files = true
additional-css = [
"theme/css/language-picker.css",
]
additional-js = ["theme/js/language-picker.js"]

[rust]
edition = "2021"
Expand Down
71 changes: 69 additions & 2 deletions theme/head.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,71 @@
<script>
const mdbookPath = "{{ path }}";
const mdbookPathToRoot = "{{ path_to_root }}";
document.addEventListener('DOMContentLoaded', function() {
const mdbookPath = "{{ path }}";
const mdbookPathToRoot = "{{ path_to_root }}";
const rightButtonsElement = document.querySelector('.right-buttons');
rightButtonsElement.insertAdjacentHTML("afterbegin", `
<button id="language-toggle" class="icon-button" type="button"
title="Change language" aria-label="Change language"
aria-haspopup="true" aria-expanded="false"
aria-controls="language-list">
{{fa "solid" "globe"}}
</button>
<ul id="language-list" class="theme-popup" aria-label="Languages" role="menu">
<li role="none"><button role="menuitem" class="theme">
<a id="en">English</a>
</button></li>
<li role="none"><button role="menuitem" class="theme">
<a id="ja">日本語</a>
</button></li>
<li role="none"><button role="menuitem" class="theme">
<a id="zh">中文</a>
</button></li>
<li role="none"><button role="menuitem" class="theme">
<a id="es">Español</a>
</button></li>
</ul>
`);
const language = document.documentElement.getAttribute("lang");
let langToggle = document.getElementById("language-toggle");
let langList = document.getElementById("language-list");
langToggle.addEventListener("click", (event) => {
langList.style.display =
langList.style.display == "block" ? "none" : "block";
});
let selectedLang = document.getElementById(language);
if (selectedLang) {
selectedLang.parentNode.classList.add("theme-selected");
}
// The path to the root, taking the current language into account.
let full_path_to_root =
language == "en" ? `${mdbookPathToRoot}` : `${mdbookPathToRoot}../`;
// The page path (mdbook only gives us access to the path to the Markdown file).
let path = mdbookPath.replace(/\.md$/, ".html");
const langAnchors = Array.from(langList.querySelectorAll("a"));
for (let lang of langAnchors) {
if (lang.id == "en") {
lang.href = `${full_path_to_root}${path}`;
} else {
lang.href = `${full_path_to_root}${lang.id}/${path}`;
}
}
// Hide languages whose target page is not available (e.g., not deployed).
// This prevents users from hitting 404s on sites that only ship some locales.
for (let lang of langAnchors) {
const url = lang.href;
// Attempt a lightweight HEAD request; fall back to hiding on failure.
fetch(url, { method: "HEAD" }).then((resp) => {
if (!resp.ok) {
const li = lang.parentNode && lang.parentNode.parentNode;
if (li) li.style.display = "none";
}
}).catch(() => {
const li = lang.parentNode && lang.parentNode.parentNode;
if (li) li.style.display = "none";
});
}
});
</script>
67 changes: 0 additions & 67 deletions theme/js/language-picker.js

This file was deleted.