Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
beifeng778 opened this issue Sep 19, 2023 · 1 comment
Assignees

Comments

@beifeng778
Copy link

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."
@kataras
Copy link
Owner

kataras commented Sep 25, 2023

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants