localization

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package localization provides experimental locale helpers for templates.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Default is the fallback Localizer used when no localizer is configured.
	Default = Localizer(defaultLocalizer{locale: "en_US"})
)

Functions

func FuncMap

func FuncMap() template.FuncMap

FuncMap returns placeholders for localization template helpers.

func Funcs added in v0.15.0

func Funcs(l Localizer) template.FuncMap

Funcs returns the locale and localizer helpers bound to l, for templates go-partial does not execute, such as the text part of an e-mail written with text/template: they give those templates what the Stage gives the templates go-partial renders.

text := texttemplate.New("mail").Funcs(texttemplate.FuncMap(localization.Funcs(localization.New("nl"))))

func Locale

func Locale(ctx ...*partial.RenderContext) string

Locale returns the configured locale for a render context.

go-doc:sig func() string

func Stage

func Stage() partial.RenderStage

Stage gives templates the locale and localizer helpers. They are made only for the templates that call them.

func WithLocalizer

func WithLocalizer(ctx context.Context, localizer Localizer) context.Context

WithLocalizer stores a Localizer on a context.

Types

type Localizer

type Localizer interface {
	GetLocale() string
}

Localizer provides the active locale for a render.

func FromContext

func FromContext(ctx context.Context) Localizer

FromContext returns the configured Localizer or Default.

func LocalizerValue

func LocalizerValue(ctx ...*partial.RenderContext) Localizer

LocalizerValue returns the configured localizer for a render context.

go-doc:sig func() github.com/donseba/go-partial/exp/localization.Localizer

func New added in v0.15.0

func New(code string) Localizer

New returns a Localizer for the locale code, such as "nl" or "en_US", for renders and templates that have no localizer of their own.

Jump to

Keyboard shortcuts

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