i18n

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLanguageFromContext

func GetLanguageFromContext(ctx context.Context) string

GetLanguageFromContext extracts the language from the request context

func LanguageMiddleware

func LanguageMiddleware() gin.HandlerFunc

LanguageMiddleware detects the user's language preference and sets it in context

func SetLanguage

func SetLanguage(lang string) error

SetLanguage sets the global language

func T

func T(key string) string

T is a convenience function for the global localizer

func TFromContext

func TFromContext(ctx context.Context, key string) string

TFromContext translates a key using the language from context

func TWithData

func TWithData(key string, data map[string]string) string

TWithData is a convenience function for the global localizer

func TWithDataFromContext

func TWithDataFromContext(ctx context.Context, key string, data map[string]string) string

TWithDataFromContext translates a key with data using the language from context

Types

type Localizer

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

Localizer handles translation lookups

func New

func New(lang string) (*Localizer, error)

New creates a new localizer for the given language

func (*Localizer) Lang

func (l *Localizer) Lang() string

Lang returns the current language

func (*Localizer) T

func (l *Localizer) T(key string) string

T translates a key path like "backend.auth.invalid_credentials"

func (*Localizer) TWithData

func (l *Localizer) TWithData(key string, data map[string]string) string

TWithData translates a key with template data for interpolation

Jump to

Keyboard shortcuts

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