locale

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LangNB      = "nb"
	LangNN      = "nn"
	LangEN      = "en"
	DefaultLang = LangNB
	CookieName  = "vigil_lang"
)

Variables

This section is empty.

Functions

func FromContext

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

FromContext returns the Localizer stored in ctx, or nil if not set.

func LangFromContext

func LangFromContext(ctx context.Context) string

LangFromContext returns the resolved language tag string, or DefaultLang if not set.

func LangMiddleware

func LangMiddleware(bundle *i18n.Bundle) func(http.Handler) http.Handler

LangMiddleware detects the preferred language via cookie → Accept-Language → default, then injects a *i18n.Localizer into the request context.

func NewBundle

func NewBundle() (*i18n.Bundle, error)

NewBundle loads all embedded locale files and returns a bundle safe for concurrent use.

func SetLocalizer

func SetLocalizer(ctx context.Context, l *i18n.Localizer, lang string) context.Context

SetLocalizer stores both the localizer and the resolved language string in ctx.

func T

func T(ctx context.Context, messageID string, tplData ...map[string]any) string

T translates messageID using the localizer in ctx. Returns messageID as fallback if the localizer is absent or the key is missing.

func TN

func TN(ctx context.Context, messageID string, count int, tplData ...map[string]any) string

TN translates messageID with plural form determined by count. Always injects {"Count": count} into template data so messages can use {{.Count}}.

Types

This section is empty.

Jump to

Keyboard shortcuts

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