Documentation ¶
Overview ¶
Package i18n implements i18n with simple config file or custom backends.
Files are simple config files based on https://github.com/pilu/config. You can load a file with i18n.Load:
err := i18n.Load("en.conf")
You can also load multiple files passing a glob pattern:
i18n.Load("/path/to/locals/*.conf")
In the first example, all the translations of "en.conf" are added to the locale "en", which is the file name without extension.
You can also create a file with a different name and 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 en.conf greeting: hello [it] greeting: ciao [es] greeting: hola
All top level translations are added to the locale "en", which is the file name.
Check the example folder for a complete example https://github.com/pilu/i18n-go/tree/master/example
Index ¶
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