i18n

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const ModuleID = "i18n"

Variables

This section is empty.

Functions

func DetectLanguage

func DetectLanguage(service LanguageService, resolver ProfileLanguageResolver) echo.MiddlewareFunc

func LanguageFromContext

func LanguageFromContext(ctx context.Context) string

func LanguageSwitcherURL

func LanguageSwitcherURL(currentURL string, lang string) string

LanguageSwitcherURL preserves current route/query while switching the `lang` query value.

func LocaleDir

func LocaleDir() string

func New

func New(cfg *config.Config) core.I18n

func WithLanguage

func WithLanguage(ctx context.Context, lang string) context.Context

Types

type LanguageService

type LanguageService interface {
	DefaultLanguage() string
	NormalizeLanguage(raw string) string
}

type Module

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

func NewModule

func NewModule(service *Service) *Module

func (*Module) ID

func (m *Module) ID() string

func (*Module) Service

func (m *Module) Service() *Service

type Options

type Options struct {
	LocaleDir       string
	DefaultLanguage string
}

type ProfileLanguageResolver

type ProfileLanguageResolver interface {
	PreferredLanguage(ctx context.Context, userID int) (lang string, ok bool, err error)
	SetPreferredLanguage(ctx context.Context, userID int, lang string) error
}

type Service

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

func NewService

func NewService(opts Options) (*Service, error)

func (*Service) DefaultLanguage

func (s *Service) DefaultLanguage() string

func (*Service) NormalizeLanguage

func (s *Service) NormalizeLanguage(raw string) string

func (*Service) SupportedLanguages

func (s *Service) SupportedLanguages() []string

func (*Service) T

func (s *Service) T(ctx context.Context, key string, templateData ...map[string]any) string

func (*Service) TC

func (s *Service) TC(ctx context.Context, key string, count any, templateData ...map[string]any) string

func (*Service) TS

func (s *Service) TS(ctx context.Context, key string, choice string, templateData ...map[string]any) string

Directories

Path Synopsis
views
gen
templ: version: v0.3.1001
templ: version: v0.3.1001

Jump to

Keyboard shortcuts

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