lexigo

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromCtx

func FromCtx(ctx context.Context) (language.Tag, bool)

FromCtx retrieves the language tag from the context

func LanguageMiddleware

func LanguageMiddleware(matcher *Matcher) func(http.Handler) http.Handler

LanguageMiddleware inserts the language.Tag into the request context according to "Accept-Language" header

Usage:

func main() {
	// Assuming the package name where the generated locales are is "i18n"
	mux := LanguageMiddleware(i18n.Matcher)(http.DefaultServeMux)
	//...
}

func WithLanguage

func WithLanguage(ctx context.Context, lang language.Tag) context.Context

WithLanguage injects the language.Tag into the context

If the provided value is not a valid language according to language.Parse, an empty value with be injected, in which case creating a locale with the ctx will result in the default tag being used.

func WithLanguageString

func WithLanguageString(ctx context.Context, lang string) (context.Context, error)

WithLanguageString injects the language.Tag corresponding to the given string into the context

Refer to WithLanguage for more info.

Types

type Matcher added in v0.3.2

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

func NewMatcher added in v0.3.2

func NewMatcher(supported []language.Tag, opts ...language.MatchOption) *Matcher

func (*Matcher) Match added in v0.3.2

func (m *Matcher) Match(lang language.Tag) language.Tag

func (*Matcher) MatchAll added in v0.3.2

func (m *Matcher) MatchAll(langs ...language.Tag) language.Tag

Jump to

Keyboard shortcuts

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