message

package
v0.43.2 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package message connects generated argument structs to i18n through the same typed JSON descriptor used by runtime codecs and client contract exporters.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Definitions

func Definitions(registrations ...Registration) ([]i18n.MessageDefinition, error)

Definitions collects message definitions from a bounded list of valid registrations.

func Describe

func Describe(key i18n.MessageKey, schema contract.Schema, options Options) (i18n.MessageDefinition, error)

Describe derives message parameters from the shared wire graph. Message parameters are required nonnullable text, booleans, integers or exact decimal strings. Floating-point and structured arguments are deliberately rejected.

func Load

func Load(ctx context.Context, source fs.FS, locales i18n.LocaleCatalog, options i18n.CatalogOptions, registrations ...Registration) (*i18n.Catalog, error)

Load loads a catalog from a filesystem and the registered message definitions.

Types

type Description

type Description struct {
	Message   i18n.MessageDefinition `json:"message"`
	Arguments contract.Schema        `json:"arguments"`
}

Description describes a message definition and its typed argument schema.

type Message

type Message[A any] struct {
	// contains filtered or unexported fields
}

Message binds a message definition to a concrete argument codec and resolved properties.

func Define

func Define[A any](key i18n.MessageKey, arguments contract.JSON[A], options Options) Message[A]

Define is the construction boundary emitted by foundry generate. The message signature and per-parameter wire metadata are validated once here.

func (Message[A]) Bind

func (m Message[A]) Bind(ctx context.Context, args A, fallback i18n.Template) (i18n.PreparedMessage, error)

Bind snapshots typed declaration arguments once and validates an English fallback. Returned messages can be shared without retaining the argument object.

func (Message[A]) BindLiteral

func (m Message[A]) BindLiteral(ctx context.Context, args A, text string) (i18n.PreparedMessage, error)

BindLiteral binds typed arguments while retaining a literal fallback.

func (Message[A]) Definition

func (m Message[A]) Definition() (i18n.MessageDefinition, error)

Definition returns a validated definition with an owned parameter slice.

func (Message[A]) Description

func (m Message[A]) Description() (Description, error)

Description returns the message definition and argument schema.

func (Message[A]) Format

func (m Message[A]) Format(ctx context.Context, catalog *i18n.Catalog, locale i18n.LocaleID, args A) (i18n.Result, error)

Format validates and binds typed arguments, then formats the registered message for a supported locale.

func (Message[A]) Key

func (m Message[A]) Key() i18n.MessageKey

Key returns the message key.

func (Message[A]) Registration

func (m Message[A]) Registration() Registration

Registration returns a registration backed by the message's definition.

func (Message[A]) Validate

func (m Message[A]) Validate() error

Validate checks initialization errors, the argument codec, and parameter bindings.

type Options

type Options struct {
	Plural string
	Kind   i18n.PluralKind
}

Options configures a message's plural parameter and pluralization kind.

type Registration

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

Registration erases only the argument type at catalog assembly, not Format.

Jump to

Keyboard shortcuts

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