Documentation ¶
Index ¶
- type Error
- type I18n
- func (i *I18n) AddMessages(lang string, messages ...*i18n.Message) error
- func (i *I18n) Load(ld string, languages ...string)
- func (i *I18n) Translate(key string, languages ...string) string
- func (i *I18n) TranslateFromError(err Error, languages ...string) string
- func (i *I18n) TranslateFromErrorDetail(err Error, languages ...string) (string, interface{})
- func (i *I18n) TranslateWithParams(key string, params interface{}, languages ...string) string
- type P
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Error ¶
type Error struct { // Key is the error key to be used in the translation // It is required // If it is empty, the error is not an error Key string // Params is the error params to be used in the translation // It is optional // If it is nil, the error params will be empty Params *P // Details is the error details to be used in the translation // It is optional // If it is nil, the error details will be empty Details interface{} }
I18nError is a struct that contains the error key and the error params to be used in the translation It implements the error interface It can be used to return errors from functions
func NewError ¶
NewError returns a new I18nError It is used to return errors from functions example: i18n.NewError("error.key", i18np.P{"param1": "value1"})
func NewErrorDetails ¶
NewErrorDetails returns a new I18nError with details
It is used to return errors from functions
example: i18n.NewErrorDetails("error.key", "details", i18np.P{"param1": "value1"})
func (*Error) Error ¶
Error returns the error key and the error params It implements the error interface
type I18n ¶
type I18n struct { // Fallback is default language Fallback string // contains filtered or unexported fields }
I18n is base struct for i18n b is i18n bundle Fallback is default language
func (*I18n) AddMessages ¶
AddMessages is add i18n message lang is language messages is i18n message example: i18n.AddMessages("en", &i18n.Message{ID: "hello", Other: "Hello!"})
func (*I18n) Load ¶
Load is load i18n file ld is directory path languages is language list example: i18n.Load("./i18n", "en", "ja")
func (*I18n) Translate ¶
Translate is translate i18n message key is i18n key languages is language list example: i18n.Translate("hello", "en") example: i18n.Translate("hello", "en", "ja") example: i18n.Translate("hello", "ja", "en")
func (*I18n) TranslateFromError ¶
TranslateFromError is translate i18n message from I18nError err is I18nError
languages is language list
example: i18n.TranslateFromError(err, "en") example: i18n.TranslateFromError(err, "en", "ja")
func (*I18n) TranslateFromErrorDetail ¶
TranslateFromErrorDetail is translate i18n message from I18nError err is I18nError languages is language list return string, interface{} example: i18n.TranslateFromErrorDetail(err, "en") example: i18n.TranslateFromErrorDetail(err, "en", "ja") example: i18n.TranslateFromErrorDetail(err, "ja", "en")
func (*I18n) TranslateWithParams ¶
TranslateWithParams is translate i18n message with params key is i18n key params is i18n params languages is language list example: i18n.TranslateWithParams("hello", i18n.P{"Name": "John"}, "en")