Documentation ¶
Index ¶
- type LanguageFinder
- type Translator
- func (t *Translator) AddTranslation(lang *language.Language, translations ...translation.Translation)
- func (t *Translator) Load() error
- func (t *Translator) Middleware() buffalo.MiddlewareFunc
- func (t *Translator) Translate(c buffalo.Context, s string) (string, error)
- func (t *Translator) TranslatePlural(c buffalo.Context, s string, i interface{}) (string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LanguageFinder ¶
type LanguageFinder func(*Translator, buffalo.Context) []string
LanguageFinder can be implemented for custom finding of search languages. This can be useful if you want to load a user's language from something like a database. See Middleware() for more information on how the default implementation searches for languages.
type Translator ¶
type Translator struct { // Box - where are the files? Box packr.Box // DefaultLanguage - default is "en-US" DefaultLanguage string // CookieName - name of the cookie to find the desired language. // default is "lang" CookieName string // SessionName - name of the session to find the desired language. // default is "lang" SessionName string // HelperName - name of the view helper. default is "t" HelperName string // HelperNamePlural - name of the view plural helper. default is "tp" HelperNamePlural string LanguageFinder LanguageFinder }
Translator for handling all your i18n needs.
func New ¶
func New(box packr.Box, language string) (*Translator, error)
New Translator. Requires a packr.Box that points to the location of the translation files, as well as a default language. This will also call t.Load() and load the translations from disk.
func (*Translator) AddTranslation ¶
func (t *Translator) AddTranslation(lang *language.Language, translations ...translation.Translation)
AddTranslation directly, without using a file. This is useful if you wish to load translations from a database, instead of disk.
func (*Translator) Middleware ¶
func (t *Translator) Middleware() buffalo.MiddlewareFunc
Middleware for loading the translations for the language(s) selected. By default languages are loaded in the following order:
Cookie - "lang" Header - "Accept-Language" Default - "en-US"
These values can be changed on the Translator itself. In development model the translation files will be reloaded on each request.
func (*Translator) Translate ¶
Translate translates a string given a Context s is the translation ID
func (*Translator) TranslatePlural ¶ added in v0.10.1
TranslatePlural is the plural version of Translate s is the translation ID i must be an integer type (int, int8, int16, int32, int64) or a float formatted as a string (e.g. "123.45")