i18n

package
v0.0.0-...-932f57c Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

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 PT

func PT(ctx context.Context, module ModuleKey, prefix string, key string, args ...string) (r string)

func PTFk

func PTFk(ctx context.Context, module ModuleKey, fFieldKey func() string, key string, args ...string) (r string)

func RegisterTimeLayoutFormatterAlias

func RegisterTimeLayoutFormatterAlias(from TimeLayout, to ...TimeLayout)

func T

func T(ctx context.Context, module ModuleKey, key string, args ...string) (r string)

func Translate

func Translate(t Translator, ctx context.Context, key string, args ...string) string

func TranslateD

func TranslateD(t Translator, defaul func() string, ctx context.Context, key string, args ...string) (s string)

func TranslateHandler

func TranslateHandler(t Translator, ctx context.Context) func(key string, args ...string) string

Types

type Builder

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

func New

func New() *Builder

func (*Builder) EnsureLanguage

func (b *Builder) EnsureLanguage(in http.Handler) (out http.Handler)

func (*Builder) GetCookieName

func (b *Builder) GetCookieName() string

func (*Builder) GetCurrentLangFromCookie

func (b *Builder) GetCurrentLangFromCookie(r *http.Request) (lang string)

func (*Builder) GetModuleMessages

func (b *Builder) GetModuleMessages(lang language.Tag, module ModuleKey) any

func (*Builder) GetQueryName

func (b *Builder) GetQueryName() string

func (*Builder) GetSupportLanguages

func (b *Builder) GetSupportLanguages() []language.Tag

func (*Builder) GetSupportLanguagesFromRequest

func (b *Builder) GetSupportLanguagesFromRequest(R *http.Request) []language.Tag

func (*Builder) GetSupportLanguagesFromRequestFunc

func (b *Builder) GetSupportLanguagesFromRequestFunc(v func(R *http.Request) []language.Tag) (r *Builder)

func (*Builder) RegisterForModule

func (b *Builder) RegisterForModule(lang language.Tag, module ModuleKey, msg Messages) (r *Builder)

func (*Builder) RegisterForModules

func (b *Builder) RegisterForModules(lang language.Tag, args ...any) (r *Builder)

func (*Builder) SupportLanguage

func (b *Builder) SupportLanguage(vs ...language.Tag) (r *Builder)

func (*Builder) SupportLanguages

func (b *Builder) SupportLanguages(vs ...language.Tag) (r *Builder)

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 Fallback

type Fallback func(ctx context.Context, key string, args ...string) (v string, ok bool)

func (Fallback) Fallback

func (f Fallback) Fallback(ctx context.Context, key string, args ...string) (string, bool)

func (Fallback) Translate

func (f Fallback) Translate(ctx context.Context, key string, args ...string) (string, bool)

type FallbackTranslator

type FallbackTranslator interface {
	Translator
	Fallback(ctx context.Context, key string, args ...string) (v string, ok bool)
}

type Messages

type Messages interface{}

func MustGetModuleMessages

func MustGetModuleMessages(ctx context.Context, module ModuleKey, defaultMessages Messages) Messages

type ModuleKey

type ModuleKey string
const DefaultKey ModuleKey = "i18n:default"

type TimeFormatHandler

type TimeFormatHandler func(ctx context.Context) func(t time.Time) string

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 (*TimeFormatLeveled) Of

func (*TimeFormatLeveled) Short

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 TimeLayoutFormatter interface {
	Formatter(m *DefaultMessages, ctx context.Context) func(t time.Time) string
}

type TimeLayoutFunc

type TimeLayoutFunc func(m *DefaultMessages, ctx context.Context) func(t time.Time) string

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

type TimeLayoutString

type TimeLayoutString string

func (TimeLayoutString) Formatter

type TranslateFunc

type TranslateFunc func(ctx context.Context, key string, args ...string) (v string, ok bool)

func (TranslateFunc) Translate

func (f TranslateFunc) Translate(ctx context.Context, key string, args ...string) (string, bool)

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

func (Translators) Fallback

func (ts Translators) Fallback(ctx context.Context, key string, args ...string) (s string, ok bool)

func (Translators) Translate

func (ts Translators) Translate(ctx context.Context, key string, args ...string) (v string, ok bool)

Directories

Path Synopsis
csv

Jump to

Keyboard shortcuts

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