Documentation ¶
Index ¶
- func GetLangFromRequest(c MessageCatalog, r *http.Request) language.Tag
- func GetMessage(c MessageCatalog, ID string, tag language.Tag, v ...interface{}) string
- func GetMessageOrDefault(c MessageCatalog, ID string, tag language.Tag, def string, v ...interface{}) string
- type DefaultLocaleBundle
- type DefaultMessage
- type MessageCatalog
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetLangFromRequest ¶
func GetLangFromRequest(c MessageCatalog, r *http.Request) language.Tag
GetLangFromRequest is a helper func to get the language tag based on the HTTP request and the constructed message catalog.
func GetMessage ¶
func GetMessage(c MessageCatalog, ID string, tag language.Tag, v ...interface{}) string
GetMessage is a helper func to get the translated message based on the message ID and lang. If no matching message is found, it uses ID as the message itself.
func GetMessageOrDefault ¶
func GetMessageOrDefault(c MessageCatalog, ID string, tag language.Tag, def string, v ...interface{}) string
GetMessageOrDefault is a helper func to get the translated message based on the message ID and lang. If no matching message is found, it returns the 'def' message.
Types ¶
type DefaultLocaleBundle ¶
type DefaultLocaleBundle struct { LangTag string `json:"lang"` Messages []*DefaultMessage `json:"messages"` }
DefaultLocaleBundle is a bundle of messages for the specified locale. The language tag can be arbitrary to allow for unsupported/unknown languages used by custom clients.
func (*DefaultLocaleBundle) Init ¶
func (l *DefaultLocaleBundle) Init() error
Init initializes the default catalog with the list of messages. The lang tag must parse, otherwise this func will panic.
type DefaultMessage ¶
DefaultMessage is a single message in the locale bundle identified by 'ID'.
type MessageCatalog ¶
type MessageCatalog interface { GetMessage(ID string, tag language.Tag, v ...interface{}) string GetLangFromRequest(r *http.Request) language.Tag }
MessageCatalog declares the interface to get globalized messages
func NewDefaultMessageCatalog ¶
func NewDefaultMessageCatalog(bundles []*DefaultLocaleBundle) MessageCatalog