i18n

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateFallbacks

func GenerateFallbacks(pages []*engine.Page, languageCodes []string, defaultLang string, opts FallbackOptions) []*engine.Page

GenerateFallbacks creates fallback pages for non-default languages where a page exists in the default language but has no translation. Per-collection i18n_fallback:"omit" suppresses fallbacks for that collection. Returns the newly created fallback pages (caller should append to allPages).

For versioned pages, fallback operates within a version (no cross-version fallback). The grouping key includes collection+version for versioned pages, making the intent explicit rather than relying on version being embedded in LangRelPath.

func LinkAllTranslations

func LinkAllTranslations(pages []*engine.Page, weights map[string]int)

LinkAllTranslations groups all pages (real + fallback) by LangRelPath and populates each page's AllTranslations slice. Called after GenerateFallbacks so that fallback pages appear in AllTranslations but not in Translations.

func LinkTranslations

func LinkTranslations(pages []*engine.Page, weights map[string]int)

LinkTranslations groups pages by LangRelPath and populates each page's Translations slice with pointers to the same page in other languages. Pages are sorted by language weight (if available via the weights map).

Types

type FallbackOptions

type FallbackOptions struct {
	// SiteFallback is the site-level policy: "default" or "omit".
	SiteFallback string

	// CollectionFallback maps collection name → override policy.
	CollectionFallback map[string]string
}

FallbackOptions controls fallback generation behaviour.

type StringTable

type StringTable struct {
	// contains filtered or unexported fields
}

StringTable holds translation strings for all languages with fallback resolution.

func LoadStrings

func LoadStrings(embeddedFS fs.FS, projectDir, themeName, defaultLang string) (*StringTable, error)

LoadStrings loads i18n YAML files from three layers (embedded → theme → user). Later layers override earlier layers per-key.

func NewStringTable

func NewStringTable(defaultLang string) *StringTable

NewStringTable creates an empty StringTable with the given default language.

func (*StringTable) Misses

func (st *StringTable) Misses() map[string][]string

Misses returns keys that fell back during resolution, grouped by language.

func (*StringTable) Resolve

func (st *StringTable) Resolve(lang, key string, data ...any) string

Resolve looks up a translation key for the given language. Falls back to the default language, then to the key itself. If the value contains Go template syntax, it is executed with the optional data argument.

func (*StringTable) SetStrict

func (st *StringTable) SetStrict(on bool)

SetStrict enables strict mode, which records keys that fall back.

Jump to

Keyboard shortcuts

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