Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrTranslationNotFound = errors.New("translation not found")
Functions ¶
func SetDefaultFactory ¶
func SetDefaultFactory(f LangFactory)
Types ¶
type DefaultTemplateFactory ¶
type DefaultTemplateFactory struct{}
DefaultTemplateFactory - provides `text/template` templates if it detects a placeholder, or directly returns the string from the config
func (*DefaultTemplateFactory) GetTemplate ¶
type LangFactory ¶
type LangFactory interface {
Lang(code string) LangSource
}
func NewLangFactory ¶
func NewLangFactory(tf TemplateFactory, files ...*LangFile) (LangFactory, error)
type LangFile ¶
func ValuesToLangFile ¶
type LangSource ¶
type LangSource interface { Get(key string, ctx ...any) *Result GetFirst(key []string, ctx ...any) *Result Msg(*Message) *Result }
LangSource searches for a translation to the given key
func Lang ¶
func Lang(code string) LangSource
type LoadOptions ¶
type LoadOptions interface { // TemplateFactory sets which factory will provide the templates // that will be returned in the end. Default is DefaultTemplateFactory TemplateFactory(tf TemplateFactory) LoadOptions // AddFiles accepts a list of files to be parsed. // They need to at least have the language property defined in them. // If adding multiple files for the same language, their fallback language MUST match. // The 'language' and 'fallback' settings could be moved to a separate file in the future. AddFiles(file ...string) LoadOptions // AsDefault sets the configured factory from Build as the default factory to be used by the global methods available AsDefault() error // Build configures and returns the lang factory Build() (LangFactory, error) }
func Setup ¶
func Setup() LoadOptions
type LookupSource ¶
type LookupSource struct {
// contains filtered or unexported fields
}
func NewLookupSource ¶
func NewLookupSource(parent LangSource, configs ConfigMap) *LookupSource
func (*LookupSource) GetFirst ¶ added in v0.0.4
func (l *LookupSource) GetFirst(keys []string, ctx ...any) *Result
func (*LookupSource) Msg ¶
func (l *LookupSource) Msg(m *Message) *Result
type TemplateFactory ¶
type TemplateFactory interface { // GetTemplate - provides the template GetTemplate(lang string, path []string, entry string) (Template, error) }
TemplateFactory provides templates based on the lang, key and value in the config This allows setting custom template resolving when needed
Click to show internal directories.
Click to hide internal directories.