Documentation ¶
Overview ¶
Package messages manage the REST messages in a specific language
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ShelterRESTLanguagePacks LanguagePacks // Store all possible languages ShelterRESTLanguagePack *LanguagePack // Store the messages from the selected language )
var ( // When the default language is not found in the language pack this error is used. This // is a critical error because the ShelterRESTLanguagePack will be null and can cause // panic when the system try to use it ErrDefaultLanguageNotFound = errors.New("Default language not found in configuration file") // All loaded languages are checked to see if they match with the predefined list of // IANA languages, if not this error is returned to alert the administrator ErrInvalidLanguage = errors.New("Language is not valid") )
List of possible errors that can occur in this language controller. There can be also other errors from low level drivers (like json unmarshall)
Functions ¶
func LoadConfig ¶
Load the language packs from the configuration file
Types ¶
type LanguagePack ¶
type LanguagePack struct { GenericName string // Language acronym (eg. pt) SpecificName string // Language acronym with region (eg. pt-br) Messages map[string]string // List of messages with identifiers }
LanguagePack defines a structure for a specific message
func (*LanguagePack) Name ¶
func (l *LanguagePack) Name() string
Return the language name to be add to HTTP header response. We are going to normalize all the names in lower case
type LanguagePacks ¶
type LanguagePacks struct { Default string // Language used for returning messages Packs []LanguagePack // List of possible languages }
Structure responsable for storing all messages from the REST server in different idioms for a flexible internationalization
func (*LanguagePacks) Names ¶
func (l *LanguagePacks) Names() string
Return the languages supported by Shelter REST server
func (*LanguagePacks) Select ¶
func (l *LanguagePacks) Select(language string) *LanguagePack
Select the language that is going to be used in the REST server messages based on the Language HTTP header