i18n icon indicating copy to clipboard operation
i18n copied to clipboard

Pluralization doesn't work

Open adhatama opened this issue 6 years ago • 1 comments

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?

adhatama avatar Sep 12 '18 10:09 adhatama

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.

shoamano83 avatar Oct 11 '19 11:10 shoamano83