iris
iris copied to clipboard
[BUG] Pluralization uses yml for template configuration, uses ctx.Tr method for rendering, returns no data
Describe the bug Pluralization uses yml for template configuration, uses ctx.Tr method for rendering, returns no data.
iris.Version
- e.g. v12.2.5 or main
Additional context code:
package main
import (
"github.com/kataras/iris/v12"
"strings"
)
const (
female = iota + 1
male
)
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) {
a := ctx.Tr("VarTemplatePlural", iris.Map{
"PluralCount": 5,
"Names": []string{"John", "Peter"},
"InlineJoin": func(arr []string) string {
return strings.Join(arr, ", ")
},
})
// Outputs: John, Peter are awesome
b := ctx.Tr("VarTemplatePlural", 1, female)
// Outputs: She is awesome!
c := ctx.Tr("VarTemplatePlural", 2, female, 5)
// Outputs: other (She) has 5 houses.
ctx.WriteString(a + b + c)
})
app.Listen(`:8080`)
}
welcome.yml:
Vars:
- Houses:
one: "house"
other: "houses"
- Gender:
"=1": "She"
"=2": "He"
VarTemplatePlural:
one: "${Gender} is awesome!"
other: "other (${Gender}) has %[3]d ${Houses}."
"=5": "{{call .InlineJoin .Names}} are awesome."
Hello @beifeng778 I ran your example and it seems that there is no issue here, the response is: John, Peter are awesome.She is awesome!other (She) has 5 houses. Can you explain the problem a bit more?