2020-09-10 04:17:03 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-09-10 16:52:25 +02:00
|
|
|
"strings"
|
2020-09-10 05:22:53 +02:00
|
|
|
"text/template"
|
2020-09-10 04:17:03 +02:00
|
|
|
|
2020-09-10 05:22:53 +02:00
|
|
|
"github.com/kataras/iris/v12"
|
2020-09-10 04:17:03 +02:00
|
|
|
)
|
|
|
|
|
2020-09-10 05:22:53 +02:00
|
|
|
/*
|
|
|
|
Iris I18n supports text/template inside the translation values.
|
2020-09-10 09:12:06 +02:00
|
|
|
Follow this example to learn how to use that feature.
|
2020-09-10 05:22:53 +02:00
|
|
|
*/
|
|
|
|
|
2020-09-10 04:17:03 +02:00
|
|
|
func main() {
|
|
|
|
app := newApp()
|
|
|
|
app.Listen(":8080")
|
|
|
|
}
|
|
|
|
|
|
|
|
func newApp() *iris.Application {
|
|
|
|
app := iris.New()
|
|
|
|
|
2020-09-10 05:22:53 +02:00
|
|
|
// Set custom functions per locale!
|
|
|
|
app.I18n.Loader.Funcs = func(current iris.Locale) template.FuncMap {
|
|
|
|
return template.FuncMap{
|
2020-09-10 16:52:25 +02:00
|
|
|
"uppercase": func(word string) string {
|
|
|
|
return strings.ToUpper(word)
|
|
|
|
},
|
2020-09-10 05:22:53 +02:00
|
|
|
}
|
2020-09-10 04:17:03 +02:00
|
|
|
}
|
2020-09-10 05:22:53 +02:00
|
|
|
|
2020-11-07 11:49:14 +01:00
|
|
|
err := app.I18n.Load("./locales/*/*.ini", "en-US", "el-GR")
|
2020-09-14 21:00:20 +02:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2020-09-10 04:17:03 +02:00
|
|
|
|
|
|
|
app.Get("/", func(ctx iris.Context) {
|
2020-11-07 11:49:14 +01:00
|
|
|
text := ctx.Tr("forms.register") // en-US: prints "Become a MEMBER".
|
2020-09-10 16:52:25 +02:00
|
|
|
ctx.WriteString(text)
|
|
|
|
})
|
|
|
|
|
2020-11-07 11:49:14 +01:00
|
|
|
app.Get("/title", func(ctx iris.Context) {
|
|
|
|
text := ctx.Tr("user.connections.Title") // en-US: prints "Accounts Connections".
|
2020-09-10 09:12:06 +02:00
|
|
|
ctx.WriteString(text)
|
|
|
|
})
|
|
|
|
|
2020-09-10 04:17:03 +02:00
|
|
|
return app
|
|
|
|
}
|