package main
import (
"strings"
"github.com/kataras/iris/v12"
)
const (
female = iota + 1
male
)
const tableStyle = `
`
/*
$ go run .
Visit http://localhost:8080
*/
func main() {
app := iris.New()
err := app.I18n.Load("./locales/*/*", "en-US")
// ^ here we only use a single locale for the sake of the example,
// on a real app you can register as many languages as you want to support.
if err != nil {
panic(err)
}
app.Get("/", func(ctx iris.Context) {
ctx.HTML("
\n")
ctx.WriteString(tableStyle)
ctx.WriteString(`
Key |
Translation |
Arguments |
`)
defer ctx.WriteString("
")
tr(ctx, "Classic")
tr(ctx, "YouLate", 1)
tr(ctx, "YouLate", 2)
tr(ctx, "FreeDay", 1)
tr(ctx, "FreeDay", 5)
tr(ctx, "FreeDay", 3, 15)
tr(ctx, "HeIsHome", "Peter")
tr(ctx, "HouseCount", female, 2, "Maria")
tr(ctx, "HouseCount", male, 1, "Peter")
tr(ctx, "nav.home")
tr(ctx, "nav.user")
tr(ctx, "nav.more.what")
tr(ctx, "nav.more.even.more")
tr(ctx, "nav.more.even.aplural", 1)
tr(ctx, "nav.more.even.aplural", 15)
tr(ctx, "VarTemplate", iris.Map{
"Name": "Peter",
"GenderCount": male,
})
tr(ctx, "VarTemplatePlural", 1, female)
tr(ctx, "VarTemplatePlural", 2, female, 1)
tr(ctx, "VarTemplatePlural", 2, female, 5)
tr(ctx, "VarTemplatePlural", 1, male)
tr(ctx, "VarTemplatePlural", 2, male, 1)
tr(ctx, "VarTemplatePlural", 2, male, 2)
tr(ctx, "VarTemplatePlural", iris.Map{
"PluralCount": 5,
"Names": []string{"Makis", "Peter"},
"InlineJoin": func(arr []string) string {
return strings.Join(arr, ", ")
},
})
tr(ctx, "TemplatePlural", iris.Map{
"PluralCount": 1,
"Name": "Peter",
})
tr(ctx, "TemplatePlural", iris.Map{
"PluralCount": 5,
"Names": []string{"Makis", "Peter"},
"InlineJoin": func(arr []string) string {
return strings.Join(arr, ", ")
},
})
tr(ctx, "VarTemplatePlural", 2, male, 4)
tr(ctx, "TemplateVarTemplatePlural", iris.Map{
"PluralCount": 3,
"DogsCount": 5,
})
tr(ctx, "message.HostResult")
tr(ctx, "LocalVarsHouseCount.Text", 3, 4)
})
app.Listen(":8080")
}
func tr(ctx iris.Context, key string, args ...interface{}) {
translation := ctx.Tr(key, args...)
ctx.Writef("%s | %s | %v |
\n", key, translation, args)
}