Documentation
¶
Index ¶
- Constants
- func GenerateFallbacks(pages []*engine.Page, languageCodes []string, defaultLang string, ...) []*engine.Page
- func LinkAllTranslations(pages []*engine.Page, weights map[string]int)
- func LinkTranslations(pages []*engine.Page, weights map[string]int)
- func LoadLayers(embeddedFS fs.FS, projectDir, themeName string) ([]Layer, []FileProblem)
- type FallbackOptions
- type FileProblem
- type Layer
- type StringTable
Constants ¶
const ( SourceBuiltin = "builtin" SourceTheme = "theme" SourceProject = "project" )
Layer sources, in load order: later layers override earlier ones per key.
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 ¶
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 ¶
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).
func LoadLayers ¶ added in v1.6.0
func LoadLayers(embeddedFS fs.FS, projectDir, themeName string) ([]Layer, []FileProblem)
LoadLayers reads the three string layers (embedded, theme, project) without merging them. A file that cannot be read or parsed is reported and skipped; a missing directory is an empty layer.
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 FileProblem ¶ added in v1.6.0
type FileProblem struct {
Source string `json:"source"`
File string `json:"file"`
Message string `json:"message"`
// contains filtered or unexported fields
}
FileProblem is a string file that could not be read or parsed.
type Layer ¶ added in v1.6.0
type Layer struct {
Source string `json:"source"`
// Dir is the layer's folder, relative to the project and slash-separated.
// Empty for the built-in strings.
Dir string `json:"dir,omitempty"`
// Strings maps a language code to its dotted keys and values.
Strings map[string]map[string]string `json:"strings"`
}
Layer is one source of translation strings.
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.