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(pref string, prefs ...string) TranslateFunc
- func (b *Bundle) MustTfuncAndLanguage(pref string, prefs ...string) (TranslateFunc, *language.Language)
- func (b *Bundle) ParseTranslationFileBytes(filename string, buf []byte) error
- func (b *Bundle) Tfunc(pref string, prefs ...string) (TranslateFunc, error)
- func (b *Bundle) TfuncAndLanguage(pref string, prefs ...string) (TranslateFunc, *language.Language, 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(pref string, prefs ...string) TranslateFunc
MustTfunc is similar to Tfunc except it panics if an error happens.
func (*Bundle) MustTfuncAndLanguage ¶
func (b *Bundle) MustTfuncAndLanguage(pref string, prefs ...string) (TranslateFunc, *language.Language)
MustTfuncAndLanguage is similar to TfuncAndLanguage 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(pref string, prefs ...string) (TranslateFunc, error)
Tfunc is similar to TfuncAndLanguage except is doesn't return the Language.
func (*Bundle) TfuncAndLanguage ¶
func (b *Bundle) TfuncAndLanguage(pref string, prefs ...string) (TranslateFunc, *language.Language, error)
TfuncAndLanguage returns a TranslateFunc for the first Language that has a non-zero number of translations in the bundle.
The returned Language matches the the first language preference that could be satisfied, but this may not strictly match the language of the translations used to satisfy that preference.
For example, the user may request "zh". If there are no translations for "zh" but there are translations for "zh-cn", then the translations for "zh-cn" will be used but the returned Language will be "zh".
It can parse languages from Accept-Language headers (RFC 2616), but it assumes weights are monotonically decreasing.
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.