Documentation ¶
Index ¶
- type JSONDriver
- func (this *JSONDriver) Load() error
- func (this *JSONDriver) Register(locale string, key string, message string)
- func (this JSONDriver) Resolve(locale string, key string) string
- func (this JSONDriver) ResolveStruct(s any, locale string, key string, field string) string
- func (this JSONDriver) Translate(locale string, key string, placeholders map[string]string) string
- func (this JSONDriver) TranslateStruct(s any, locale string, key string, field string, placeholders map[string]string) string
- type Translatable
- type Translator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type JSONDriver ¶
type JSONDriver struct {
// contains filtered or unexported fields
}
JSONDriver json driver
func (*JSONDriver) Load ¶
func (this *JSONDriver) Load() error
Load load translations file to memory
func (*JSONDriver) Register ¶
func (this *JSONDriver) Register(locale string, key string, message string)
Register new translation message for locale Use placeholder in message for field name @example: t.Register("en", "welcome", "Hello {name}, welcome!")
func (JSONDriver) Resolve ¶
func (this JSONDriver) Resolve(locale string, key string) string
Resolve find translation for locale if no translation found for locale return fallback translation or nil
func (JSONDriver) ResolveStruct ¶
ResolveStruct find translation from translatable if empty string returned from translatable or struct not translatable, default translation will resolved
func (JSONDriver) Translate ¶
Translate get translation for locale @example: t.Translate("en", "welcome", map[string]string{ "name": "John" })
func (JSONDriver) TranslateStruct ¶
func (this JSONDriver) TranslateStruct(s any, locale string, key string, field string, placeholders map[string]string) string
TranslateStruct translate using translatable interface if empty string returned from translatable or struct not translatable, default translation will resolved Caution: use non-pointer implemantation for struct
type Translatable ¶
Translatable interface for struct
type Translator ¶
type Translator interface { // Register new translation message for locale // Use placeholder in message for field name // @example: // t.Register("en", "welcome", "Hello {name}, welcome!") Register(locale string, key string, message string) // Resolve find translation for locale // if no translation found for locale return fallback translation or nil Resolve(locale string, key string) string // ResolveStruct find translation from translatable // if empty string returned from translatable or struct not translatable, default translation will resolved ResolveStruct(s any, locale string, key string, field string) string // Translate get translation for locale // @example: // t.Translate("en", "welcome", map[string]string{ "name": "John" }) Translate(locale string, key string, placeholders map[string]string) string // TranslateStruct translate using translatable interface // if empty string returned from translatable or struct not translatable, default translation will resolved // Caution: use non-pointer implemantation for struct TranslateStruct(s any, locale string, key string, field string, placeholders map[string]string) string }
Translator interface
func NewJSONTranslator ¶
func NewJSONTranslator(fallbackLocale string, dir string) (Translator, error)
NewJSONTranslator create a new memory based translator
func NewMemoryTranslator ¶
func NewMemoryTranslator(fallbackLocale string) Translator
NewMemoryTranslator create a new memory based translator