Skip to content
/ cldr Public
forked from theplant/cldr

A golang i18n tool using CLDR data

License

Notifications You must be signed in to change notification settings

rannoch/cldr

 
 

Repository files navigation

CLDR

GoDoc

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.

How to use

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.

How to add locales

cldr.RegisterLocale(Locale{...})

How to override default locales

// 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"

About

A golang i18n tool using CLDR data

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%