Documentation ¶
Overview ¶
Package bundle manages translations for multiple languages.
Index ¶
- type Bundle
- func (b *Bundle) AddTranslation(lang *language.Language, translations ...translation.Translation)
- func (b *Bundle) LoadTranslationFile(filename string) error
- func (b *Bundle) MustLoadTranslationFile(filename string)
- func (b *Bundle) MustTfunc(languageSource string, languageSources ...string) TranslateFunc
- func (b *Bundle) ParseTranslationFileBytes(filename string, buf []byte) error
- func (b *Bundle) Tfunc(src string, srcs ...string) (TranslateFunc, error)
- func (b *Bundle) Translations() map[string]map[string]translation.Translation
- type TranslateFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bundle ¶
type Bundle struct {
// contains filtered or unexported fields
}
Bundle stores the translations for multiple languages.
func (*Bundle) AddTranslation ¶
func (b *Bundle) AddTranslation(lang *language.Language, translations ...translation.Translation)
AddTranslation adds translations for a language.
It is useful if your translations are in a format not supported by LoadTranslationFile.
func (*Bundle) LoadTranslationFile ¶
LoadTranslationFile loads the translations from filename into memory.
The language that the translations are associated with is parsed from the filename (e.g. en-US.json).
Generally you should load translation files once during your program's initialization.
func (*Bundle) MustLoadTranslationFile ¶
MustLoadTranslationFile is similar to LoadTranslationFile except it panics if an error happens.
func (*Bundle) MustTfunc ¶
func (b *Bundle) MustTfunc(languageSource string, languageSources ...string) TranslateFunc
MustTfunc is similar to Tfunc except it panics if an error happens.
func (*Bundle) ParseTranslationFileBytes ¶
ParseTranslationFileBytes is similar to LoadTranslationFile except it parses the bytes in buf.
It is useful for parsing translation files embedded with go-bindata.
func (*Bundle) Tfunc ¶
func (b *Bundle) Tfunc(src string, srcs ...string) (TranslateFunc, error)
Tfunc returns a TranslateFunc that will be bound to the first language which has a non-zero number of translations in the bundle.
It can parse languages from Accept-Language headers (RFC 2616).
func (*Bundle) Translations ¶
func (b *Bundle) Translations() map[string]map[string]translation.Translation
Translations returns all translations in the bundle.
type TranslateFunc ¶
TranslateFunc is a copy of i18n.TranslateFunc to avoid a circular dependency.