Documentation
¶
Index ¶
- Constants
- func CreateCookie(w http.ResponseWriter, localization string, cy core.Cypher) error
- func ReadCookie(req *http.Request, cy core.Cypher) (string, error)
- type Localizer
- type Store
- type WebStore
- func (ws WebStore) CreateCookie(w http.ResponseWriter, localization string) error
- func (ws WebStore) Get(key, language string) Localizer
- func (ws WebStore) GetLocalizedError(err core.DomainError, req *http.Request) string
- func (ws WebStore) GetUsingRequest(key string, req *http.Request) Localizer
- func (ws WebStore) GetUsingRequestWithoutShared(key string, req *http.Request) Localizer
- func (ws WebStore) LoadIntoFieldUsingRequest(field **Localizer, key string, req *http.Request)
- func (ws WebStore) ReadCookie(req *http.Request) string
Constants ¶
const ( LangSpanish = "es" LangEnglish = "en" )
const ContextKey string = "phx_localization"
context.Context key to localize localization token inside a request
Variables ¶
This section is empty.
Functions ¶
func CreateCookie ¶
Types ¶
type Localizer ¶
Localizer is a map of key and translations.
func (Localizer) Get ¶
Safely gets a localizer key. If the key is not defined in the localizer returns the key instead of returning the translation.
func (Localizer) GetFormatted ¶ added in v1.4.1
Safely gets a localizer key. If the key is not defined in the localizer returns the key instead of returning the translation. Then, it will format the string replacing a format specifier (using fmt.Sprintf)
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
A localizer store is a system to get a Localizer depending of a file name.
func NewLocalizerStore ¶
type WebStore ¶ added in v1.1.3
type WebStore struct {
Store
// contains filtered or unexported fields
}
WebStore is a Localizer store with a defined SharedKey, ErrorKey and a core.Cypher.
- SharedKey is the filename of shared translations. For example 'shared.json'. This file will be used as a fallback.
- ErrorKey is the file of error translations. For example 'error.json'. This file will be used to tranlate errors when you call the function "GetLocalizerError"
- core.Cypher is used to create and read localization HTTP cookie.
func NewWebLocalizerStore ¶ added in v1.1.3
Creates a web localizer store. See WebStore documentation.
func (WebStore) CreateCookie ¶ added in v1.1.3
func (ws WebStore) CreateCookie(w http.ResponseWriter, localization string) error
Creates a localizer cookie
func (WebStore) Get ¶ added in v1.1.3
Gets a Localizer reading a json file identified by 'key' and then reads the language defined in that file. The localizer loaded will be merged with shared localizer.
func (WebStore) GetLocalizedError ¶ added in v1.1.3
Localize a DomainError using the ErrorKey
func (WebStore) GetUsingRequest ¶ added in v1.1.3
Get a Localizer using the language defined in HTTP cookie
func (WebStore) GetUsingRequestWithoutShared ¶ added in v1.1.3
Get a Localizer using the language defined in HTTP cookie without SharedKey