kataras / kataras/iris

[BUG] Pluralization uses yml for template configuration, uses ctx.Tr method for rendering, returns no data

Open
#2,212 1 comment 0 reactions 1 assignee Claimed by @kataras View on GitHub
Dominant language
Go
Stars
25.6k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

**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."
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.