Documentation ¶
Index ¶
- Variables
- func G(key string, defaults ...string) string
- func GetCurrent() string
- func SetCurrent(locale string)
- type Localization
- func (l *Localization) Add(locale string, translations map[string]string)
- func (l *Localization) AddFile(file string) error
- func (l *Localization) AddFolder(folder string) error
- func (l *Localization) G(key string, defaults ...string) string
- func (l *Localization) Get(locale, key string, defaults ...string) string
- func (l *Localization) GetCurrent() string
- func (l *Localization) GetLocales() []string
- func (l *Localization) SetCurrent(locale string)
Constants ¶
This section is empty.
Variables ¶
var Global = New()
Global is the default localization instance.
Functions ¶
func GetCurrent ¶
func GetCurrent() string
GetCurrent returns the current locale in the default localization instance.
func SetCurrent ¶
func SetCurrent(locale string)
SetCurrent sets the current locale in the default localization instance.
Types ¶
type Localization ¶
type Localization struct {
// contains filtered or unexported fields
}
func New ¶
func New() *Localization
func (*Localization) Add ¶
func (l *Localization) Add(locale string, translations map[string]string)
Add adds a new locale with the given translations. If the locale already exists, the translations will be added to the existing ones.
func (*Localization) AddFile ¶
func (l *Localization) AddFile(file string) error
AddFile adds a new locale with the given translations from the given file.
func (*Localization) AddFolder ¶
func (l *Localization) AddFolder(folder string) error
AddFolder adds all locales from the given folder. Will walk through all sub-folders and add all .yaml and .yml files.
func (*Localization) G ¶
func (l *Localization) G(key string, defaults ...string) string
G is a shortcut for Get with the current locale.
func (*Localization) Get ¶
func (l *Localization) Get(locale, key string, defaults ...string) string
Get returns the translation for the given key in the given locale. If the key is not found, it will fall back to the "en" locale and if the key is not found there, it will return the key or the given defaults.
func (*Localization) GetCurrent ¶
func (l *Localization) GetCurrent() string
GetCurrent returns the current locale.
func (*Localization) GetLocales ¶
func (l *Localization) GetLocales() []string
GetLocales returns a list of all available locales.
func (*Localization) SetCurrent ¶
func (l *Localization) SetCurrent(locale string)
SetCurrent sets the current locale.