i18n

package
v0.0.1-0...-104a2d1 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2025 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func I18nMiddleware

func I18nMiddleware(i18n *I18n, languageExtractor func(*http.Request) string) func(http.Handler) http.Handler

func T

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

T translates a message using i18n instance from context

Types

type Config

type Config struct {
	DefaultLanguage string
	LocalesDir      string
}

Config holds configuration for i18n initialization

type I18Key

type I18Key string
const (
	// I18nContextKey is the key used to store the i18n translator in the context
	I18nContextKey I18Key = "i18n"
	// LangContextKey is the key used to store the current language in the context
	LangContextKey I18Key = "lang"
)

type I18n

type I18n struct {
	// contains filtered or unexported fields
}

I18n is a wrapper around github.com/nicksnyder/go-i18n

func FromContext

func FromContext(ctx context.Context) (*I18n, string)

FromContext retrieves the i18n instance from the request context

func New

func New(config Config) (*I18n, error)

New creates a new i18n instance

func (*I18n) GetLocalizer

func (i *I18n) GetLocalizer(lang string) *i18n.Localizer

GetLocalizer returns a localizer for the given language

func (*I18n) T

func (i *I18n) T(lang, messageID string, templateData map[string]interface{}) string

T translates a message using a language, message ID, and optional template data

Jump to

Keyboard shortcuts

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