Documentation ¶
Index ¶
- func GetLanguageFromContext(ctx context.Context) language.Tag
- func GetLanguageFromRequest(r *http.Request) language.Tag
- func NewLanguageContext(ctx context.Context, tag language.Tag) context.Context
- type Cache
- type Group
- func (group *Group) Add(translation *Translation) error
- func (group *Group) Delete(translation *Translation) error
- func (group *Group) GenerateHelper(tag language.Tag) T
- func (group *Group) Get(lang language.Tag, key string) *Translation
- func (group *Group) GetWithLangString(lang string, key string) (*Translation, error)
- func (group *Group) Group(key string) *Group
- func (group *Group) T(lang interface{}, key string) string
- type I18n
- func (i18n *I18n) Add(translation *Translation) error
- func (i18n *I18n) AddSupportedLanguage(tags ...language.Tag) error
- func (i18n *I18n) Close() error
- func (i18n *I18n) Delete(translation *Translation) error
- func (i18n *I18n) GenerateHelper(tag language.Tag) T
- func (i18n *I18n) Get(lang language.Tag, key string) *Translation
- func (i18n *I18n) GetDefaultLanguage() language.Tag
- func (i18n *I18n) GetSupportedLanguages() []language.Tag
- func (i18n *I18n) GetWithLangString(lang string, key string) (*Translation, error)
- func (i18n *I18n) Group(key string) *Group
- func (i18n *I18n) RemoveSupportedLanguage(tag language.Tag) error
- func (i18n *I18n) SetDefaultLanguage(tag language.Tag) error
- func (i18n *I18n) SetRefreshInterval(d time.Duration)
- func (i18n *I18n) Sync() error
- func (i18n *I18n) T(lang interface{}, key string) string
- type Matcher
- type Storage
- type T
- type Translation
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetLanguageFromContext ¶
GetLanguageFromContext returns the language from the context
func GetLanguageFromRequest ¶
GetLanguageFromRequest gets the language from the internal map
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache stores translations in a map for fast access
func (*Cache) Delete ¶
func (cache *Cache) Delete(translation *Translation)
Delete translation from cache
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group is a translation subgroup
func (*Group) Delete ¶
func (group *Group) Delete(translation *Translation) error
Delete translation
func (*Group) GenerateHelper ¶
GenerateHelper generates a method that allways gets tags in a certain language This is usefull for passing to the template engine
func (*Group) Get ¶
func (group *Group) Get(lang language.Tag, key string) *Translation
Get translation
func (*Group) GetWithLangString ¶
func (group *Group) GetWithLangString(lang string, key string) (*Translation, error)
GetWithLangString parses the lang string before lookip up the translation
type I18n ¶
type I18n struct {
// contains filtered or unexported fields
}
I18n defines basic translation get/set methods
func (*I18n) AddSupportedLanguage ¶
AddSupportedLanguage adds a supported language in storage
func (*I18n) GenerateHelper ¶
GenerateHelper generates a method that allways gets tags in a certain language This is usefull for passing to the template engine
func (*I18n) Get ¶
func (i18n *I18n) Get(lang language.Tag, key string) *Translation
Get translation
func (*I18n) GetDefaultLanguage ¶
GetDefaultLanguage gets the default language from storage
func (*I18n) GetSupportedLanguages ¶
GetSupportedLanguages gets the supported languages from storage
func (*I18n) GetWithLangString ¶
func (i18n *I18n) GetWithLangString(lang string, key string) (*Translation, error)
GetWithLangString parses the lang string before lookip up the translation
func (*I18n) RemoveSupportedLanguage ¶
RemoveSupportedLanguage removes a supported language in storage
func (*I18n) SetDefaultLanguage ¶
SetDefaultLanguage sets the default language in storage
func (*I18n) SetRefreshInterval ¶
SetRefreshInterval sets the inerval to sync the translations, 0 means no sync
type Matcher ¶
type Matcher struct {
// contains filtered or unexported fields
}
Matcher get parses languages from http requests
func (*Matcher) Middleware ¶
func (matcher *Matcher) Middleware() scaffold.Middleware
Middleware returns scaffold.Middleware that stores the language in the context redirecting if necessary
type Storage ¶
type Storage interface { GetAll() ([]*Translation, error) Store(*Translation) error Delete(*Translation) error DefaultLanguage() (language.Tag, error) SupportedLanguages() ([]language.Tag, error) SetDefaultLanguage(language.Tag) error StoreSupportedLanguage(language.Tag) error DeleteSupportedLanguage(language.Tag) error }
Storage interface
func NewInMemoryStorage ¶
func NewInMemoryStorage() Storage
NewInMemoryStorage Creates a non persistent in memory translation store