Skip to content

Commit 86ad68a

Browse files
committed
Preliminary support multilingual
mdBook does not natively support multilingual documentation. A common approach is to use a third-party library like mdbook-i18n-helper, which relies on a Gettext-based workflow to enable multilingual support. However, I believe such a complex system is unnecessary for our case. Therefore, this commit follows the approach suggested in the official mdBook documentation: overriding the 'index.hbs' template to add a button that redirects users to the corresponding documentation in another language, thus achieving basic multilingual support. This commit introduces the following three files under the theme directory: - 'index.hbs': Adds a redirect button for switching languages. - 'lang-toggle.css': Defines the styling for the button and the dropdown menu. - 'lang-toggle.js': Implements the main logic behind the button's behavior. As a result, two separate books need to be built. However, since mdBook’s 'book.toml' does not support multiple '[book]' sections in a single configuration, this commit introduces a configuration template and a CMake script that generates language-specific toml files for each version, which are then built into their respective output folders. [1]: https://github.com/google/mdbook-i18n-helpers
1 parent 39884df commit 86ad68a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+478
-6
lines changed

guide/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
book
2+
build/*
3+
book.toml

guide/CMakeLists.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
cmake_minimum_required(VERSION 3.24)
2+
project(learn-vk-docs)
3+
4+
# Function to configure the book file and add a custom target to build it.
5+
function(MakeConfig LANGUAGE AUTHORS)
6+
# Set the variables for substitution.
7+
set(AUTHORS "${AUTHORS}")
8+
set(LANGUAGE "${LANGUAGE}")
9+
set(ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
10+
set(TARGET_DIR "${ROOT_DIR}/src/${LANGUAGE}")
11+
12+
# Configure the template file with the substitutions.
13+
configure_file(
14+
${ROOT_DIR}/book-template.config
15+
${TARGET_DIR}/book.toml
16+
@ONLY
17+
)
18+
19+
# Create a custom target that calls mdbook with the generated config.
20+
message("mdbook build ${TARGET_DIR}")
21+
execute_process(
22+
COMMAND mdbook build -d ${ROOT_DIR}/book/${LANGUAGE}
23+
WORKING_DIRECTORY ${TARGET_DIR}
24+
)
25+
endfunction()
26+
27+
# Create configurations for both languages.
28+
MakeConfig("en" "Karn Kaul")
29+
MakeConfig("zh-TW" "Mes")

guide/book-template.config

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[book]
2+
authors = ["@AUTHORS@"]
3+
language = "@LANGUAGE@"
4+
src = "."
5+
title = "Learn Vulkan"
6+
7+
[output.html]
8+
theme = "../../theme"
9+
additional-js = ["../../theme/lang-toggle.js"]
10+
additional-css = ["../../theme/lang-toggle.css"]

guide/book.toml

Lines changed: 0 additions & 6 deletions
This file was deleted.
File renamed without changes.

0 commit comments

Comments
 (0)