translation

package
v1.22.3 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2024 License: MIT Imports: 14 Imported by: 17

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ContextKey any = &contextKey{}

Functions

func InitLocales

func InitLocales(ctx context.Context)

InitLocales loads the locales

func Match

func Match(tags ...language.Tag) language.Tag

Match matches accept languages

Types

type LangType

type LangType struct {
	Lang, Name string // these fields are used directly in templates: {{range .AllLangs}}{{.Lang}}{{.Name}}{{end}}
}

LangType represents a lang type

func AllLangs

func AllLangs() []*LangType

AllLangs returns all supported languages sorted by name

type Locale

type Locale interface {
	Language() string
	TrString(string, ...any) string

	Tr(key string, args ...any) template.HTML
	TrN(cnt any, key1, keyN string, args ...any) template.HTML

	PrettyNumber(v any) string
}

Locale represents an interface to translation

func NewLocale

func NewLocale(lang string) Locale

NewLocale return a locale

type MockLocale added in v1.20.0

type MockLocale struct {
	Lang, LangName string // these fields are used directly in templates: ctx.Locale.Lang
}

MockLocale provides a mocked locale without any translations

func (MockLocale) Language added in v1.20.0

func (l MockLocale) Language() string

func (MockLocale) PrettyNumber added in v1.20.0

func (l MockLocale) PrettyNumber(v any) string

func (MockLocale) Tr added in v1.20.0

func (l MockLocale) Tr(s string, args ...any) template.HTML

func (MockLocale) TrN added in v1.20.0

func (l MockLocale) TrN(cnt any, key1, keyN string, args ...any) template.HTML

func (MockLocale) TrString added in v1.22.0

func (l MockLocale) TrString(s string, args ...any) string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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