i18n

package
v0.8.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package i18n provides multi-language book support. It parses language definitions from LANGS.md, where each language maps to a subdirectory.

LANGS.md format:

# Languages

* [English](en/)
* [Chinese](zh/)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CrossRefLabels added in v0.8.0

type CrossRefLabels struct {
	Figure  string // Format string taking the figure number, e.g. "Figure %d".
	Table   string // Format string taking the table number.
	Section string // Format string taking the section number.
}

CrossRefLabels holds the wording used for figure, table and section cross-references and for auto-generated captions. Keeping it here rather than in the cross-reference resolver means an English book no longer prints "图 1" under its figures.

func CrossRefLabelsFor added in v0.8.0

func CrossRefLabelsFor(lang string) CrossRefLabels

CrossRefLabelsFor returns the labels for a book language code such as "en-US" or "zh-CN". Unknown languages fall back to English, matching the default language in book.yaml.

func (CrossRefLabels) FigureLabel added in v0.8.0

func (l CrossRefLabels) FigureLabel(n int) string

FigureLabel renders the label for figure n, e.g. "Figure 1".

func (CrossRefLabels) SectionLabel added in v0.8.0

func (l CrossRefLabels) SectionLabel(n int) string

SectionLabel renders the label for section n, e.g. "Section 1".

func (CrossRefLabels) TableLabel added in v0.8.0

func (l CrossRefLabels) TableLabel(n int) string

TableLabel renders the label for table n, e.g. "Table 1".

type LangDef

type LangDef struct {
	Name string // Display name, for example "English".
	Dir  string // Subdirectory path, for example "en" or "zh".
}

LangDef describes one language variant.

func ParseLangsFile

func ParseLangsFile(path string) ([]LangDef, error)

ParseLangsFile parses language definitions from LANGS.md. Entries are resolved relative to the directory holding LANGS.md.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL