localization

package
v1.13.1 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package localization prepares localized document inputs before locale sites bind documents to routes, renderers, or cached Liquid drops.

Package localization contains the project-level localization seams shared by discovery, prepared locale sites, and Liquid registration.

Index

Constants

View Source
const PagesNamespace = "pages"

PagesNamespace is the namespace reserved for standalone pages. Each collection name is a separate namespace.

Variables

This section is empty.

Functions

This section is empty.

Types

type Catalog

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

Catalog is the validated collection of published translation editions and the prepared, locale-filtered document inputs.

func BuildCatalog

func BuildCatalog(registry *config.LocalizationConfig, documents []Document) (*Catalog, error)

BuildCatalog assigns included documents to locales, validates their translation identities, and produces deterministic locale-filtered inputs. Publication eligibility must already be reflected in Document.Included; excluded documents are intentionally absent from duplicate and sibling checks, as they are absent from the build.

func (*Catalog) Editions

func (c *Catalog) Editions(identity Identity) []Edition

Editions returns the published sibling editions in catalog locale order. The returned slice is independent from the catalog.

func (*Catalog) PreparedInputs

func (c *Catalog) PreparedInputs() []PreparedInput

PreparedInputs returns the independent, deterministic locale inputs. A caller may retain or modify the returned slices without mutating the catalog.

type CatalogError

type CatalogError struct {
	Problems []string
}

CatalogError reports catalog problems in deterministic order.

func (*CatalogError) Error

func (e *CatalogError) Error() string

type DataCatalog

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

DataCatalog owns immutable shared data and locale overlays discovered from a project's data directory. Its methods always return independent values, so a locale overlay cannot mutate the data exposed to another locale.

func DiscoverData

func DiscoverData(dir string, locales *config.LocalizationConfig) (*DataCatalog, error)

DiscoverData reads a project's data directory. A top-level shared data file contributes its mapping directly to common data. The locales directory is reserved for locale overlays and is never included in shared data.

func (*DataCatalog) Data

func (c *DataCatalog) Data(locale string) (map[string]interface{}, error)

Data returns the data visible to locale. It merges shared data, then each fallback from farthest to nearest, then the active locale overlay.

func (*DataCatalog) Messages

func (c *DataCatalog) Messages(locale string) (*MessageCatalog, error)

Messages returns the message catalog bound to locale. The returned module is the seam consumed by Liquid's translate filter; it deliberately does not expose generic data merging details to filter registration.

func (*DataCatalog) Shared

func (c *DataCatalog) Shared() map[string]interface{}

Shared returns a fresh copy of data common to every locale. It never contains the reserved locales subtree.

type DataValidationError

type DataValidationError struct {
	Problems []string
}

DataValidationError reports independent data-discovery failures in a stable order, independent of filesystem enumeration order.

func (*DataValidationError) Error

func (e *DataValidationError) Error() string

type Document

type Document struct {
	Source       string
	RelativePath string
	Namespace    string
	FrontMatter  frontmatter.FrontMatter
	Static       bool
	Included     bool
}

Document is an unbound source document with its effective front matter. It deliberately has no site, route, or render state so it can be assigned to a locale before those values are initialized.

func DiscoverDocument

func DiscoverDocument(cfg *config.Config, source, relativePath, namespace, typename string) (Document, error)

DiscoverDocument reads a source document without constructing a page. It applies the same front-matter-default lookup used by ordinary site discovery before returning the document for locale assignment. namespace is PagesNamespace for standalone pages and the collection name for collection documents; typename is the existing defaults type ("pages" or a collection name).

The returned Included value applies the current unpublished setting. A caller that filters drafts or future posts must set Included to false before BuildCatalog; doing so guarantees those editions cannot create duplicate catalog identities or appear in prepared inputs.

type Edition

type Edition struct {
	Document
	Locale         config.Locale
	TranslationKey string
}

Edition is an included document assigned to a configured locale. Documents without a TranslationKey are represented in PreparedInput but never appear in the translation catalog.

type Identity

type Identity struct {
	Namespace      string
	TranslationKey string
}

Identity identifies a translation set within one content namespace.

type MessageCatalog

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

MessageCatalog resolves interface messages for one active locale. It has no interpolation or formatting behavior: callers receive only scalar strings.

func (*MessageCatalog) Translate

func (c *MessageCatalog) Translate(key string) (string, error)

Translate resolves a dotted message key through the active locale and its validated fallback chain. A present non-string value is terminal and fails; it never silently falls through to a different locale.

type PreparedInput

type PreparedInput struct {
	Locale    config.Locale
	Documents []Edition
}

PreparedInput is the locale-specific document input consumed by the later project coordinator. Documents are sorted by source path and contain only editions assigned to Locale.

Jump to

Keyboard shortcuts

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