Documentation
¶
Overview ¶
Package i18n provides internationalization as core framework infrastructure.
The middleware detects the user's locale from the Accept-Language header and stores a localizer in the request context.
Use T for simple message translation, TData for messages with template data, and TPlural for messages with plural support. All three fall back to the message key if no localizer is present.
Locale returns the current locale string, defaulting to "en".
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func T ¶
T translates a message by ID using the localizer from context. Falls back to the message ID if no localizer is present.
Types ¶
type Bundle ¶
type Bundle struct {
// contains filtered or unexported fields
}
Bundle manages i18n translation bundles and locale matching. It is created and managed by the Server; apps should not create it directly.
func NewBundle ¶
NewBundle creates a new i18n Bundle with the given default language and supported languages. It loads built-in validation translations automatically.
func NewTestBundle ¶
NewTestBundle creates a minimal i18n Bundle for use in tests. It initializes the bundle with the given default language and English+German support, and loads translations from the given filesystems. This avoids the need for Server-based configuration.
func (*Bundle) AddTranslations ¶
AddTranslations loads translation files from an fs.FS. Files must be in a "translations/" directory matching "translations/*.toml".
func (*Bundle) LocaleMiddleware ¶
LocaleMiddleware returns HTTP middleware that detects the user's locale from the Accept-Language header and stores it in the request context.
func (*Bundle) RequestFuncMap ¶
RequestFuncMap returns context-scoped template functions for translations.