2 <img align="right" src="https://raw.githubusercontent.com/go-playground/locales/master/logo.png">![Project status](https://img.shields.io/badge/version-0.11.1-green.svg)
3 [![Build Status](https://semaphoreci.com/api/v1/joeybloggs/locales/branches/master/badge.svg)](https://semaphoreci.com/joeybloggs/locales)
4 [![Go Report Card](https://goreportcard.com/badge/github.com/go-playground/locales)](https://goreportcard.com/report/github.com/go-playground/locales)
5 [![GoDoc](https://godoc.org/github.com/go-playground/locales?status.svg)](https://godoc.org/github.com/go-playground/locales)
6 ![License](https://img.shields.io/dub/l/vibe-d.svg)
7 [![Gitter](https://badges.gitter.im/go-playground/locales.svg)](https://gitter.im/go-playground/locales?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
9 Locales is a set of locales generated from the [Unicode CLDR Project](http://cldr.unicode.org/) which can be used independently or within
10 an i18n package; these were built for use with, but not exclusive to, [Universal Translator](https://github.com/go-playground/universal-translator).
14 - [x] Rules generated from the latest [CLDR](http://cldr.unicode.org/index/downloads) data, v31.0.1
15 - [x] Contains Cardinal, Ordinal and Range Plural Rules
16 - [x] Contains Month, Weekday and Timezone translations built in
17 - [x] Contains Date & Time formatting functions
18 - [x] Contains Number, Currency, Accounting and Percent formatting functions
19 - [x] Supports the "Gregorian" calendar only ( my time isn't unlimited, had to draw the line somewhere )
23 I could sure use your help adding tests for every locale, it is a huge undertaking and I just don't have the free time to do it all at the moment;
24 any help would be **greatly appreciated!!!!** please see [issue](https://github.com/go-playground/locales/issues/1) for details.
32 go get github.com/go-playground/locales
37 You'll notice most return types are []byte, this is because most of the time the results will be concatenated with a larger body
38 of text and can avoid some allocations if already appending to a byte array, otherwise just cast as string.
49 "github.com/go-playground/locales/currency"
50 "github.com/go-playground/locales/en_CA"
55 loc, _ := time.LoadLocation("America/Toronto")
56 datetime := time.Date(2016, 02, 03, 9, 0, 1, 0, loc)
61 fmt.Println(l.FmtDateFull(datetime))
62 fmt.Println(l.FmtDateLong(datetime))
63 fmt.Println(l.FmtDateMedium(datetime))
64 fmt.Println(l.FmtDateShort(datetime))
67 fmt.Println(l.FmtTimeFull(datetime))
68 fmt.Println(l.FmtTimeLong(datetime))
69 fmt.Println(l.FmtTimeMedium(datetime))
70 fmt.Println(l.FmtTimeShort(datetime))
73 fmt.Println(l.MonthWide(time.January))
74 fmt.Println(l.MonthWide(time.February))
75 fmt.Println(l.MonthWide(time.March))
79 fmt.Println(l.MonthAbbreviated(time.January))
80 fmt.Println(l.MonthAbbreviated(time.February))
81 fmt.Println(l.MonthAbbreviated(time.March))
85 fmt.Println(l.MonthNarrow(time.January))
86 fmt.Println(l.MonthNarrow(time.February))
87 fmt.Println(l.MonthNarrow(time.March))
91 fmt.Println(l.WeekdayWide(time.Sunday))
92 fmt.Println(l.WeekdayWide(time.Monday))
93 fmt.Println(l.WeekdayWide(time.Tuesday))
96 // Weekdays Abbreviated
97 fmt.Println(l.WeekdayAbbreviated(time.Sunday))
98 fmt.Println(l.WeekdayAbbreviated(time.Monday))
99 fmt.Println(l.WeekdayAbbreviated(time.Tuesday))
103 fmt.Println(l.WeekdayShort(time.Sunday))
104 fmt.Println(l.WeekdayShort(time.Monday))
105 fmt.Println(l.WeekdayShort(time.Tuesday))
109 fmt.Println(l.WeekdayNarrow(time.Sunday))
110 fmt.Println(l.WeekdayNarrow(time.Monday))
111 fmt.Println(l.WeekdayNarrow(time.Tuesday))
119 fmt.Println(l.FmtNumber(f64, 2))
122 fmt.Println(l.FmtCurrency(f64, 2, currency.CAD))
123 fmt.Println(l.FmtCurrency(f64, 2, currency.USD))
126 fmt.Println(l.FmtAccounting(f64, 2, currency.CAD))
127 fmt.Println(l.FmtAccounting(f64, 2, currency.USD))
132 fmt.Println(l.FmtPercent(f64, 0))
134 // Plural Rules for locale, so you know what rules you must cover
135 fmt.Println(l.PluralsCardinal())
136 fmt.Println(l.PluralsOrdinal())
138 // Cardinal Plural Rules
139 fmt.Println(l.CardinalPluralRule(1, 0))
140 fmt.Println(l.CardinalPluralRule(1.0, 0))
141 fmt.Println(l.CardinalPluralRule(1.0, 1))
142 fmt.Println(l.CardinalPluralRule(3, 0))
144 // Ordinal Plural Rules
145 fmt.Println(l.OrdinalPluralRule(21, 0)) // 21st
146 fmt.Println(l.OrdinalPluralRule(22, 0)) // 22nd
147 fmt.Println(l.OrdinalPluralRule(33, 0)) // 33rd
148 fmt.Println(l.OrdinalPluralRule(34, 0)) // 34th
150 // Range Plural Rules
151 fmt.Println(l.RangePluralRule(1, 0, 1, 0)) // 1-1
152 fmt.Println(l.RangePluralRule(1, 0, 2, 0)) // 1-2
153 fmt.Println(l.RangePluralRule(5, 0, 8, 0)) // 5-8
159 These rules were generated from the [Unicode CLDR Project](http://cldr.unicode.org/), if you encounter any issues
160 I strongly encourage contributing to the CLDR project to get the locale information corrected and the next time
161 these locales are regenerated the fix will come with.
163 I do however realize that time constraints are often important and so there are two options:
165 1. Create your own locale, copy, paste and modify, and ensure it complies with the `Translator` interface.
166 2. Add an exception in the locale generation code directly and once regenerated, fix will be in place.
168 Please to not make fixes inside the locale files, they WILL get overwritten when the locales are regenerated.
172 Distributed under MIT License, please see license file in code for more details.