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

Pluralization doesn't work #16

Open
adhatama opened this issue Sep 12, 2018 · 1 comment
Open

Pluralization doesn't work #16

adhatama opened this issue Sep 12, 2018 · 1 comment

Comments

@adhatama
Copy link

adhatama commented Sep 12, 2018

I have a simple pluralization like this:

lang/en-US.yml

en-US:
  demo:
    plural: '{{p "Count" (one "{{.Count}} item") (other "{{.Count}} items")}}'
main.go

I18n := i18n.New(
    yaml.New("lang"),
)
val := I18n.T(
    "en-US",
    "demo.plural",
    map[string]int{"Count": 1},
)
fmt.Println(val)

The printed value of val is 1 items where it should be 1 item
Did I miss something?

@shoamano83
Copy link

Hi, looking at CLDR document https://github.com/theplant/cldr#how-to-use, I think we need to import locale files.

These worked for me with en locale:

lang/en.yaml

en:
  demo:
    plural: '{{p "Count" (one "{{.Count}} item") (other "{{.Count}} items")}}'

main.go

package main
  
import (
        "fmt"
        "github.com/qor/i18n"
        "github.com/qor/i18n/backends/yaml"
        _ "github.com/theplant/cldr/resources/locales" // this one!
)

func main() {
        I18n := i18n.New(
                yaml.New("lang"),
        )
        val := I18n.T(
                "en",
                "demo.plural",
                map[string]int{"Count": 1},
        )
        fmt.Println(val)
}

Result:

$ go run main.go 
1 item

However, I couldn't figure out how to use it with en-US locale. It looks like CLDR has en but not en-US.

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