Documentation
¶
Overview ¶
Package i18n provides server-side UI localization for the web module.
Index ¶
- Constants
- func Bundle() *i18n.Bundle
- func ClientJSON(ctx context.Context) []byte
- func ClientJSONString(ctx context.Context) string
- func ClientMessages(ctx context.Context) map[string]string
- func CookieLang(ctx context.Context) string
- func DefaultContext() context.Context
- func LangTag(ctx context.Context) string
- func LocalizerForCookie(cookie string) *i18n.Localizer
- func LocalizerFromContext(ctx context.Context) *i18n.Localizer
- func ParseCookie(raw string) string
- func T(ctx context.Context, messageID string) string
- func TClient(ctx context.Context, messageID string) string
- func TData(ctx context.Context, messageID string, data map[string]any) string
- func TDefault(ctx context.Context, messageID, defaultText string) string
- func TagForCookie(cookie string) language.Tag
- func WithCookieLang(ctx context.Context, cookie string) context.Context
- func WithLocalizer(ctx context.Context, loc *i18n.Localizer) context.Context
Constants ¶
const ( // CookieName is the browser cookie storing UI locale preference. CookieName = "flowbot-lang" // CookieEN and CookieZH are accepted cookie values. CookieEN = "en" CookieZH = "zh" )
Variables ¶
This section is empty.
Functions ¶
func ClientJSON ¶
ClientJSON returns localized client strings as JSON bytes for templ embedding.
func ClientJSONString ¶
ClientJSONString returns ClientJSON as a string for templ script tags.
func ClientMessages ¶
ClientMessages returns localized client strings for #flowbot-i18n.
func CookieLang ¶ added in v0.99.5
CookieLang returns the flowbot-lang cookie value stored on ctx (en or zh).
func DefaultContext ¶
DefaultContext returns a context with the English UI locale (for tests).
func LocalizerForCookie ¶
LocalizerForCookie builds a localizer for a flowbot-lang cookie value.
func LocalizerFromContext ¶
LocalizerFromContext returns the request localizer or an English default.
func ParseCookie ¶
ParseCookie returns a normalized cookie value (en or zh). Unknown values default to en.
func TClient ¶ added in v0.99.7
TClient returns a client-side i18n template without executing {{.Var}} placeholders. Client JS replaces placeholders locally via flowbotI18n + string replace.
func TData ¶
TData localizes messageID with template data (e.g. {{.Name}}). Missing keys fall back to English.
func TDefault ¶
TDefault localizes messageID for the active locale; when the key is absent, returns defaultText. Use for catalog copy (e.g. config field docs) where English godoc is the source of truth.
func TagForCookie ¶
TagForCookie maps a cookie value to a BCP 47 language tag.
func WithCookieLang ¶ added in v0.99.5
WithCookieLang attaches a flowbot-lang cookie value and its localizer to ctx.
Types ¶
This section is empty.