README.md (5555B)
1 ## locales 2 <img align="right" src="https://raw.githubusercontent.com/go-playground/locales/master/logo.png">![Project status](https://img.shields.io/badge/version-0.14.1-green.svg) 3 [![Build Status](https://travis-ci.org/go-playground/locales.svg?branch=master)](https://travis-ci.org/go-playground/locales) 4 [![GoDoc](https://godoc.org/github.com/go-playground/locales?status.svg)](https://godoc.org/github.com/go-playground/locales) 5 ![License](https://img.shields.io/dub/l/vibe-d.svg) 6 7 Locales is a set of locales generated from the [Unicode CLDR Project](http://cldr.unicode.org/) which can be used independently or within 8 an i18n package; these were built for use with, but not exclusive to, [Universal Translator](https://github.com/go-playground/universal-translator). 9 10 Features 11 -------- 12 - [x] Rules generated from the latest [CLDR](http://cldr.unicode.org/index/downloads) data, v36.0.1 13 - [x] Contains Cardinal, Ordinal and Range Plural Rules 14 - [x] Contains Month, Weekday and Timezone translations built in 15 - [x] Contains Date & Time formatting functions 16 - [x] Contains Number, Currency, Accounting and Percent formatting functions 17 - [x] Supports the "Gregorian" calendar only ( my time isn't unlimited, had to draw the line somewhere ) 18 19 Full Tests 20 -------------------- 21 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; 22 any help would be **greatly appreciated!!!!** please see [issue](https://github.com/go-playground/locales/issues/1) for details. 23 24 Installation 25 ----------- 26 27 Use go get 28 29 ```shell 30 go get github.com/go-playground/locales 31 ``` 32 33 NOTES 34 -------- 35 You'll notice most return types are []byte, this is because most of the time the results will be concatenated with a larger body 36 of text and can avoid some allocations if already appending to a byte array, otherwise just cast as string. 37 38 Usage 39 ------- 40 ```go 41 package main 42 43 import ( 44 "fmt" 45 "time" 46 47 "github.com/go-playground/locales/currency" 48 "github.com/go-playground/locales/en_CA" 49 ) 50 51 func main() { 52 53 loc, _ := time.LoadLocation("America/Toronto") 54 datetime := time.Date(2016, 02, 03, 9, 0, 1, 0, loc) 55 56 l := en_CA.New() 57 58 // Dates 59 fmt.Println(l.FmtDateFull(datetime)) 60 fmt.Println(l.FmtDateLong(datetime)) 61 fmt.Println(l.FmtDateMedium(datetime)) 62 fmt.Println(l.FmtDateShort(datetime)) 63 64 // Times 65 fmt.Println(l.FmtTimeFull(datetime)) 66 fmt.Println(l.FmtTimeLong(datetime)) 67 fmt.Println(l.FmtTimeMedium(datetime)) 68 fmt.Println(l.FmtTimeShort(datetime)) 69 70 // Months Wide 71 fmt.Println(l.MonthWide(time.January)) 72 fmt.Println(l.MonthWide(time.February)) 73 fmt.Println(l.MonthWide(time.March)) 74 // ... 75 76 // Months Abbreviated 77 fmt.Println(l.MonthAbbreviated(time.January)) 78 fmt.Println(l.MonthAbbreviated(time.February)) 79 fmt.Println(l.MonthAbbreviated(time.March)) 80 // ... 81 82 // Months Narrow 83 fmt.Println(l.MonthNarrow(time.January)) 84 fmt.Println(l.MonthNarrow(time.February)) 85 fmt.Println(l.MonthNarrow(time.March)) 86 // ... 87 88 // Weekdays Wide 89 fmt.Println(l.WeekdayWide(time.Sunday)) 90 fmt.Println(l.WeekdayWide(time.Monday)) 91 fmt.Println(l.WeekdayWide(time.Tuesday)) 92 // ... 93 94 // Weekdays Abbreviated 95 fmt.Println(l.WeekdayAbbreviated(time.Sunday)) 96 fmt.Println(l.WeekdayAbbreviated(time.Monday)) 97 fmt.Println(l.WeekdayAbbreviated(time.Tuesday)) 98 // ... 99 100 // Weekdays Short 101 fmt.Println(l.WeekdayShort(time.Sunday)) 102 fmt.Println(l.WeekdayShort(time.Monday)) 103 fmt.Println(l.WeekdayShort(time.Tuesday)) 104 // ... 105 106 // Weekdays Narrow 107 fmt.Println(l.WeekdayNarrow(time.Sunday)) 108 fmt.Println(l.WeekdayNarrow(time.Monday)) 109 fmt.Println(l.WeekdayNarrow(time.Tuesday)) 110 // ... 111 112 var f64 float64 113 114 f64 = -10356.4523 115 116 // Number 117 fmt.Println(l.FmtNumber(f64, 2)) 118 119 // Currency 120 fmt.Println(l.FmtCurrency(f64, 2, currency.CAD)) 121 fmt.Println(l.FmtCurrency(f64, 2, currency.USD)) 122 123 // Accounting 124 fmt.Println(l.FmtAccounting(f64, 2, currency.CAD)) 125 fmt.Println(l.FmtAccounting(f64, 2, currency.USD)) 126 127 f64 = 78.12 128 129 // Percent 130 fmt.Println(l.FmtPercent(f64, 0)) 131 132 // Plural Rules for locale, so you know what rules you must cover 133 fmt.Println(l.PluralsCardinal()) 134 fmt.Println(l.PluralsOrdinal()) 135 136 // Cardinal Plural Rules 137 fmt.Println(l.CardinalPluralRule(1, 0)) 138 fmt.Println(l.CardinalPluralRule(1.0, 0)) 139 fmt.Println(l.CardinalPluralRule(1.0, 1)) 140 fmt.Println(l.CardinalPluralRule(3, 0)) 141 142 // Ordinal Plural Rules 143 fmt.Println(l.OrdinalPluralRule(21, 0)) // 21st 144 fmt.Println(l.OrdinalPluralRule(22, 0)) // 22nd 145 fmt.Println(l.OrdinalPluralRule(33, 0)) // 33rd 146 fmt.Println(l.OrdinalPluralRule(34, 0)) // 34th 147 148 // Range Plural Rules 149 fmt.Println(l.RangePluralRule(1, 0, 1, 0)) // 1-1 150 fmt.Println(l.RangePluralRule(1, 0, 2, 0)) // 1-2 151 fmt.Println(l.RangePluralRule(5, 0, 8, 0)) // 5-8 152 } 153 ``` 154 155 NOTES: 156 ------- 157 These rules were generated from the [Unicode CLDR Project](http://cldr.unicode.org/), if you encounter any issues 158 I strongly encourage contributing to the CLDR project to get the locale information corrected and the next time 159 these locales are regenerated the fix will come with. 160 161 I do however realize that time constraints are often important and so there are two options: 162 163 1. Create your own locale, copy, paste and modify, and ensure it complies with the `Translator` interface. 164 2. Add an exception in the locale generation code directly and once regenerated, fix will be in place. 165 166 Please to not make fixes inside the locale files, they WILL get overwritten when the locales are regenerated. 167 168 License 169 ------ 170 Distributed under MIT License, please see license file in code for more details.