Documentation
¶
Index ¶
- Constants
- Variables
- func PT(ctx context.Context, module ModuleKey, prefix string, key string, ...) (r string)
- func PTFk(ctx context.Context, module ModuleKey, fFieldKey func() string, key string, ...) (r string)
- func RegisterTimeLayoutFormatterAlias(from TimeLayout, to ...TimeLayout)
- func T(ctx context.Context, module ModuleKey, key string, args ...string) (r string)
- func Translate(t Translator, ctx context.Context, key string, args ...string) string
- func TranslateD(t Translator, defaul func() string, ctx context.Context, key string, ...) (s string)
- func TranslateHandler(t Translator, ctx context.Context) func(key string, args ...string) string
- type Builder
- func (b *Builder) EnsureLanguage(in http.Handler) (out http.Handler)
- func (b *Builder) GetCookieName() string
- func (b *Builder) GetCurrentLangFromCookie(r *http.Request) (lang string)
- func (b *Builder) GetModuleMessages(lang language.Tag, module ModuleKey) any
- func (b *Builder) GetQueryName() string
- func (b *Builder) GetSupportLanguages() []language.Tag
- func (b *Builder) GetSupportLanguagesFromRequest(R *http.Request) []language.Tag
- func (b *Builder) GetSupportLanguagesFromRequestFunc(v func(R *http.Request) []language.Tag) (r *Builder)
- func (b *Builder) RegisterForModule(lang language.Tag, module ModuleKey, msg Messages) (r *Builder)
- func (b *Builder) RegisterForModules(lang language.Tag, args ...any) (r *Builder)
- func (b *Builder) SupportLanguage(vs ...language.Tag) (r *Builder)
- func (b *Builder) SupportLanguages(vs ...language.Tag) (r *Builder)
- type DefaultMessages
- type DynaBuilder
- type ErrorString
- type Fallback
- type FallbackTranslator
- type Messages
- type ModuleKey
- type TimeFormatHandler
- type TimeFormatLevel
- type TimeFormatLeveled
- type TimeFormatsMap
- func (m TimeFormatsMap) Add(name TimeLayout, formatter TimeLayoutFormatter)
- func (m TimeFormatsMap) AddFunc(name TimeLayout, formatter TimeLayoutFunc)
- func (m TimeFormatsMap) AddFuncs(f func(add func(name TimeLayout, formatter TimeLayoutFunc)))
- func (m TimeFormatsMap) AddLayout(name TimeLayout, layout string)
- func (m TimeFormatsMap) AddLayouts(f func(add func(name TimeLayout, layout string)))
- func (m TimeFormatsMap) Get(layout TimeLayout, fallback ...TimeLayout) (f TimeLayoutFormatter)
- type TimeLayout
- type TimeLayoutFormat
- type TimeLayoutFormatter
- type TimeLayoutFunc
- type TimeLayoutSpec
- type TimeLayoutString
- type TranslateFunc
- type Translator
- type Translators
Constants ¶
View Source
const ( PtDateDefaultFormat = "pt:date:default" PtDateShortFormat = "pt:date:short" PtDateFullFormat = "pt:date:full" PtTimeDefaultFormat = "pt:time:default" PtTimeShortFormat = "pt:time:short" PtTimeFullFormat = "pt:time:full" PtDateTimeDefaultFormat = "pt:datetime:default" PtDateTimeShortFormat = "pt:datetime:short" PtDateTimeFullFormat = "pt:datetime:full" )
View Source
const ( TimeFormatDefault TimeFormatLevel = iota TimeFormatShort TimeFormatFull DefaultTimeFormatter TimeLayoutString = "15:04:05" DefaultDateFormatter TimeLayoutString = "2006-01-02" DefaultDateTimeFormatter TimeLayoutString = "2006-01-02 15:04:05" )
Variables ¶
View Source
var Default_en = &DefaultMessages{
True: "True",
False: "False",
Yes: "Yes",
No: "No",
}
View Source
var Default_pt_BR = &DefaultMessages{ True: "Verdadeiro", False: "Falso", Yes: "Sim", No: "Não", DateLayout: TimeLayoutSpec{ Default: PtDateDefaultFormat, Short: PtDateShortFormat, Full: PtDateFullFormat, }, TimeLayout: TimeLayoutSpec{ Default: PtTimeDefaultFormat, Short: PtTimeShortFormat, Full: PtTimeFullFormat, }, DateTimeLayout: TimeLayoutSpec{ Default: PtDateTimeDefaultFormat, Short: PtDateTimeShortFormat, Full: PtDateTimeFullFormat, }, }
View Source
var TimeFormats = TimeFormatsMap{}
Functions ¶
func RegisterTimeLayoutFormatterAlias ¶
func RegisterTimeLayoutFormatterAlias(from TimeLayout, to ...TimeLayout)
func TranslateD ¶
func TranslateHandler ¶
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
func (*Builder) EnsureLanguage ¶
func (*Builder) GetCookieName ¶
func (*Builder) GetCurrentLangFromCookie ¶
func (*Builder) GetModuleMessages ¶
func (*Builder) GetQueryName ¶
func (*Builder) GetSupportLanguages ¶
func (*Builder) GetSupportLanguagesFromRequest ¶
func (*Builder) GetSupportLanguagesFromRequestFunc ¶
func (*Builder) RegisterForModule ¶
func (*Builder) RegisterForModules ¶
func (*Builder) SupportLanguage ¶
type DefaultMessages ¶
type DefaultMessages struct { MonthNames [13]string AbbrMonthNames [13]string TimeLayout TimeLayoutSpec DateLayout TimeLayoutSpec DateTimeLayout TimeLayoutSpec True string False string Yes string No string }
func GetMessages ¶
func GetMessages(ctx context.Context) *DefaultMessages
func (*DefaultMessages) DateFormatter ¶
func (m *DefaultMessages) DateFormatter() *TimeFormatLeveled
func (*DefaultMessages) DateTimeFormatter ¶
func (m *DefaultMessages) DateTimeFormatter() *TimeFormatLeveled
func (*DefaultMessages) TimeFormatter ¶
func (m *DefaultMessages) TimeFormatter() *TimeFormatLeveled
func (*DefaultMessages) TrueOrFalse ¶
func (m *DefaultMessages) TrueOrFalse(v bool) string
func (*DefaultMessages) YesOrNo ¶
func (m *DefaultMessages) YesOrNo(v bool) string
type DynaBuilder ¶
type DynaBuilder struct {
// contains filtered or unexported fields
}
func DynaNew ¶
func DynaNew() (r *DynaBuilder)
func (*DynaBuilder) HaveMissingKeys ¶
func (d *DynaBuilder) HaveMissingKeys() bool
func (*DynaBuilder) Language ¶
func (d *DynaBuilder) Language(lang string) (r *DynaBuilder)
func (*DynaBuilder) PrettyMissingKeys ¶
func (d *DynaBuilder) PrettyMissingKeys() string
type ErrorString ¶
type ErrorString string
func (ErrorString) Error ¶
func (e ErrorString) Error() string
type FallbackTranslator ¶
type FallbackTranslator interface { Translator Fallback(ctx context.Context, key string, args ...string) (v string, ok bool) }
func TranslatorWithFallback ¶
func TranslatorWithFallback(t TranslateFunc, f TranslateFunc) FallbackTranslator
type TimeFormatLevel ¶
type TimeFormatLevel uint8
type TimeFormatLeveled ¶
type TimeFormatLeveled struct {
// contains filtered or unexported fields
}
func (*TimeFormatLeveled) Default ¶
func (h *TimeFormatLeveled) Default() TimeFormatHandler
func (*TimeFormatLeveled) Full ¶
func (h *TimeFormatLeveled) Full() TimeFormatHandler
func (*TimeFormatLeveled) Of ¶
func (h *TimeFormatLeveled) Of(level TimeFormatLevel) TimeFormatHandler
func (*TimeFormatLeveled) Short ¶
func (h *TimeFormatLeveled) Short() TimeFormatHandler
type TimeFormatsMap ¶
type TimeFormatsMap map[TimeLayout]*TimeLayoutFormat
func (TimeFormatsMap) Add ¶
func (m TimeFormatsMap) Add(name TimeLayout, formatter TimeLayoutFormatter)
func (TimeFormatsMap) AddFunc ¶
func (m TimeFormatsMap) AddFunc(name TimeLayout, formatter TimeLayoutFunc)
func (TimeFormatsMap) AddFuncs ¶
func (m TimeFormatsMap) AddFuncs(f func(add func(name TimeLayout, formatter TimeLayoutFunc)))
func (TimeFormatsMap) AddLayout ¶
func (m TimeFormatsMap) AddLayout(name TimeLayout, layout string)
func (TimeFormatsMap) AddLayouts ¶
func (m TimeFormatsMap) AddLayouts(f func(add func(name TimeLayout, layout string)))
func (TimeFormatsMap) Get ¶
func (m TimeFormatsMap) Get(layout TimeLayout, fallback ...TimeLayout) (f TimeLayoutFormatter)
type TimeLayout ¶
type TimeLayout string
type TimeLayoutFormat ¶
type TimeLayoutFormat struct { Name string Formatter TimeLayoutFormatter }
type TimeLayoutFormatter ¶
type TimeLayoutFunc ¶
func (TimeLayoutFunc) Formatter ¶
func (f TimeLayoutFunc) Formatter(m *DefaultMessages, ctx context.Context) func(t time.Time) string
type TimeLayoutSpec ¶
type TimeLayoutSpec struct { Default TimeLayout Short TimeLayout Full TimeLayout }
func (*TimeLayoutSpec) FromLevel ¶
func (s *TimeLayoutSpec) FromLevel(level TimeFormatLevel) TimeLayout
func (*TimeLayoutSpec) Level ¶
func (s *TimeLayoutSpec) Level(level TimeFormatLevel) TimeLayoutFormatter
type TimeLayoutString ¶
type TimeLayoutString string
func (TimeLayoutString) Formatter ¶
func (l TimeLayoutString) Formatter(*DefaultMessages, context.Context) func(t time.Time) string
type TranslateFunc ¶
type Translator ¶
type Translator interface {
Translate(ctx context.Context, key string, args ...string) (v string, ok bool)
}
func ModuleTranslator ¶
func ModuleTranslator(module ModuleKey, allowEmpty bool, fFieldKey func(key string) string) Translator
func WrapFallback ¶
func WrapFallback(t Translator, f func(old TranslateFunc) TranslateFunc) Translator
type Translators ¶
type Translators []Translator
func (Translators) Append ¶
func (ts Translators) Append(translators ...Translator) Translators
Source Files
¶
Click to show internal directories.
Click to hide internal directories.