Tools / Mw-i18n

Mw-i18n

Buffalo i18n Middleware

Repository: gobuffalo/mw-i18n
Forks: 0
Watchers: 6
Stars: 0

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.

License: MIT License - A short and simple permissive license with conditions only requiring preservation of copyright and license notices. Licensed works, modifications, and larger works may be distributed under different terms and without source code.

MIT License

Copyright (c) [year] [fullname]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.