Skip to content
Buffalo i18n Middleware
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
locales
templates
LICENSE.txt
README.md
azure-pipelines.yml
azure-tests.yml
go.mod
go.sum
i18n.go
i18n_test.go

README.md

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.

You can’t perform that action at this time.