localization

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package localization owns locale request resolution and the logical single-locale/canonical-storage transform shared by operation engines and strict store fixtures.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyLocaleIssues

func CopyLocaleIssues(fields []schema.Field, values store.Values) []schema.Issue

CopyLocaleIssues rejects structured localized copies that cannot match rows back to their canonical storage counterparts. Positional matching would let stale or reordered input overwrite non-localized siblings, so row keys are a safety requirement for non-localized arrays and blocks with localized descendants.

func LocalizedValues

func LocalizedValues(fields []schema.Field, values store.Values) store.Values

LocalizedValues extracts only localized authored values from one projected document. Row identity and block discriminators are retained so a copy-to-locale update can merge nested values without replacing shared structure or non-localized siblings.

func LocalizedValuesChecked added in v0.2.0

func LocalizedValuesChecked(fields []schema.Field, values store.Values) (store.Values, error)

func MergeStoragePatch

func MergeStoragePatch(fields []schema.Field, current, patch store.Values) store.Values

MergeStoragePatch combines partial locale maps during an update.

func MergeStoragePatchChecked added in v0.2.0

func MergeStoragePatchChecked(fields []schema.Field, current, patch store.Values) (store.Values, error)

func MergeStorageUpdate

func MergeStorageUpdate(fields []schema.Field, current, patch store.Values) store.Values

MergeStorageUpdate expands submitted structured fields against their current canonical value while keeping the update limited to top-level fields present in the patch. PostgreSQL stores groups, arrays, and blocks as one JSON value, so this makes its patch semantics match stores that merge those values in memory: omitted nested fields are preserved, explicit nulls still clear, and keyed row lists may still remove whole rows by omitting the row itself.

func MergeStorageUpdateChecked added in v0.2.0

func MergeStorageUpdateChecked(fields []schema.Field, current, patch store.Values) (store.Values, error)

func ParseFallbackQuery

func ParseFallbackQuery(value string) ([]schema.LocaleCode, bool, error)

ParseFallbackQuery accepts Payload-compatible disable tokens or a comma-separated fallback chain. A nil slice means no explicit override.

func ProjectDocument

func ProjectDocument(document store.Document, fields []schema.Field, selection Selection) store.Document

ProjectDocument selects localized values for hooks and API output. All locale requests retain canonical locale maps.

func ProjectDocumentChecked added in v0.2.0

func ProjectDocumentChecked(document store.Document, fields []schema.Field, selection Selection) (store.Document, error)

ProjectDocumentChecked rejects malformed or unbounded embedded envelopes before projecting any portion of a document.

func StoragePatch

func StoragePatch(fields []schema.Field, values store.Values, selection Selection) (store.Values, error)

StoragePatch turns selected-locale authored input into the canonical locale map expected by stores without adding or deleting values for other locales.

Types

type Projector added in v0.2.0

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

Projector reuses recent root-field projections within one operation. Its resolved schema must remain immutable. A changed root is projected normally; only the latest source generation and its recent locale selections are kept. This cache does not index every nested item or retain an operation's history. Independent operations own independent projectors; a Projector is not intended for concurrent use. Call Clear when the operation finishes to release its values.

func NewProjector added in v0.2.0

func NewProjector(fields []schema.Field) *Projector

NewProjector borrows one resolved schema, which must remain immutable for the projector's lifetime. Cache storage is allocated only for active projections.

func (*Projector) Clear added in v0.2.0

func (projector *Projector) Clear()

Clear releases all cached source values, projections and provenance. The fixed schema remains available if the projector is used again.

func (*Projector) Document added in v0.2.0

func (projector *Projector) Document(document store.Document, selection Selection) store.Document

Document uses the current document's metadata and returns detached mutable root and provenance maps, including when all field projections are cache hits.

func (*Projector) DocumentChecked added in v0.2.0

func (projector *Projector) DocumentChecked(document store.Document, selection Selection) (store.Document, error)

DocumentChecked retains embedded admission on every call, independently of cached projections.

func (*Projector) Values added in v0.2.0

func (projector *Projector) Values(values store.Values, selection Selection) store.Values

Values returns a detached root map containing immutable projected values. Provenance stays private in the cache instead of being copied into a discarded Document on values-only paths.

func (*Projector) ValuesChecked added in v0.2.0

func (projector *Projector) ValuesChecked(values store.Values, selection Selection) (store.Values, error)

ValuesChecked retains embedded admission on every call, independently of any cached projection. All canonical locale branches are validated as usual.

type Selection

type Selection struct {
	Locale     schema.LocaleCode
	Chain      []schema.LocaleCode
	All        bool
	Configured []schema.LocaleCode
	// PreserveNull is used only while completing write patches. Read projections
	// normally skip null locale values so fallback can select another locale.
	PreserveNull bool
}

Selection is one validated request locale and its effective fallback chain.

func Resolve

func Resolve(settings *schema.LocalizationSettings, locale string, explicitFallback []schema.LocaleCode, disableFallback, all bool) (Selection, error)

Resolve validates request locale input. ExplicitFallback replaces configured fallback behavior. DisableFallback prevents both locale and default fallback.

Jump to

Keyboard shortcuts

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