Documentation
¶
Overview ¶
Package i18n provides internationalization support for the framework.
Index ¶
- func Configure(cfg *Config)
- func ContextWithI18nPrinter(ctx context.Context, printer *message.Printer) context.Context
- func GetI18nPrinter(langTag language.Tag) *message.Printer
- func PrinterFromContext(ctx context.Context) (*message.Printer, bool)
- type Config
- type MessageEntry
- type MessageFile
- type Placeholder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Configure ¶
func Configure(cfg *Config)
Configure initializes the internationalization system with the provided configuration. It sets up the filesystem and base path for locale files, then loads all message catalogs. Panics if locales directory or filesystem is missing.
func ContextWithI18nPrinter ¶
ContextWithI18nPrinter adds the message printer to the context ContextWithI18nPrinter stores a message printer in the context. Returns a new context containing the printer, which can be retrieved later with PrinterFromContext.
func GetI18nPrinter ¶
GetI18nPrinter creates a message printer for the given language tag GetI18nPrinter creates a message printer for the specified language tag. The printer can be used to translate messages according to the loaded message catalogs. Returns a printer configured for the given language tag.
Types ¶
type Config ¶
Config holds i18n configuration.
func Configuration ¶
Configuration returns the current i18n configuration. Returns the config and true if i18n is configured, or an empty config and false if not configured.
type MessageEntry ¶
type MessageEntry struct {
Placeholders map[string]Placeholder `json:"placeholders,omitempty"`
ID string `json:"id"`
Message string `json:"message"`
Translation string `json:"translation,omitempty"`
}
MessageEntry represents a single message with its translations and placeholders.
type MessageFile ¶
type MessageFile struct {
Language string `json:"language"`
Messages []MessageEntry `json:"messages"`
}
MessageFile represents the structure of the JSON message files.