Documentation ¶
Overview ¶
Package i18n implements i18n with simple config file or custom backends. Files are simple config files based on https://github.com/mojombo/toml.
You can load a file with i18n.Load:
err := i18n.Load("sample.conf")
You can also load multiple files passing a glob pattern:
i18n.Load("/path/to/locals/*.conf")
Add all your translations under the "en" section:
[en] greeting = "hello"
Inside a file you can have multiple sections. Each section will be a different locale:
// file sample.conf [en] greeting = "hello" [it] greeting = "ciao" [es] greeting = "hola"
Check the example folder for a complete example https://github.com/dre1080/i18n/tree/master/example
Index ¶
- func AddLocale(locale *Locale)
- func Load(globPattern string) error
- func SetLocale(code string) error
- func T(key string, args ...interface{}) (string, error)
- func Translate(key string, args ...interface{}) (string, error)
- type Locale
- type LocaleMissing
- type Options
- type Sections
- type Translation
- type TranslationMissing
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Locale ¶
type Locale struct { Code string Translations map[string]*Translation }
Locale represents a locale with its Code and translations
func (*Locale) Add ¶
func (locale *Locale) Add(key, value string) *Translation
Adds a key and its translation to locale.
type LocaleMissing ¶
type LocaleMissing struct {
Code string
}
func (LocaleMissing) Error ¶
func (m LocaleMissing) Error() string
type Translation ¶
type Translation [2]string
Translation is a pair of strings, the key and the value, which is the actual translation.
func NewTranslation ¶
func NewTranslation(key, value string) *Translation
Returns a new Translation.
func (*Translation) Format ¶
func (t *Translation) Format(args ...interface{}) string
Returns fmt.Sprintf(t.Value(), args...)
func (*Translation) Key ¶
func (t *Translation) Key() string
func (*Translation) Value ¶
func (t *Translation) Value() string
type TranslationMissing ¶
type TranslationMissing struct {
Key string
}
func (TranslationMissing) Error ¶
func (t TranslationMissing) Error() string