cldr is a golang library using Common Locale Data Repository to format dates, plurals (and more in the future), inspired by twitter-cldr-rb and borrowing some codes from github.com/vube/i18n.
cldr embeds CLDR data in pure go and it doesn't import all those locale data by default. If you are using specific locale data, you can import that package as bellow:
package main
import (
"github.com/rannoch/cldr"
_ "github.com/rannoch/cldr/resources/locales/en"
)
func main() {
cldr.Parse(
"en",
`{{p "Count" (one "{{.Count}} item") (other "{{.Count}} items")}}`,
map[string]int{"Count": 1},
) // "1 item in Your Cart"
}
If you don't like hand-importing locales, you can import github.com/rannoch/cldr/resources/locales
, which import all available locales in cldr pacakge.
More API could be found here.
cldr.RegisterLocale(Locale{...})
// solution 1
// using the same locale name
import _ github.com/rannoch/cldr/resources/locales/en
cldr.RegisterLocale(Locale{Locale: "en"})
// solution 2
// update the exported locale directly
import github.com/rannoch/cldr/resources/locales/en
en.Locale.PluralRule = "2A"