README
¶
i18n middleware
This Buffalo middleware enables i18n features in your app:
- User language detection from configurable sources
- Translation helper using locales bundles from github.com/nicksnyder/go-i18n
- Localized views
Installation
This middleware is setup by default on a new Buffalo app:
actions/app.go
var app *buffalo.App
// T is used to provide translations
var T *i18n.Translator
// App is where all routes and middleware for buffalo
// should be defined. This is the nerve center of your
// application.
func App() *buffalo.App {
if app == nil {
// [...]
// Setup and use translations:
var err error
if T, err = i18n.New(packr.NewBox("../locales"), "en"); err != nil {
app.Stop(err)
}
app.Use(T.Middleware())
}
return app
}
Use i18n.New
to create a new instance of the translation module, then add the middleware (T.Middleware()
) to the app to enable its features.
See https://gobuffalo.io/docs/localization for further info about Buffalo translation features and configuration.
Documentation
¶
Index ¶
- Variables
- type LanguageExtractordeprecated
- type LanguageExtractorOptionsdeprecated
- type Translatordeprecated
Constants ¶
This section is empty.
Variables ¶
var CookieLanguageExtractor = i18nm.CookieLanguageExtractor
CookieLanguageExtractor is a LanguageExtractor implementation, using a cookie.
Deprecated: use github.com/gobuffalo/mw-i18n#CookieLanguageExtractor instead.
var HeaderLanguageExtractor = i18nm.HeaderLanguageExtractor
HeaderLanguageExtractor is a LanguageExtractor implementation, using a HTTP Accept-Language header.
Deprecated: use github.com/gobuffalo/mw-i18n#HeaderLanguageExtractor instead.
var New = i18nm.New
New Translator. Requires a packd.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.
Deprecated: use github.com/gobuffalo/mw-i18n#New instead.
var SessionLanguageExtractor = i18nm.SessionLanguageExtractor
SessionLanguageExtractor is a LanguageExtractor implementation, using a session.
Deprecated: use github.com/gobuffalo/mw-i18n#SessionLanguageExtractor instead.
var URLPrefixLanguageExtractor = i18nm.URLPrefixLanguageExtractor
URLPrefixLanguageExtractor is a LanguageExtractor implementation, using a prefix in the URL.
Deprecated: use github.com/gobuffalo/mw-i18n#URLPrefixLanguageExtractor instead.
Functions ¶
This section is empty.
Types ¶
type LanguageExtractor
deprecated
added in
v0.12.0
type LanguageExtractor = i18nm.LanguageExtractor
LanguageExtractor 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.
Deprecated: use github.com/gobuffalo/mw-i18n#LanguageExtractor instead.
type LanguageExtractorOptions
deprecated
added in
v0.12.0
type LanguageExtractorOptions = i18nm.LanguageExtractorOptions
LanguageExtractorOptions is a map of options for a LanguageExtractor.
Deprecated: use github.com/gobuffalo/mw-i18n#LanguageExtractorOptions instead.
type Translator
deprecated
type Translator = i18nm.Translator
Translator for handling all your i18n needs.
Deprecated: use github.com/gobuffalo/mw-i18n#Translator instead.