Documentation
¶
Overview ¶
Package localization contains transport-neutral policy message localization.
Index ¶
- Variables
- func NewEffectiveCatalog(system Catalog, overlays ...CatalogOverlay) (*EffectiveCatalog, []CatalogOverride, error)
- type Catalog
- type CatalogBuilder
- type CatalogOverlay
- type CatalogOverride
- type CatalogRegistry
- func (r *CatalogRegistry) Active() *EffectiveCatalog
- func (r *CatalogRegistry) RegisterOverlay(overlay CatalogOverlay) ([]CatalogOverride, error)
- func (r *CatalogRegistry) RegisterOverlays(overlays ...CatalogOverlay) ([]CatalogOverride, error)
- func (r *CatalogRegistry) Reload(overlays ...CatalogOverlay) ([]CatalogOverride, error)
- func (r *CatalogRegistry) ValidateAdditionalOverlays(overlays ...CatalogOverlay) ([]CatalogOverride, error)
- type CatalogStore
- type EffectiveCatalog
- type LanguagePreference
- type ManagerCatalog
- type MapCatalog
- type MessageResolver
- type RegistryResolver
- type ResolvedStatusMessage
- type Resolver
- type StatusMessage
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 deployment overlays only after the complete catalog builds successfully.
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 ¶
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 ¶
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) 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 RegistryResolver ¶
type RegistryResolver struct {
// contains filtered or unexported fields
}
RegistryResolver resolves against the currently active immutable catalog.
func NewRegistryResolver ¶
func NewRegistryResolver(registry *CatalogRegistry, defaultLanguage string) *RegistryResolver
NewRegistryResolver returns a resolver that reads the active catalog per call.
func (*RegistryResolver) ResolveStatusMessage ¶
func (r *RegistryResolver) ResolveStatusMessage( ctx context.Context, selection StatusMessage, preference LanguagePreference, ) ResolvedStatusMessage
ResolveStatusMessage resolves through the registry's currently active catalog.
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 ¶
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 ¶
StatusMessage carries the policy-selected fallback text and optional catalog key.