Localization
Middleware i18n provides app Internationalization and Localization for Macaron Instances.
Installation
go get github.com/go-macaron/i18nUsage
// main.go
import (
"github.com/go-macaron/i18n"
"gopkg.in/macaron.v1"
)
func main() {
m := macaron.Classic()
m.Use(i18n.I18n(i18n.Options{
Langs: []string{"en-US", "zh-CN"},
Names: []string{"English", "简体中文"},
}))
m.Get("/", func(locale i18n.Locale) string {
return "current language is" + locale.Lang
})
// Use in handler.
m.Get("/trans", func(ctx *macaron.Context) string {
return ctx.Tr("hello %s", "world")
})
m.Run()
}Pongo2
To use i18n feature in pongo2 with middleware pongo2:
Options
i18n.I18n comes with a variety of configuration options(i18n.Options):
Loading Locale Files
By default, locale files should be put in conf/locale:
Others
See unknwon/i18n for specification of translation.
See Peach Docs as a study example.
Last updated
Was this helpful?