This repository has been archived by the owner on Feb 24, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 578
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a README for the i18n middleware (#960)
* Add a README for the i18n middleware * Remove bad indentation
- Loading branch information
1 parent
6f7d3a3
commit 35866e9
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
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** | ||
```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. |