go-html/context.go
Virgil 84ad59cd09
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run
feat(context): accept optional locale
Allow callers to seed Locale directly when constructing a rendering context, while preserving the existing no-argument API.

Co-Authored-By: Virgil <virgil@lethean.io>
2026-04-03 16:33:38 +00:00

37 lines
925 B
Go

package html
import i18n "dappco.re/go/core/i18n"
// Context carries rendering state through the node tree.
type Context struct {
Identity string
Locale string
Entitlements func(feature string) bool
Data map[string]any
service *i18n.Service
}
// NewContext creates a new rendering context with sensible defaults.
// An optional locale may be provided as the first argument.
func NewContext(locale ...string) *Context {
ctx := &Context{
Data: make(map[string]any),
}
if len(locale) > 0 {
ctx.Locale = locale[0]
}
return ctx
}
// NewContextWithService creates a rendering context backed by a specific i18n service.
// An optional locale may be provided as the second argument.
func NewContextWithService(svc *i18n.Service, locale ...string) *Context {
ctx := &Context{
Data: make(map[string]any),
service: svc,
}
if len(locale) > 0 {
ctx.Locale = locale[0]
}
return ctx
}