Documentation
¶
Overview ¶
Package localization provides go-i18n middleware for HTTP services.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetLocalizer ¶
GetLocalizer returns the *i18n.Localizer stored by Middleware, or nil if not set.
func Localize ¶
func Localize(ctx context.Context, cfg *i18n.LocalizeConfig) string
Localize translates cfg using the Localizer from ctx (set by Middleware). If no localizer is in the context or the message is not found, returns cfg.DefaultMessage.Other, or "" if DefaultMessage is nil.
func Middleware ¶
Middleware selects a locale from the request (priority: cookie -> query param -> Accept-Language), builds an *i18n.Localizer from bundle, and stores it in the context. Use GetLocalizer or Localize to retrieve translations in handlers. bundle must not be nil.
Types ¶
type Option ¶
type Option func(*config)
Option configures the localization middleware.
func WithLanguageCookie ¶
WithLanguageCookie sets a cookie name (e.g. "lang") used as language preference, checked first.
func WithLanguageQueryParam ¶
WithLanguageQueryParam sets a URL query parameter name (e.g. "lang") used as language preference, checked after cookie but before Accept-Language header.