translation

package
v0.0.0-...-77b0776 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetUserLocalesForContext

func GetUserLocalesForContext(ctx context.Context) []string

GetUserLocalesForContext finds the user locales from the context.

func LocaleForContext

func LocaleForContext(ctx context.Context) string

LocaleForContext finds the locale from the context.

func ParseAcceptLanguageMiddleware

func ParseAcceptLanguageMiddleware(next http.Handler) http.Handler

ParseAcceptLanguageMiddleware parses the Accept-Language http header

Types

type Translator

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

Translator handles translations

func NewTranslator

func NewTranslator(path string, locales []string) *Translator

NewTranslator instanciates a new Translator struct. Locales should be passed by priority order. First locale will be the default one. First locale for a specific language will be the default for this language.

func (*Translator) Get

func (t *Translator) Get(key string, locales []string) string

Get gets the translation for a given key and locales ordered by preference. The first match returns. Fallback to the default locale if the ones given does not exist

func (*Translator) GetForContext

func (t *Translator) GetForContext(ctx context.Context, key string) string

GetForContext gets the translation for a given key and context. Same logic as Get().

type TranslatorInterface

type TranslatorInterface interface {
	Get(key string, locales []string) string
	GetForContext(ctx context.Context, key string) string
}

TranslatorInterface should be implemented by Translator struct

Jump to

Keyboard shortcuts

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