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 ¶
- func CopyLocaleIssues(fields []schema.Field, values store.Values) []schema.Issue
- func LocalizedValues(fields []schema.Field, values store.Values) store.Values
- func LocalizedValuesChecked(fields []schema.Field, values store.Values) (store.Values, error)
- func MergeStoragePatch(fields []schema.Field, current, patch store.Values) store.Values
- func MergeStoragePatchChecked(fields []schema.Field, current, patch store.Values) (store.Values, error)
- func MergeStorageUpdate(fields []schema.Field, current, patch store.Values) store.Values
- func MergeStorageUpdateChecked(fields []schema.Field, current, patch store.Values) (store.Values, error)
- func ParseFallbackQuery(value string) ([]schema.LocaleCode, bool, error)
- func ProjectDocument(document store.Document, fields []schema.Field, selection Selection) store.Document
- func ProjectDocumentChecked(document store.Document, fields []schema.Field, selection Selection) (store.Document, error)
- func StoragePatch(fields []schema.Field, values store.Values, selection Selection) (store.Values, error)
- type Projector
- func (projector *Projector) Clear()
- func (projector *Projector) Document(document store.Document, selection Selection) store.Document
- func (projector *Projector) DocumentChecked(document store.Document, selection Selection) (store.Document, error)
- func (projector *Projector) Values(values store.Values, selection Selection) store.Values
- func (projector *Projector) ValuesChecked(values store.Values, selection Selection) (store.Values, error)
- type Selection
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CopyLocaleIssues ¶
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 ¶
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 MergeStoragePatch ¶
MergeStoragePatch combines partial locale maps during an update.
func MergeStoragePatchChecked ¶ added in v0.2.0
func MergeStorageUpdate ¶
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 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.
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
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
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
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.