localization

package
v4.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package localization contains transport-neutral policy message localization.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNilCatalog is returned when a required catalog dependency is missing.
	ErrNilCatalog = errors.New("localization catalog is nil")

	// ErrNilEffectiveCatalog is returned when activation receives no effective catalog.
	ErrNilEffectiveCatalog = errors.New("effective localization catalog is nil")
)

Functions

func NewEffectiveCatalog

func NewEffectiveCatalog(system Catalog, overlays ...CatalogOverlay) (*EffectiveCatalog, []CatalogOverride, error)

NewEffectiveCatalog merges the system catalog with deployment overlays.

Types

type Catalog

type Catalog interface {
	Lookup(tag language.Tag, key string) (string, bool)
	Tags() []language.Tag
}

Catalog resolves localized messages for one immutable catalog view.

type CatalogBuilder

type CatalogBuilder func() (*EffectiveCatalog, error)

CatalogBuilder builds a complete effective catalog candidate for reload.

type CatalogOverlay

type CatalogOverlay struct {
	Entries   map[string]map[string]string
	Namespace string
}

CatalogOverlay contains deployment-owned translation entries.

func CloneCatalogOverlay

func CloneCatalogOverlay(overlay CatalogOverlay) CatalogOverlay

CloneCatalogOverlay returns a detached catalog overlay copy.

func CloneCatalogOverlays

func CloneCatalogOverlays(overlays []CatalogOverlay) []CatalogOverlay

CloneCatalogOverlays returns detached catalog overlay copies.

type CatalogOverride

type CatalogOverride struct {
	Language          string
	Key               string
	Namespace         string
	PreviousNamespace string
}

CatalogOverride reports an entry replaced by a deployment overlay.

type CatalogRegistry

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

CatalogRegistry owns deployment overlays and publishes effective catalogs.

func NewCatalogRegistry

func NewCatalogRegistry(system Catalog, overlays ...CatalogOverlay) (*CatalogRegistry, error)

NewCatalogRegistry creates a registry with an atomically published initial catalog.

func (*CatalogRegistry) Active

func (r *CatalogRegistry) Active() *EffectiveCatalog

Active returns the currently published immutable catalog.

func (*CatalogRegistry) RegisterOverlay

func (r *CatalogRegistry) RegisterOverlay(overlay CatalogOverlay) ([]CatalogOverride, error)

RegisterOverlay adds one deployment overlay and activates the resulting catalog atomically.

func (*CatalogRegistry) RegisterOverlays

func (r *CatalogRegistry) RegisterOverlays(overlays ...CatalogOverlay) ([]CatalogOverride, error)

RegisterOverlays adds deployment overlays and activates the resulting catalog atomically.

func (*CatalogRegistry) Reload

func (r *CatalogRegistry) Reload(overlays ...CatalogOverlay) ([]CatalogOverride, error)

Reload replaces all startup overlays only after the complete catalog builds successfully.

func (*CatalogRegistry) ReloadOperatorOverlays

func (r *CatalogRegistry) ReloadOperatorOverlays(overlays ...CatalogOverlay) ([]CatalogOverride, error)

ReloadOperatorOverlays atomically replaces only operator-configured overlays.

func (*CatalogRegistry) ValidateAdditionalOverlays

func (r *CatalogRegistry) ValidateAdditionalOverlays(overlays ...CatalogOverlay) ([]CatalogOverride, error)

ValidateAdditionalOverlays builds a candidate catalog without activating it.

type CatalogStore

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

CatalogStore publishes complete effective catalogs atomically.

func NewCatalogStore

func NewCatalogStore(initial *EffectiveCatalog) *CatalogStore

NewCatalogStore returns a store initialized with the provided catalog.

func (*CatalogStore) Activate

func (s *CatalogStore) Activate(candidate *EffectiveCatalog) error

Activate publishes a fully built effective catalog.

func (*CatalogStore) Active

func (s *CatalogStore) Active() *EffectiveCatalog

Active returns the immutable request-time catalog.

func (*CatalogStore) Reload

func (s *CatalogStore) Reload(build CatalogBuilder) error

Reload builds a new catalog and activates it only after the build succeeds.

type EffectiveCatalog

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

EffectiveCatalog is the frozen request-time catalog view.

func (*EffectiveCatalog) Lookup

func (c *EffectiveCatalog) Lookup(tag language.Tag, key string) (string, bool)

Lookup returns the effective message for the selected language and key.

func (*EffectiveCatalog) Tags

func (c *EffectiveCatalog) Tags() []language.Tag

Tags returns the effective supported language tags.

type LanguagePreference

type LanguagePreference struct {
	Explicit string
	Policy   string
	Header   string
	Tags     []string
	Default  string
}

LanguagePreference describes the transport-neutral language preference chain.

type ManagerCatalog

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

ManagerCatalog adapts the existing language manager as a system catalog.

func NewManagerCatalog

func NewManagerCatalog(manager corelang.Manager) *ManagerCatalog

NewManagerCatalog returns a catalog backed by the existing language manager.

func (*ManagerCatalog) Lookup

func (c *ManagerCatalog) Lookup(tag language.Tag, key string) (string, bool)

Lookup resolves a message only when it exists in the selected language.

func (*ManagerCatalog) Tags

func (c *ManagerCatalog) Tags() []language.Tag

Tags returns the language manager's supported language tags.

type MapCatalog

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

MapCatalog is an immutable in-memory catalog for tests and deployment overlays.

func NewMapCatalog

func NewMapCatalog(entries map[string]map[string]string) *MapCatalog

NewMapCatalog returns a detached in-memory catalog from language-key entries.

func (*MapCatalog) Lookup

func (c *MapCatalog) Lookup(tag language.Tag, key string) (string, bool)

Lookup returns a message for an exact catalog language tag and key.

func (*MapCatalog) Tags

func (c *MapCatalog) Tags() []language.Tag

Tags returns the supported language tags.

type MessageResolver

type MessageResolver interface {
	ResolveStatusMessage(ctx context.Context, selection StatusMessage, preference LanguagePreference) ResolvedStatusMessage
}

MessageResolver resolves policy-selected status messages at response boundaries.

type ResolvedStatusMessage

type ResolvedStatusMessage struct {
	Text         string
	Language     string
	Key          string
	Localized    bool
	FallbackUsed bool
}

ResolvedStatusMessage contains the rendered response-boundary message.

type Resolver

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

Resolver resolves status messages through one immutable catalog view.

func NewResolver

func NewResolver(catalog Catalog, defaultLanguage string) *Resolver

NewResolver returns a resolver backed by the supplied effective catalog.

func (*Resolver) ResolveStatusMessage

func (r *Resolver) ResolveStatusMessage(_ context.Context, selection StatusMessage, preference LanguagePreference) ResolvedStatusMessage

ResolveStatusMessage resolves an i18n key or returns the bounded fallback text.

type StatusMessage

type StatusMessage struct {
	Text      string
	I18NKey   string
	MaxLength int
}

StatusMessage carries the policy-selected fallback text and optional catalog key.

Jump to

Keyboard shortcuts

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