Documentation ¶
Overview ¶
Package intergo implements a simple library for internationalized strings. The library manages a hash map in the form map["language"]["locale"]. The supported format for locale strings is language_locale.encoding. The encoding part is actually ignored, and the form language_locale also works. Of course, it's case-sensitive and the recommended form is language_LOCALE, e.g., en_US is a locale for American English, and pt_BR is for Brazilian Portuguese.
Index ¶
- type InterContext
- func (ctx *InterContext) AddLocale(locale string, entries map[string]string) error
- func (ctx *InterContext) AutoSetPreferedLocale() error
- func (ctx *InterContext) Get(text string) string
- func (ctx *InterContext) GetFromLocale(text string, locale string) (string, error)
- func (ctx *InterContext) Init()
- func (ctx *InterContext) SetPreferedLocale(locale string) error
- type Language
- type Locale
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type InterContext ¶
type InterContext struct {
// contains filtered or unexported fields
}
The library context itself.
func (*InterContext) AddLocale ¶
func (ctx *InterContext) AddLocale(locale string, entries map[string]string) error
Adds a new mapping of strings, i.e., a new locale, to the context. Usually called for all the supported locales right after the context initialization.
func (*InterContext) AutoSetPreferedLocale ¶
func (ctx *InterContext) AutoSetPreferedLocale() error
Automatically sets the prefered locale with the variables `LC_ALL` and `LANG`. Basically tries `LC_ALL`, and if it cannot parse a locale from it, tries `LC_LANG`.
func (*InterContext) Get ¶
func (ctx *InterContext) Get(text string) string
Gets an internationalized string with the prefered locale.
func (*InterContext) GetFromLocale ¶
func (ctx *InterContext) GetFromLocale(text string, locale string) (string, error)
Gets an internationalized string from a specific locale.
func (*InterContext) Init ¶
func (ctx *InterContext) Init()
Initializes the language map, should be called after instanciating an InterContext. Usually called right after the application startup.
func (*InterContext) SetPreferedLocale ¶
func (ctx *InterContext) SetPreferedLocale(locale string) error
Sets the prefered locale.