mirror of
https://github.com/ebrandi/FDD-book.git
synced 2026-12-06 00:23:30 +00:00
Merge branch 'main' into fix/chinese-translation
This commit is contained in:
commit
b6e3f7571c
3 changed files with 233 additions and 31 deletions
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
This document explains how to build the FreeBSD Device Drivers book using the updated build system with the Eisvogel pandoc LaTeX template.
|
This document explains how to build the FreeBSD Device Drivers book using the updated build system with the Eisvogel pandoc LaTeX template.
|
||||||
|
|
||||||
The build system supports three languages out of the box: English (`en_US`), Brazilian Portuguese (`pt_BR`), and Spanish (`es_ES`). A single invocation of `./scripts/build-book.sh` with no arguments produces every supported format (PDF, EPUB, HTML5) in every supported language. Individual formats and languages can be selected with the `--pdf`, `--epub`, `--html`, `--all`, and `--lang` options described below.
|
The build system supports four languages out of the box: English (`en_US`), Brazilian Portuguese (`pt_BR`), Spanish (`es_ES`), and Simplified Chinese (`zh_CN`). A single invocation of `./scripts/build-book.sh` with no arguments produces every supported format (PDF, EPUB, HTML5) in every supported language. Individual formats and languages can be selected with the `--pdf`, `--epub`, `--html`, `--all`, and `--lang` options described below.
|
||||||
|
|
||||||
> [!WARNING]
|
> [!WARNING]
|
||||||
>
|
>
|
||||||
|
|
@ -114,10 +114,12 @@ sudo apt install -y texlive-amsmath texlive-amssymb texlive-amsthm
|
||||||
sudo apt install -y texlive-bibtex-extra texlive-biblatex
|
sudo apt install -y texlive-bibtex-extra texlive-biblatex
|
||||||
|
|
||||||
# Install hyphenation and language packs for the translated editions.
|
# Install hyphenation and language packs for the translated editions.
|
||||||
# Required to build the Brazilian Portuguese (pt_BR) and Spanish (es_ES)
|
# Required to build the Brazilian Portuguese (pt_BR), Spanish (es_ES),
|
||||||
# PDFs. Already included by texlive-full, so skip this line if you chose
|
# and Simplified Chinese (zh_CN) PDFs. Already included by texlive-full,
|
||||||
# the full installation above.
|
# so skip these lines if you chose the full installation above. The
|
||||||
sudo apt install -y texlive-lang-portuguese texlive-lang-spanish
|
# Simplified Chinese edition additionally requires CJK fonts (see the
|
||||||
|
# "CJK Fonts" section below).
|
||||||
|
sudo apt install -y texlive-lang-portuguese texlive-lang-spanish texlive-lang-chinese
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 4. **Font Installation** (Essential for Professional Typography)
|
#### 4. **Font Installation** (Essential for Professional Typography)
|
||||||
|
|
@ -194,9 +196,10 @@ sudo apt install -y texlive-fonts-extra
|
||||||
sudo apt install -y texlive-fonts-extra texlive-fonts-recommended
|
sudo apt install -y texlive-fonts-extra texlive-fonts-recommended
|
||||||
```
|
```
|
||||||
|
|
||||||
**CJK Fonts (if you need Asian language support):**
|
**CJK Fonts (required for the Simplified Chinese edition):**
|
||||||
```bash
|
```bash
|
||||||
# Install Chinese, Japanese, Korean fonts
|
# Install Chinese, Japanese, Korean fonts (Noto CJK is required to build
|
||||||
|
# the zh_CN PDF; the build pipeline uses it as the default CJK main font)
|
||||||
sudo apt install -y fonts-noto-cjk fonts-noto-cjk-extra
|
sudo apt install -y fonts-noto-cjk fonts-noto-cjk-extra
|
||||||
|
|
||||||
# Install additional CJK fonts
|
# Install additional CJK fonts
|
||||||
|
|
@ -359,7 +362,12 @@ echo "or run 'sudo fc-cache -fv' again to ensure the font cache is updated."
|
||||||
│ │ │ ├── part1/
|
│ │ │ ├── part1/
|
||||||
│ │ │ └── ...
|
│ │ │ └── ...
|
||||||
│ │ └── appendices/
|
│ │ └── appendices/
|
||||||
│ └── es_ES/ # Spanish edition
|
│ ├── es_ES/ # Spanish edition
|
||||||
|
│ │ ├── chapters/
|
||||||
|
│ │ │ ├── part1/
|
||||||
|
│ │ │ └── ...
|
||||||
|
│ │ └── appendices/
|
||||||
|
│ └── zh_CN/ # Simplified Chinese edition
|
||||||
│ ├── chapters/
|
│ ├── chapters/
|
||||||
│ │ ├── part1/
|
│ │ ├── part1/
|
||||||
│ │ └── ...
|
│ │ └── ...
|
||||||
|
|
@ -379,6 +387,7 @@ Each language build reads from its own chapters and appendices tree:
|
||||||
| `en_US` | `content/chapters/` | `content/appendices/` |
|
| `en_US` | `content/chapters/` | `content/appendices/` |
|
||||||
| `pt_BR` | `translations/pt_BR/chapters/` | `translations/pt_BR/appendices/` |
|
| `pt_BR` | `translations/pt_BR/chapters/` | `translations/pt_BR/appendices/` |
|
||||||
| `es_ES` | `translations/es_ES/chapters/` | `translations/es_ES/appendices/` |
|
| `es_ES` | `translations/es_ES/chapters/` | `translations/es_ES/appendices/` |
|
||||||
|
| `zh_CN` | `translations/zh_CN/chapters/` | `translations/zh_CN/appendices/` |
|
||||||
|
|
||||||
## Building the Book
|
## Building the Book
|
||||||
|
|
||||||
|
|
@ -391,15 +400,15 @@ To build the complete book, run the script from the root directory:
|
||||||
./scripts/build-book.sh
|
./scripts/build-book.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
**Note**: All command-line options are case-insensitive. You can use `--PDF`, `--Pdf`, `--pdf`, or any mixed case variation. Language codes (`en_US`, `pt_BR`, `es_ES`) accept either `-` or `_` as the separator and are also case-insensitive, so `pt_BR`, `pt-BR`, `PT_br`, and `ptbr` all resolve to the same canonical code.
|
**Note**: All command-line options are case-insensitive. You can use `--PDF`, `--Pdf`, `--pdf`, or any mixed case variation. Language codes (`en_US`, `pt_BR`, `es_ES`, `zh_CN`) accept either `-` or `_` as the separator and are also case-insensitive, so `pt_BR`, `pt-BR`, `PT_br`, and `ptbr` all resolve to the same canonical code.
|
||||||
|
|
||||||
With no arguments the script will:
|
With no arguments the script will:
|
||||||
1. Check all prerequisites
|
1. Check all prerequisites
|
||||||
2. Discover all chapters and appendices automatically for every supported language
|
2. Discover all chapters and appendices automatically for every supported language
|
||||||
3. Build the PDF for `en_US`, `pt_BR`, and `es_ES` using the Eisvogel template
|
3. Build the PDF for `en_US`, `pt_BR`, `es_ES`, and `zh_CN` using the Eisvogel template
|
||||||
4. Build EPUB versions for all three languages
|
4. Build EPUB versions for all four languages
|
||||||
5. Build HTML5 versions for all three languages
|
5. Build HTML5 versions for all four languages
|
||||||
6. Place output files in the `public/downloads/` directory, one per language × format (nine files in total)
|
6. Place output files in the `public/downloads/` directory, one per language × format (twelve files in total)
|
||||||
|
|
||||||
If a given language has no valid chapter files, that language is skipped with a clear error message, but the build continues for the remaining languages rather than aborting.
|
If a given language has no valid chapter files, that language is skipped with a clear error message, but the build continues for the remaining languages rather than aborting.
|
||||||
|
|
||||||
|
|
@ -438,6 +447,7 @@ Use `--lang CODE` (or `--lang=CODE`) to restrict the build to one or more langua
|
||||||
| `en_US` | English (original manuscript) |
|
| `en_US` | English (original manuscript) |
|
||||||
| `pt_BR` | Brazilian Portuguese |
|
| `pt_BR` | Brazilian Portuguese |
|
||||||
| `es_ES` | Spanish |
|
| `es_ES` | Spanish |
|
||||||
|
| `zh_CN` | Simplified Chinese |
|
||||||
| `all` | Every supported language |
|
| `all` | Every supported language |
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|
@ -453,6 +463,9 @@ Use `--lang CODE` (or `--lang=CODE`) to restrict the build to one or more langua
|
||||||
# Build the Spanish EPUB and HTML5 only
|
# Build the Spanish EPUB and HTML5 only
|
||||||
./scripts/build-book.sh --epub --html --lang es_ES
|
./scripts/build-book.sh --epub --html --lang es_ES
|
||||||
|
|
||||||
|
# Build the Simplified Chinese PDF only
|
||||||
|
./scripts/build-book.sh --pdf --lang zh_CN
|
||||||
|
|
||||||
# Equivalent to running with no arguments (all formats, all languages)
|
# Equivalent to running with no arguments (all formats, all languages)
|
||||||
./scripts/build-book.sh --all --lang all
|
./scripts/build-book.sh --all --lang all
|
||||||
```
|
```
|
||||||
|
|
@ -469,7 +482,7 @@ The build system automatically filters out markdown files with less than 20 line
|
||||||
|
|
||||||
### Output Files
|
### Output Files
|
||||||
|
|
||||||
Every generated file is named with the canonical language code suffix so that the three editions can sit side by side in the same output directory. A full build produces nine files (three formats × three languages) under `public/downloads/`:
|
Every generated file is named with the canonical language code suffix so that the four editions can sit side by side in the same output directory. A full build produces twelve files (three formats × four languages) under `public/downloads/`:
|
||||||
|
|
||||||
**English (en_US):**
|
**English (en_US):**
|
||||||
- **PDF**: `public/downloads/freebsd-device-drivers-en_US.pdf`
|
- **PDF**: `public/downloads/freebsd-device-drivers-en_US.pdf`
|
||||||
|
|
@ -486,7 +499,12 @@ Every generated file is named with the canonical language code suffix so that th
|
||||||
- **EPUB**: `public/downloads/freebsd-device-drivers-es_ES.epub`
|
- **EPUB**: `public/downloads/freebsd-device-drivers-es_ES.epub`
|
||||||
- **HTML5**: `public/downloads/freebsd-device-drivers-es_ES.html`
|
- **HTML5**: `public/downloads/freebsd-device-drivers-es_ES.html`
|
||||||
|
|
||||||
Each build also sets the appropriate Pandoc/LaTeX `lang` metadata (`en-US`, `pt-BR`, or `es-ES`) so that hyphenation, quotation marks, and other locale-sensitive typography are handled correctly for the chosen language.
|
**Simplified Chinese (zh_CN):**
|
||||||
|
- **PDF**: `public/downloads/freebsd-device-drivers-zh_CN.pdf`
|
||||||
|
- **EPUB**: `public/downloads/freebsd-device-drivers-zh_CN.epub`
|
||||||
|
- **HTML5**: `public/downloads/freebsd-device-drivers-zh_CN.html`
|
||||||
|
|
||||||
|
Each build also sets the appropriate Pandoc/LaTeX `lang` metadata (`en-US`, `pt-BR`, `es-ES`, or `zh-CN`) so that hyphenation, quotation marks, and other locale-sensitive typography are handled correctly for the chosen language. For `zh_CN`, the build also wires Noto CJK SC fonts into the Eisvogel template through the `CJKmainfont`, `CJKsansfont`, and `CJKmonofont` variables so that Chinese glyphs render correctly in the PDF.
|
||||||
|
|
||||||
## Eisvogel Template Features
|
## Eisvogel Template Features
|
||||||
|
|
||||||
|
|
@ -826,6 +844,24 @@ pandoc scripts/title.md $(find translations/es_ES/chapters translations/es_ES/ap
|
||||||
-o public/downloads/freebsd-device-drivers-es_ES.html
|
-o public/downloads/freebsd-device-drivers-es_ES.html
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**Simplified Chinese (zh_CN):**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pandoc scripts/title.md $(find translations/zh_CN/chapters translations/zh_CN/appendices -name "*.md" | sort) \
|
||||||
|
--metadata-file=scripts/metadata.yaml \
|
||||||
|
--to=html5 \
|
||||||
|
--standalone \
|
||||||
|
--embed-resources \
|
||||||
|
--syntax-highlighting=tango \
|
||||||
|
--toc \
|
||||||
|
--toc-depth=2 \
|
||||||
|
--number-sections \
|
||||||
|
--metadata title="FreeBSD Device Drivers" \
|
||||||
|
--metadata author="Edson Brandi" \
|
||||||
|
--metadata lang="zh-CN" \
|
||||||
|
-o public/downloads/freebsd-device-drivers-zh_CN.html
|
||||||
|
```
|
||||||
|
|
||||||
**Note**: The `--syntax-highlighting=tango` option (new name for the deprecated `--highlight-style` flag in recent Pandoc releases) provides excellent C language syntax highlighting. Other available styles include: `pygments`, `kate`, `espresso`, `zenburn`, `monochrome`, `breezedark`, and `haddock`. You can list all available styles with `pandoc --list-highlight-styles`.
|
**Note**: The `--syntax-highlighting=tango` option (new name for the deprecated `--highlight-style` flag in recent Pandoc releases) provides excellent C language syntax highlighting. Other available styles include: `pygments`, `kate`, `espresso`, `zenburn`, `monochrome`, `breezedark`, and `haddock`. You can list all available styles with `pandoc --list-highlight-styles`.
|
||||||
|
|
||||||
### HTML5 vs PDF Comparison
|
### HTML5 vs PDF Comparison
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@
|
||||||
# en_US English (original) content/chapters, content/appendices
|
# en_US English (original) content/chapters, content/appendices
|
||||||
# pt_BR Brazilian Portuguese translations/pt_BR/chapters, translations/pt_BR/appendices
|
# pt_BR Brazilian Portuguese translations/pt_BR/chapters, translations/pt_BR/appendices
|
||||||
# es_ES Spanish translations/es_ES/chapters, translations/es_ES/appendices
|
# es_ES Spanish translations/es_ES/chapters, translations/es_ES/appendices
|
||||||
|
# zh_CN Chinese (Simplified) translations/zh_CN/chapters, translations/zh_CN/appendices
|
||||||
#
|
#
|
||||||
# Running the script with no arguments builds every supported format
|
# Running the script with no arguments builds every supported format
|
||||||
# (PDF + EPUB + HTML) in every supported language. Individual formats or
|
# (PDF + EPUB + HTML) in every supported language. Individual formats or
|
||||||
|
|
@ -78,7 +79,7 @@ PDF_ENGINE="xelatex"
|
||||||
|
|
||||||
# Supported languages in canonical form. The list order controls the order
|
# Supported languages in canonical form. The list order controls the order
|
||||||
# used by "build everything" runs and by the final summary.
|
# used by "build everything" runs and by the final summary.
|
||||||
LANGUAGES_ALL=(en_US pt_BR es_ES)
|
LANGUAGES_ALL=(en_US pt_BR es_ES zh_CN)
|
||||||
|
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
# LANGUAGE HELPERS
|
# LANGUAGE HELPERS
|
||||||
|
|
@ -90,6 +91,7 @@ get_chapters_dir() {
|
||||||
en_US) echo "content/chapters" ;;
|
en_US) echo "content/chapters" ;;
|
||||||
pt_BR) echo "translations/pt_BR/chapters" ;;
|
pt_BR) echo "translations/pt_BR/chapters" ;;
|
||||||
es_ES) echo "translations/es_ES/chapters" ;;
|
es_ES) echo "translations/es_ES/chapters" ;;
|
||||||
|
zh_CN) echo "translations/zh_CN/chapters" ;;
|
||||||
*) echo ""; return 1 ;;
|
*) echo ""; return 1 ;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
@ -100,18 +102,21 @@ get_appendices_dir() {
|
||||||
en_US) echo "content/appendices" ;;
|
en_US) echo "content/appendices" ;;
|
||||||
pt_BR) echo "translations/pt_BR/appendices" ;;
|
pt_BR) echo "translations/pt_BR/appendices" ;;
|
||||||
es_ES) echo "translations/es_ES/appendices" ;;
|
es_ES) echo "translations/es_ES/appendices" ;;
|
||||||
|
zh_CN) echo "translations/zh_CN/appendices" ;;
|
||||||
*) echo ""; return 1 ;;
|
*) echo ""; return 1 ;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
# Map a canonical language code to its Pandoc/LaTeX `lang` metadata value.
|
# Map a canonical language code to its Pandoc/LaTeX `lang` metadata value.
|
||||||
# Pandoc uses this to pick the right hyphenation/typography rules, which is
|
# Pandoc uses this to pick the right hyphenation/typography rules, which is
|
||||||
# why pt_BR and es_ES need it set explicitly instead of defaulting to en-US.
|
# why pt_BR, es_ES, and zh_CN need it set explicitly instead of defaulting
|
||||||
|
# to en-US.
|
||||||
get_pandoc_lang() {
|
get_pandoc_lang() {
|
||||||
case "$1" in
|
case "$1" in
|
||||||
en_US) echo "en-US" ;;
|
en_US) echo "en-US" ;;
|
||||||
pt_BR) echo "pt-BR" ;;
|
pt_BR) echo "pt-BR" ;;
|
||||||
es_ES) echo "es-ES" ;;
|
es_ES) echo "es-ES" ;;
|
||||||
|
zh_CN) echo "zh-CN" ;;
|
||||||
*) echo ""; return 1 ;;
|
*) echo ""; return 1 ;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
@ -122,6 +127,7 @@ get_lang_display() {
|
||||||
en_US) echo "English (en_US)" ;;
|
en_US) echo "English (en_US)" ;;
|
||||||
pt_BR) echo "Brazilian Portuguese (pt_BR)" ;;
|
pt_BR) echo "Brazilian Portuguese (pt_BR)" ;;
|
||||||
es_ES) echo "Spanish (es_ES)" ;;
|
es_ES) echo "Spanish (es_ES)" ;;
|
||||||
|
zh_CN) echo "Chinese Simplified (zh_CN)" ;;
|
||||||
*) echo "$1" ;;
|
*) echo "$1" ;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
@ -141,6 +147,7 @@ normalize_lang() {
|
||||||
enus) echo "en_US" ;;
|
enus) echo "en_US" ;;
|
||||||
ptbr) echo "pt_BR" ;;
|
ptbr) echo "pt_BR" ;;
|
||||||
eses) echo "es_ES" ;;
|
eses) echo "es_ES" ;;
|
||||||
|
zhcn) echo "zh_CN" ;;
|
||||||
*) echo "" ;;
|
*) echo "" ;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
@ -272,13 +279,14 @@ FORMATS (case-insensitive; may be combined; default: all three):
|
||||||
--html Build HTML5
|
--html Build HTML5
|
||||||
--all Shorthand for --pdf --epub --html
|
--all Shorthand for --pdf --epub --html
|
||||||
|
|
||||||
LANGUAGES (case- and separator-insensitive; repeatable; default: all three):
|
LANGUAGES (case- and separator-insensitive; repeatable; default: all four):
|
||||||
--lang CODE
|
--lang CODE
|
||||||
--lang=CODE
|
--lang=CODE
|
||||||
CODE may be:
|
CODE may be:
|
||||||
en_US English (original)
|
en_US English (original)
|
||||||
pt_BR Brazilian Portuguese
|
pt_BR Brazilian Portuguese
|
||||||
es_ES Spanish
|
es_ES Spanish
|
||||||
|
zh_CN Chinese (Simplified)
|
||||||
all Every supported language (the default)
|
all Every supported language (the default)
|
||||||
Case and the separator are ignored, so the following are equivalent:
|
Case and the separator are ignored, so the following are equivalent:
|
||||||
pt_BR pt-BR PT_br Pt-Br ptbr PTBR
|
pt_BR pt-BR PT_br Pt-Br ptbr PTBR
|
||||||
|
|
@ -289,7 +297,7 @@ OTHER OPTIONS:
|
||||||
|
|
||||||
DEFAULTS:
|
DEFAULTS:
|
||||||
Running "$0" with no arguments builds every supported format (PDF, EPUB,
|
Running "$0" with no arguments builds every supported format (PDF, EPUB,
|
||||||
HTML) in every supported language (en_US, pt_BR, es_ES).
|
HTML) in every supported language (en_US, pt_BR, es_ES, zh_CN).
|
||||||
|
|
||||||
OUTPUT DIRECTORY:
|
OUTPUT DIRECTORY:
|
||||||
Generated files are placed under: $OUTPUT_DIR/
|
Generated files are placed under: $OUTPUT_DIR/
|
||||||
|
|
@ -307,11 +315,16 @@ OUTPUT FILES (per language):
|
||||||
$OUTPUT_DIR/${OUTPUT_BASENAME}-es_ES.pdf
|
$OUTPUT_DIR/${OUTPUT_BASENAME}-es_ES.pdf
|
||||||
$OUTPUT_DIR/${OUTPUT_BASENAME}-es_ES.epub
|
$OUTPUT_DIR/${OUTPUT_BASENAME}-es_ES.epub
|
||||||
$OUTPUT_DIR/${OUTPUT_BASENAME}-es_ES.html
|
$OUTPUT_DIR/${OUTPUT_BASENAME}-es_ES.html
|
||||||
|
Chinese Simplified (zh_CN):
|
||||||
|
$OUTPUT_DIR/${OUTPUT_BASENAME}-zh_CN.pdf
|
||||||
|
$OUTPUT_DIR/${OUTPUT_BASENAME}-zh_CN.epub
|
||||||
|
$OUTPUT_DIR/${OUTPUT_BASENAME}-zh_CN.html
|
||||||
|
|
||||||
CONTENT SOURCES:
|
CONTENT SOURCES:
|
||||||
en_US content/chapters/ content/appendices/
|
en_US content/chapters/ content/appendices/
|
||||||
pt_BR translations/pt_BR/chapters/ translations/pt_BR/appendices/
|
pt_BR translations/pt_BR/chapters/ translations/pt_BR/appendices/
|
||||||
es_ES translations/es_ES/chapters/ translations/es_ES/appendices/
|
es_ES translations/es_ES/chapters/ translations/es_ES/appendices/
|
||||||
|
zh_CN translations/zh_CN/chapters/ translations/zh_CN/appendices/
|
||||||
|
|
||||||
EXAMPLES:
|
EXAMPLES:
|
||||||
$0 # Build every format in every language
|
$0 # Build every format in every language
|
||||||
|
|
@ -319,6 +332,7 @@ EXAMPLES:
|
||||||
$0 --lang pt_BR # Build every format in Brazilian Portuguese
|
$0 --lang pt_BR # Build every format in Brazilian Portuguese
|
||||||
$0 --lang pt-br --lang es-ES # Build every format in pt_BR and es_ES
|
$0 --lang pt-br --lang es-ES # Build every format in pt_BR and es_ES
|
||||||
$0 --pdf --lang en_US # Build the English PDF only
|
$0 --pdf --lang en_US # Build the English PDF only
|
||||||
|
$0 --pdf --lang zh_CN # Build the Chinese (Simplified) PDF only
|
||||||
$0 --EPUB --HTML --Lang=Pt-Br # Mixed case (all equivalent)
|
$0 --EPUB --HTML --Lang=Pt-Br # Mixed case (all equivalent)
|
||||||
$0 --test # Check dependencies without building
|
$0 --test # Check dependencies without building
|
||||||
|
|
||||||
|
|
@ -326,9 +340,12 @@ REQUIREMENTS:
|
||||||
- Pandoc 3.0+
|
- Pandoc 3.0+
|
||||||
- XeLaTeX (texlive-xetex)
|
- XeLaTeX (texlive-xetex)
|
||||||
- Eisvogel template at: $EISVOGEL_TEMPLATE
|
- Eisvogel template at: $EISVOGEL_TEMPLATE
|
||||||
- LaTeX hyphenation packs for Portuguese and Spanish
|
- LaTeX hyphenation/language packs for the translated editions
|
||||||
(e.g. texlive-lang-portuguese, texlive-lang-spanish)
|
(e.g. texlive-lang-portuguese, texlive-lang-spanish,
|
||||||
- Required fonts (Times New Roman, Arial, Liberation Mono)
|
texlive-lang-chinese, texlive-lang-cjk)
|
||||||
|
- Required Latin fonts (Times New Roman, Arial, Liberation Mono)
|
||||||
|
- Required CJK fonts for zh_CN
|
||||||
|
(fonts-noto-cjk, fonts-noto-cjk-extra — Noto Serif/Sans/Mono CJK SC)
|
||||||
|
|
||||||
For detailed installation instructions, see: $SCRIPT_DIR/BUILD-README.md
|
For detailed installation instructions, see: $SCRIPT_DIR/BUILD-README.md
|
||||||
EOF
|
EOF
|
||||||
|
|
@ -490,6 +507,25 @@ build_pdf() {
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Language-specific font configuration. The default fonts declared in
|
||||||
|
# scripts/metadata.yaml (Times New Roman / Arial / Liberation Mono) have
|
||||||
|
# no CJK glyphs, so zh_CN needs Noto CJK fonts wired in through the
|
||||||
|
# Eisvogel template's CJKmainfont/CJKsansfont/CJKmonofont variables
|
||||||
|
# (which auto-load xeCJK) plus a mainfont override so Latin text in the
|
||||||
|
# body shares the same visual weight as the surrounding Chinese.
|
||||||
|
local -a font_args=()
|
||||||
|
case "$lang" in
|
||||||
|
zh_CN)
|
||||||
|
font_args=(
|
||||||
|
--variable mainfont="Noto Serif CJK SC"
|
||||||
|
--variable sansfont="Noto Sans CJK SC"
|
||||||
|
--variable CJKmainfont="Noto Serif CJK SC"
|
||||||
|
--variable CJKsansfont="Noto Sans CJK SC"
|
||||||
|
--variable CJKmonofont="Noto Sans Mono CJK SC"
|
||||||
|
)
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
echo " Including files: ${#BUILD_FILES[@]} total (1 title + ${BUILD_FILES_CHAPTERS} chapters + ${BUILD_FILES_APPENDICES} appendices)"
|
echo " Including files: ${#BUILD_FILES[@]} total (1 title + ${BUILD_FILES_CHAPTERS} chapters + ${BUILD_FILES_APPENDICES} appendices)"
|
||||||
echo " Running pandoc with Eisvogel template (lang=$pandoc_lang)..."
|
echo " Running pandoc with Eisvogel template (lang=$pandoc_lang)..."
|
||||||
|
|
||||||
|
|
@ -517,6 +553,7 @@ build_pdf() {
|
||||||
--syntax-highlighting=tango \
|
--syntax-highlighting=tango \
|
||||||
--variable linestretch=1.15 \
|
--variable linestretch=1.15 \
|
||||||
--variable geometry:"inner=2cm,outer=2cm,top=2.5cm,bottom=2.5cm" \
|
--variable geometry:"inner=2cm,outer=2cm,top=2.5cm,bottom=2.5cm" \
|
||||||
|
"${font_args[@]}" \
|
||||||
-o "$output_file" 2>&1
|
-o "$output_file" 2>&1
|
||||||
|
|
||||||
local exit_code=$?
|
local exit_code=$?
|
||||||
|
|
@ -747,7 +784,7 @@ while [[ $# -gt 0 ]]; do
|
||||||
canonical="$(normalize_lang "$raw_value")"
|
canonical="$(normalize_lang "$raw_value")"
|
||||||
if [ -z "$canonical" ]; then
|
if [ -z "$canonical" ]; then
|
||||||
echo "❌ Unknown language: '$raw_value'"
|
echo "❌ Unknown language: '$raw_value'"
|
||||||
echo " Accepted: en_US, pt_BR, es_ES, or all (case- and separator-insensitive)"
|
echo " Accepted: en_US, pt_BR, es_ES, zh_CN, or all (case- and separator-insensitive)"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
if [ "$canonical" = "all" ]; then
|
if [ "$canonical" = "all" ]; then
|
||||||
|
|
@ -760,13 +797,13 @@ while [[ $# -gt 0 ]]; do
|
||||||
--lang)
|
--lang)
|
||||||
shift
|
shift
|
||||||
if [ $# -eq 0 ]; then
|
if [ $# -eq 0 ]; then
|
||||||
echo "❌ --lang requires a value (en_US, pt_BR, es_ES, or all)"
|
echo "❌ --lang requires a value (en_US, pt_BR, es_ES, zh_CN, or all)"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
canonical="$(normalize_lang "$1")"
|
canonical="$(normalize_lang "$1")"
|
||||||
if [ -z "$canonical" ]; then
|
if [ -z "$canonical" ]; then
|
||||||
echo "❌ Unknown language: '$1'"
|
echo "❌ Unknown language: '$1'"
|
||||||
echo " Accepted: en_US, pt_BR, es_ES, or all (case- and separator-insensitive)"
|
echo " Accepted: en_US, pt_BR, es_ES, zh_CN, or all (case- and separator-insensitive)"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
if [ "$canonical" = "all" ]; then
|
if [ "$canonical" = "all" ]; then
|
||||||
|
|
|
||||||
|
|
@ -121,17 +121,132 @@ show_usage() {
|
||||||
echo " or with region (e.g., 'pt_BR', 'en_US')"
|
echo " or with region (e.g., 'pt_BR', 'en_US')"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Options:"
|
echo "Options:"
|
||||||
echo " -h, --help Show this help message"
|
echo " -h, --help Show this help message"
|
||||||
echo " -f, --force Force copy even if files already exist"
|
echo " -f, --force Force copy even if files already exist"
|
||||||
echo " -v, --verbose Show detailed output"
|
echo " -v, --verbose Show detailed output"
|
||||||
|
echo " --skip-deps Do not attempt to install language-specific"
|
||||||
|
echo " system dependencies (fonts, LaTeX packs)"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Examples:"
|
echo "Examples:"
|
||||||
echo " $0 fr # Set up French translation"
|
echo " $0 fr # Set up French translation"
|
||||||
echo " $0 de_DE # Set up German (Germany) translation"
|
echo " $0 de_DE # Set up German (Germany) translation"
|
||||||
echo " $0 es_MX # Set up Spanish (Mexico) translation"
|
echo " $0 es_MX # Set up Spanish (Mexico) translation"
|
||||||
|
echo " $0 zh_CN # Set up Chinese (Simplified) translation"
|
||||||
echo ""
|
echo ""
|
||||||
echo "This script creates a new language directory under translations/"
|
echo "This script creates a new language directory under translations/"
|
||||||
echo "and populates it with copies of content files for translation work."
|
echo "and populates it with copies of content files for translation work."
|
||||||
|
echo "For languages that need special fonts or LaTeX hyphenation packs"
|
||||||
|
echo "(e.g. zh_CN, zh_TW, ja_JP, ko_KR), it will also try to install the"
|
||||||
|
echo "required system packages via apt-get unless --skip-deps is given."
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to install language-specific system dependencies (fonts and
|
||||||
|
# LaTeX hyphenation packs). The default build configuration in
|
||||||
|
# scripts/metadata.yaml only covers Latin-script fonts, so CJK editions
|
||||||
|
# need additional Noto CJK fonts plus the matching texlive-lang-* packs
|
||||||
|
# in order for build-book.sh to produce a usable PDF.
|
||||||
|
#
|
||||||
|
# The function prints the exact commands first so they can be copied
|
||||||
|
# manually, then attempts to run them. It is a no-op for languages that
|
||||||
|
# do not need extra packages, and it bails out cleanly on non-Debian
|
||||||
|
# systems where apt-get is unavailable.
|
||||||
|
install_language_dependencies() {
|
||||||
|
local lang_code="$1"
|
||||||
|
local -a apt_packages=()
|
||||||
|
|
||||||
|
case "$lang_code" in
|
||||||
|
zh|zh_CN|zh_TW|zh_HK)
|
||||||
|
# Simplified and Traditional Chinese: Noto CJK fonts plus
|
||||||
|
# texlive's Chinese/CJK language support.
|
||||||
|
apt_packages=(
|
||||||
|
fonts-noto-cjk
|
||||||
|
fonts-noto-cjk-extra
|
||||||
|
texlive-lang-chinese
|
||||||
|
texlive-lang-cjk
|
||||||
|
)
|
||||||
|
;;
|
||||||
|
ja|ja_JP)
|
||||||
|
apt_packages=(
|
||||||
|
fonts-noto-cjk
|
||||||
|
fonts-noto-cjk-extra
|
||||||
|
fonts-ipafont
|
||||||
|
fonts-ipafont-gothic
|
||||||
|
fonts-ipafont-mincho
|
||||||
|
texlive-lang-japanese
|
||||||
|
texlive-lang-cjk
|
||||||
|
)
|
||||||
|
;;
|
||||||
|
ko|ko_KR)
|
||||||
|
apt_packages=(
|
||||||
|
fonts-noto-cjk
|
||||||
|
fonts-noto-cjk-extra
|
||||||
|
fonts-nanum
|
||||||
|
texlive-lang-korean
|
||||||
|
texlive-lang-cjk
|
||||||
|
)
|
||||||
|
;;
|
||||||
|
pt|pt_BR|pt_PT)
|
||||||
|
apt_packages=(texlive-lang-portuguese)
|
||||||
|
;;
|
||||||
|
es|es_ES|es_MX)
|
||||||
|
apt_packages=(texlive-lang-spanish)
|
||||||
|
;;
|
||||||
|
fr|fr_FR)
|
||||||
|
apt_packages=(texlive-lang-french)
|
||||||
|
;;
|
||||||
|
de|de_DE)
|
||||||
|
apt_packages=(texlive-lang-german)
|
||||||
|
;;
|
||||||
|
it|it_IT)
|
||||||
|
apt_packages=(texlive-lang-italian)
|
||||||
|
;;
|
||||||
|
ru|ru_RU)
|
||||||
|
apt_packages=(fonts-liberation texlive-lang-cyrillic)
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
# No extra dependencies known for this language.
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ "${#apt_packages[@]}" -eq 0 ]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
print_header "Installing system dependencies for $lang_code"
|
||||||
|
echo "The following apt packages are required to build $lang_code:"
|
||||||
|
echo ""
|
||||||
|
echo " sudo apt-get install -y ${apt_packages[*]}"
|
||||||
|
echo ""
|
||||||
|
echo "After installation, refresh the font cache so XeLaTeX can see"
|
||||||
|
echo "any new fonts:"
|
||||||
|
echo ""
|
||||||
|
echo " sudo fc-cache -fv"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
if ! command -v apt-get >/dev/null 2>&1; then
|
||||||
|
print_warning "apt-get not found. Skipping automatic install."
|
||||||
|
print_warning "Run the commands above manually on this system."
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! sudo -n true 2>/dev/null; then
|
||||||
|
print_warning "Automatic install needs sudo and the cached"
|
||||||
|
print_warning "credentials are missing. You will be prompted"
|
||||||
|
print_warning "for your password by sudo below; press Ctrl-C"
|
||||||
|
print_warning "to cancel and run the commands manually."
|
||||||
|
fi
|
||||||
|
|
||||||
|
if sudo apt-get install -y "${apt_packages[@]}"; then
|
||||||
|
print_status "Packages installed successfully."
|
||||||
|
if command -v fc-cache >/dev/null 2>&1; then
|
||||||
|
sudo fc-cache -fv >/dev/null 2>&1 || true
|
||||||
|
print_status "Font cache refreshed."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
print_error "apt-get install failed. Run the commands above manually."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to get language name from code
|
# Function to get language name from code
|
||||||
|
|
@ -168,6 +283,7 @@ main() {
|
||||||
local language_code=""
|
local language_code=""
|
||||||
local force_copy=false
|
local force_copy=false
|
||||||
local verbose=false
|
local verbose=false
|
||||||
|
local skip_deps=false
|
||||||
|
|
||||||
# Parse command line arguments
|
# Parse command line arguments
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
|
|
@ -184,6 +300,10 @@ main() {
|
||||||
verbose=true
|
verbose=true
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
--skip-deps)
|
||||||
|
skip_deps=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
-*)
|
-*)
|
||||||
print_error "Unknown option: $1"
|
print_error "Unknown option: $1"
|
||||||
show_usage
|
show_usage
|
||||||
|
|
@ -233,6 +353,15 @@ main() {
|
||||||
print_warning "Use --force option to overwrite existing files."
|
print_warning "Use --force option to overwrite existing files."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Install language-specific system dependencies (fonts, LaTeX packs).
|
||||||
|
# Off by default for CI / unprivileged environments via --skip-deps.
|
||||||
|
if [ "$skip_deps" = true ]; then
|
||||||
|
print_status "Skipping language-specific dependency install (--skip-deps)."
|
||||||
|
else
|
||||||
|
install_language_dependencies "$language_code" || \
|
||||||
|
print_warning "Continuing despite dependency installation issues."
|
||||||
|
fi
|
||||||
|
|
||||||
print_status "Translators can now start working on files in: $lang_dir"
|
print_status "Translators can now start working on files in: $lang_dir"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue