i18n

package
v0.99.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2026 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package i18n provides server-side UI localization for the web module.

Index

Constants

View Source
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 Bundle

func Bundle() *i18n.Bundle

Bundle loads and returns the shared message bundle.

func ClientJSON

func ClientJSON(ctx context.Context) []byte

ClientJSON returns localized client strings as JSON bytes for templ embedding.

func ClientJSONString

func ClientJSONString(ctx context.Context) string

ClientJSONString returns ClientJSON as a string for templ script tags.

func ClientMessages

func ClientMessages(ctx context.Context) map[string]string

ClientMessages returns localized client strings for #flowbot-i18n.

func CookieLang added in v0.99.5

func CookieLang(ctx context.Context) string

CookieLang returns the flowbot-lang cookie value stored on ctx (en or zh).

func DefaultContext

func DefaultContext() context.Context

DefaultContext returns a context with the English UI locale (for tests).

func LangTag

func LangTag(ctx context.Context) string

LangTag returns the BCP 47 tag string for html lang attributes.

func LocalizerForCookie

func LocalizerForCookie(cookie string) *i18n.Localizer

LocalizerForCookie builds a localizer for a flowbot-lang cookie value.

func LocalizerFromContext

func LocalizerFromContext(ctx context.Context) *i18n.Localizer

LocalizerFromContext returns the request localizer or an English default.

func ParseCookie

func ParseCookie(raw string) string

ParseCookie returns a normalized cookie value (en or zh). Unknown values default to en.

func T

func T(ctx context.Context, messageID string) string

T localizes messageID for the request context. Missing keys fall back to English.

func TClient added in v0.99.7

func TClient(ctx context.Context, messageID string) string

TClient returns a client-side i18n template without executing {{.Var}} placeholders. Client JS replaces placeholders locally via flowbotI18n + string replace.

func TData

func TData(ctx context.Context, messageID string, data map[string]any) string

TData localizes messageID with template data (e.g. {{.Name}}). Missing keys fall back to English.

func TDefault

func TDefault(ctx context.Context, messageID, defaultText string) string

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

func TagForCookie(cookie string) language.Tag

TagForCookie maps a cookie value to a BCP 47 language tag.

func WithCookieLang added in v0.99.5

func WithCookieLang(ctx context.Context, cookie string) context.Context

WithCookieLang attaches a flowbot-lang cookie value and its localizer to ctx.

func WithLocalizer

func WithLocalizer(ctx context.Context, loc *i18n.Localizer) context.Context

WithLocalizer returns a context carrying loc for T and ClientJSON.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL