Documentation
¶
Overview ¶
Package i18n provides dependency-free typed message catalog helpers.
Index ¶
- func Format(message string, vars map[string]string) string
- type Bundle
- type Catalog
- func (catalog Catalog[K]) Format(key K, vars map[string]string) (string, bool)
- func (catalog Catalog[K]) Message(key K) (string, bool)
- func (catalog Catalog[K]) MissingKeys(keys []K) []K
- func (catalog Catalog[K]) Must(key K) string
- func (catalog Catalog[K]) MustFormat(key K, vars map[string]string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Bundle ¶
type Bundle[K comparable] struct { DefaultLocale string Catalogs map[string]Catalog[K] }
Bundle stores catalogs by locale code.
type Catalog ¶
type Catalog[K comparable] struct { Locale string Messages map[K]string }
Catalog maps typed keys to localized messages for one locale.
func NewCatalog ¶
func NewCatalog[K comparable](locale string, messages map[K]string) Catalog[K]
NewCatalog creates a catalog with a defensive message copy.
func (Catalog[K]) Format ¶
Format replaces {name} placeholders in the keyed message. Missing variables are left intact so callers can detect incomplete data in tests.
func (Catalog[K]) MissingKeys ¶
func (catalog Catalog[K]) MissingKeys(keys []K) []K
MissingKeys reports typed keys absent from the catalog.
Click to show internal directories.
Click to hide internal directories.