Documentation ¶
Index ¶
- func Handler(ts *Translators, next http.Handler, parsers ...LanguageParser) http.Handler
- func Middleware(ts *Translators, parsers ...LanguageParser) func(http.Handler) http.Handler
- type CookieLanguageParser
- type FileDecoder
- type FileStore
- type HeaderLanguageParser
- type JSONFileDecoder
- type LanguageParser
- type Option
- type Store
- type Translation
- type Translations
- type Translator
- type Translators
- type URLLanguageParser
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Handler ¶
func Handler(ts *Translators, next http.Handler, parsers ...LanguageParser) http.Handler
Handler is a HTTP handler that store the matched translator in request context.
func Middleware ¶
func Middleware(ts *Translators, parsers ...LanguageParser) func(http.Handler) http.Handler
Middleware is a HTTP middleware that store the matched translator in request context.
Types ¶
type CookieLanguageParser ¶
type CookieLanguageParser struct {
// contains filtered or unexported fields
}
CookieLanguageParser returns the language value from cookie.
func NewCookieLanguageParser ¶
func NewCookieLanguageParser(name string) CookieLanguageParser
NewCookieLanguageParser returns a CookieLanguageParser.
type FileDecoder ¶
type FileDecoder interface {
Decode([]byte, *Translation) error
}
FileDecoder is a function that decode file content to tranlation.
type FileStore ¶
type FileStore struct { Directory string Decoder FileDecoder }
FileStore is a file store.
func NewFileStore ¶
func NewFileStore(directory string, decoder FileDecoder) *FileStore
NewFileStore returns a file store with the given directory and decoder.
type HeaderLanguageParser ¶
type HeaderLanguageParser struct { }
HeaderLanguageParser returns the language value from request header.
type JSONFileDecoder ¶
type JSONFileDecoder struct { }
JSONFileDecoder is a JSON file decoder.
func (JSONFileDecoder) Decode ¶
func (d JSONFileDecoder) Decode(data []byte, translation *Translation) error
Decode implements FileDecoder.Decode
type LanguageParser ¶
LanguageParser is an interface that defined how to retrieve language from a request.
type Store ¶
type Store interface {
Get() (Translations, error)
}
Store is where translations located.
type Translations ¶
type Translations map[string]Translation
Translations is a map that mapping from language to translations.
type Translator ¶
Translator is a wrapper of message.Printer.
func GetTranslator ¶
func GetTranslator(r *http.Request) *Translator
GetTranslator returns a translator from request context.
func NewTranslator ¶
func NewTranslator(printer *message.Printer) *Translator
NewTranslator returns a new Translator.
type Translators ¶
Translators is a collections of translator.
func (*Translators) Import ¶
func (ts *Translators) Import(store Store) error
Import imports translations from the given store.
func (*Translators) MatchTranslator ¶
func (ts *Translators) MatchTranslator(langs ...string) *Translator
MatchTranslator returns the matched translator of the given language.
type URLLanguageParser ¶
type URLLanguageParser struct {
// contains filtered or unexported fields
}
URLLanguageParser returns the language value from request URL.
func NewURLLanguageParser ¶
func NewURLLanguageParser(name string) URLLanguageParser
NewURLLanguageParser returns a URLLanguageParser.