8 "github.com/go-playground/locales"
9 "github.com/go-playground/locales/currency"
14 pluralsCardinal []locales.PluralRule
15 pluralsOrdinal []locales.PluralRule
16 pluralsRange []locales.PluralRule
25 currencies []string // idx = enum of currency code
26 currencyPositiveSuffix string
27 currencyNegativeSuffix string
28 monthsAbbreviated []string
31 daysAbbreviated []string
35 periodsAbbreviated []string
36 periodsNarrow []string
39 erasAbbreviated []string
42 timezones map[string]string
45 // New returns a new instance of translator for the 'br' locale
46 func New() locales.Translator {
49 pluralsCardinal: []locales.PluralRule{2, 3, 4, 5, 6},
59 currencies: []string{"ADP", "AED", "AFA", "AFN", "ALK", "ALL", "AMD", "ANG", "AOA", "AOK", "AON", "AOR", "ARA", "ARL", "ARM", "ARP", "ARS", "ATS", "$A", "AWG", "AZM", "AZN", "BAD", "BAM", "BAN", "BBD", "BDT", "BEC", "BEF", "BEL", "BGL", "BGM", "BGN", "BGO", "BHD", "BIF", "BMD", "BND", "BOB", "BOL", "BOP", "BOV", "BRB", "BRC", "BRE", "BRL", "BRN", "BRR", "BRZ", "BSD", "BTN", "BUK", "BWP", "BYB", "BYN", "BYR", "BZD", "$CA", "CDF", "CHE", "CHF", "CHW", "CLE", "CLF", "CLP", "CNX", "CNY", "COP", "COU", "CRC", "CSD", "CSK", "CUC", "CUP", "CVE", "CYP", "CZK", "DDM", "DEM", "DJF", "DKK", "DOP", "DZD", "ECS", "ECV", "EEK", "EGP", "ERN", "ESA", "ESB", "ESP", "ETB", "€", "FIM", "FJD", "FKP", "FRF", "£ RU", "GEK", "GEL", "GHC", "GHS", "GIP", "GMD", "GNF", "GNS", "GQE", "GRD", "GTQ", "GWE", "GWP", "GYD", "$ HK", "HNL", "HRD", "HRK", "HTG", "HUF", "IDR", "IEP", "ILP", "ILR", "ILS", "₹", "IQD", "IRR", "ISJ", "ISK", "ITL", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRH", "KRO", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LTL", "LTT", "LUC", "LUF", "LUL", "LVL", "LVR", "LYD", "MAD", "MAF", "MCF", "MDC", "MDL", "MGA", "MGF", "MKD", "MKN", "MLF", "MMK", "MNT", "MOP", "MRO", "MTL", "MTP", "MUR", "MVP", "MVR", "MWK", "MX$", "MXP", "MXV", "MYR", "MZE", "MZM", "MZN", "NAD", "NGN", "NIC", "NIO", "NLG", "NOK", "NPR", "$ ZN", "OMR", "PAB", "PEI", "PEN", "PES", "PGK", "PHP", "PKR", "PLN", "PLZ", "PTE", "PYG", "QAR", "RHD", "ROL", "RON", "RSD", "RUB", "RUR", "RWF", "SAR", "SBD", "SCR", "SDD", "SDG", "SDP", "SEK", "SGD", "SHP", "SIT", "SKK", "SLL", "SOS", "SRD", "SRG", "SSP", "STD", "SUR", "SVC", "SYP", "SZL", "THB", "TJR", "TJS", "TMM", "TMT", "TND", "TOP", "TPE", "TRL", "TRY", "TTD", "TWD", "TZS", "UAH", "UAK", "UGS", "UGX", "$ SU", "USN", "USS", "UYI", "UYP", "UYU", "UZS", "VEB", "VEF", "VND", "VNN", "VUV", "WST", "FCFA", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "XCD", "XDR", "XEU", "XFO", "XFU", "CFA", "XPD", "CFPF", "XPT", "XRE", "XSU", "XTS", "XUA", "XXX", "YDD", "YER", "YUD", "YUM", "YUN", "YUR", "ZAL", "ZAR", "ZMK", "ZMW", "ZRN", "ZRZ", "ZWD", "ZWL", "ZWR"},
61 currencyPositiveSuffix: " ",
62 currencyNegativeSuffix: " ",
63 monthsAbbreviated: []string{"", "Gen.", "Cʼhwe.", "Meur.", "Ebr.", "Mae", "Mezh.", "Goue.", "Eost", "Gwen.", "Here", "Du", "Kzu."},
64 monthsNarrow: []string{"", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"},
65 monthsWide: []string{"", "Genver", "Cʼhwevrer", "Meurzh", "Ebrel", "Mae", "Mezheven", "Gouere", "Eost", "Gwengolo", "Here", "Du", "Kerzu"},
66 daysAbbreviated: []string{"Sul", "Lun", "Meu.", "Mer.", "Yaou", "Gwe.", "Sad."},
67 daysNarrow: []string{"Su", "L", "Mz", "Mc", "Y", "G", "Sa"},
68 daysShort: []string{"Sul", "Lun", "Meu.", "Mer.", "Yaou", "Gwe.", "Sad."},
69 daysWide: []string{"Sul", "Lun", "Meurzh", "Mercʼher", "Yaou", "Gwener", "Sadorn"},
70 periodsAbbreviated: []string{"A.M.", "G.M."},
71 periodsNarrow: []string{"am", "gm"},
72 periodsWide: []string{"A.M.", "G.M."},
73 erasAbbreviated: []string{"a-raok J.K.", "goude J.K."},
74 erasNarrow: []string{"a-raok J.K.", "goude J.K."},
75 erasWide: []string{"a-raok Jezuz-Krist", "goude Jezuz-Krist"},
76 timezones: map[string]string{"WESZ": "eur hañv Europa ar Cʼhornôg", "ChST": "ChST", "HNPMX": "HNPMX", "UYT": "eur cʼhoañv Uruguay", "HNOG": "eur cʼhoañv Greunland ar Cʼhornôg", "CLT": "eur cʼhoañv Chile", "HAT": "eur hañv Newfoundland", "HNPM": "eur cʼhoañv Sant-Pêr-ha-Mikelon", "CST": "CST", "HNNOMX": "eur cʼhoañv Gwalarn Mecʼhiko", "OESZ": "eur hañv Europa ar Reter", "IST": "eur cʼhoañv India", "AEST": "eur cʼhoañv Aostralia ar Reter", "ADT": "ADT", "ART": "eur cʼhoañv Arcʼhantina", "CLST": "eur hañv Chile", "HKST": "eur hañv Hong Kong", "AKDT": "eur hañv Alaska", "HNCU": "eur cʼhoañv Kuba", "AST": "AST", "HNEG": "eur cʼhoañv Greunland ar Reter", "SAST": "eur cʼhoañv Suafrika", "WAT": "eur cʼhoañv Afrika ar Cʼhornôg", "EDT": "eur hañv ar Reter", "CAT": "eur Kreizafrika", "AWST": "eur cʼhoañv Aostralia ar Cʼhornôg", "NZDT": "eur hañv Zeland-Nevez", "HEOG": "eur hañv Greunland ar Cʼhornôg", "HEEG": "eur hañv Greunland ar Reter", "WIB": "eur Indonezia ar Cʼhornôg", "BOT": "eur Bolivia", "TMT": "eur cʼhoañv Turkmenistan", "MESZ": "eur hañv Kreizeuropa", "HEPMX": "HEPMX", "HEPM": "eur hañv Sant-Pêr-ha-Mikelon", "AWDT": "eur hañv Aostralia ar Cʼhornôg", "ARST": "eur hañv Arcʼhantina", "HECU": "eur hañv Kuba", "CDT": "CDT", "HADT": "HADT", "EAT": "eur Afrika ar Reter", "GFT": "eur Gwiana cʼhall", "WART": "eur cʼhoañv Arcʼhantina ar Cʼhornôg", "COT": "eur cʼhoañv Kolombia", "HKT": "eur cʼhoañv Hong Kong", "GYT": "eur Guyana", "SGT": "eur cʼhoañv Singapour", "MEZ": "eur cʼhoañv Kreizeuropa", "HENOMX": "eur hañv Gwalarn Mecʼhiko", "OEZ": "eur cʼhoañv Europa ar Reter", "LHDT": "LHDT", "WEZ": "eur cʼhoañv Europa ar Cʼhornôg", "CHAST": "eur cʼhoañv Chatham", "HAST": "HAST", "WARST": "eur hañv Arcʼhantina ar Cʼhornôg", "MST": "eur cʼhoañv Macau", "ACWDT": "eur hañv Kreizaostralia ar Cʼhornôg", "EST": "eur cʼhoañv ar Reter", "∅∅∅": "eur hañv an Amazon", "AKST": "eur cʼhoañv Alaska", "ACST": "eur cʼhoañv Kreizaostralia", "ACDT": "eur hañv Kreizaostralia", "GMT": "Amzer keitat Greenwich (AKG)", "WITA": "WITA", "JDT": "eur hañv Japan", "LHST": "LHST", "HNT": "eur cʼhoañv Newfoundland", "ECT": "eur Ecuador", "BT": "eur Bhoutan", "WIT": "eur Indonezia ar Reter", "TMST": "eur hañv Turkmenistan", "JST": "eur cʼhoañv Japan", "WAST": "eur hañv Afrika ar Cʼhornôg", "PST": "PST", "ACWST": "eur cʼhoañv Kreizaostralia ar Cʼhornôg", "MYT": "eur Malaysia", "UYST": "eur hañv Uruguay", "AEDT": "eur hañv Aostralia ar Reter", "COST": "eur hañv Kolombia", "PDT": "PDT", "CHADT": "eur hañv Chatham", "SRT": "eur Surinam", "MDT": "eur hañv Macau", "NZST": "eur cʼhoañv Zeland-Nevez", "VET": "eur Venezuela"},
80 // Locale returns the current translators string locale
81 func (br *br) Locale() string {
85 // PluralsCardinal returns the list of cardinal plural rules associated with 'br'
86 func (br *br) PluralsCardinal() []locales.PluralRule {
87 return br.pluralsCardinal
90 // PluralsOrdinal returns the list of ordinal plural rules associated with 'br'
91 func (br *br) PluralsOrdinal() []locales.PluralRule {
92 return br.pluralsOrdinal
95 // PluralsRange returns the list of range plural rules associated with 'br'
96 func (br *br) PluralsRange() []locales.PluralRule {
97 return br.pluralsRange
100 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'br'
101 func (br *br) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
104 nMod1000000 := math.Mod(n, 1000000)
105 nMod10 := math.Mod(n, 10)
106 nMod100 := math.Mod(n, 100)
108 if nMod10 == 1 && (nMod100 != 11 && nMod100 != 71 && nMod100 != 91) {
109 return locales.PluralRuleOne
110 } else if nMod10 == 2 && (nMod100 != 12 && nMod100 != 72 && nMod100 != 92) {
111 return locales.PluralRuleTwo
112 } else if nMod10 >= 3 && nMod10 <= 4 && (nMod10 == 9) && (nMod100 < 10 || nMod100 > 19) || (nMod100 < 70 || nMod100 > 79) || (nMod100 < 90 || nMod100 > 99) {
113 return locales.PluralRuleFew
114 } else if n != 0 && nMod1000000 == 0 {
115 return locales.PluralRuleMany
118 return locales.PluralRuleOther
121 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'br'
122 func (br *br) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
123 return locales.PluralRuleUnknown
126 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'br'
127 func (br *br) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
128 return locales.PluralRuleUnknown
131 // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
132 func (br *br) MonthAbbreviated(month time.Month) string {
133 return br.monthsAbbreviated[month]
136 // MonthsAbbreviated returns the locales abbreviated months
137 func (br *br) MonthsAbbreviated() []string {
138 return br.monthsAbbreviated[1:]
141 // MonthNarrow returns the locales narrow month given the 'month' provided
142 func (br *br) MonthNarrow(month time.Month) string {
143 return br.monthsNarrow[month]
146 // MonthsNarrow returns the locales narrow months
147 func (br *br) MonthsNarrow() []string {
148 return br.monthsNarrow[1:]
151 // MonthWide returns the locales wide month given the 'month' provided
152 func (br *br) MonthWide(month time.Month) string {
153 return br.monthsWide[month]
156 // MonthsWide returns the locales wide months
157 func (br *br) MonthsWide() []string {
158 return br.monthsWide[1:]
161 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
162 func (br *br) WeekdayAbbreviated(weekday time.Weekday) string {
163 return br.daysAbbreviated[weekday]
166 // WeekdaysAbbreviated returns the locales abbreviated weekdays
167 func (br *br) WeekdaysAbbreviated() []string {
168 return br.daysAbbreviated
171 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
172 func (br *br) WeekdayNarrow(weekday time.Weekday) string {
173 return br.daysNarrow[weekday]
176 // WeekdaysNarrow returns the locales narrow weekdays
177 func (br *br) WeekdaysNarrow() []string {
181 // WeekdayShort returns the locales short weekday given the 'weekday' provided
182 func (br *br) WeekdayShort(weekday time.Weekday) string {
183 return br.daysShort[weekday]
186 // WeekdaysShort returns the locales short weekdays
187 func (br *br) WeekdaysShort() []string {
191 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
192 func (br *br) WeekdayWide(weekday time.Weekday) string {
193 return br.daysWide[weekday]
196 // WeekdaysWide returns the locales wide weekdays
197 func (br *br) WeekdaysWide() []string {
201 // Decimal returns the decimal point of number
202 func (br *br) Decimal() string {
206 // Group returns the group of number
207 func (br *br) Group() string {
211 // Group returns the minus sign of number
212 func (br *br) Minus() string {
216 // FmtNumber returns 'num' with digits/precision of 'v' for 'br' and handles both Whole and Real numbers based on 'v'
217 func (br *br) FmtNumber(num float64, v uint64) string {
219 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
220 l := len(s) + 2 + 2*len(s[:len(s)-int(v)-1])/3
223 b := make([]byte, 0, l)
225 for i := len(s) - 1; i >= 0; i-- {
228 b = append(b, br.decimal[0])
235 for j := len(br.group) - 1; j >= 0; j-- {
236 b = append(b, br.group[j])
248 b = append(b, br.minus[0])
252 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
253 b[i], b[j] = b[j], b[i]
259 // FmtPercent returns 'num' with digits/precision of 'v' for 'br' and handles both Whole and Real numbers based on 'v'
260 // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
261 func (br *br) FmtPercent(num float64, v uint64) string {
262 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
264 b := make([]byte, 0, l)
266 for i := len(s) - 1; i >= 0; i-- {
269 b = append(b, br.decimal[0])
277 b = append(b, br.minus[0])
281 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
282 b[i], b[j] = b[j], b[i]
285 b = append(b, br.percentSuffix...)
287 b = append(b, br.percent...)
292 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'br'
293 func (br *br) FmtCurrency(num float64, v uint64, currency currency.Type) string {
295 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
296 symbol := br.currencies[currency]
297 l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
300 b := make([]byte, 0, l)
302 for i := len(s) - 1; i >= 0; i-- {
305 b = append(b, br.decimal[0])
312 for j := len(br.group) - 1; j >= 0; j-- {
313 b = append(b, br.group[j])
325 b = append(b, br.minus[0])
329 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
330 b[i], b[j] = b[j], b[i]
336 b = append(b, br.decimal...)
339 for i := 0; i < 2-int(v); i++ {
344 b = append(b, br.currencyPositiveSuffix...)
346 b = append(b, symbol...)
351 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'br'
352 // in accounting notation.
353 func (br *br) FmtAccounting(num float64, v uint64, currency currency.Type) string {
355 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
356 symbol := br.currencies[currency]
357 l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
360 b := make([]byte, 0, l)
362 for i := len(s) - 1; i >= 0; i-- {
365 b = append(b, br.decimal[0])
372 for j := len(br.group) - 1; j >= 0; j-- {
373 b = append(b, br.group[j])
386 b = append(b, br.minus[0])
391 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
392 b[i], b[j] = b[j], b[i]
398 b = append(b, br.decimal...)
401 for i := 0; i < 2-int(v); i++ {
407 b = append(b, br.currencyNegativeSuffix...)
408 b = append(b, symbol...)
411 b = append(b, br.currencyPositiveSuffix...)
412 b = append(b, symbol...)
418 // FmtDateShort returns the short date representation of 't' for 'br'
419 func (br *br) FmtDateShort(t time.Time) string {
421 b := make([]byte, 0, 32)
424 b = strconv.AppendInt(b, int64(t.Year()), 10)
426 b = strconv.AppendInt(b, int64(-t.Year()), 10)
429 b = append(b, []byte{0x2d}...)
435 b = strconv.AppendInt(b, int64(t.Month()), 10)
437 b = append(b, []byte{0x2d}...)
443 b = strconv.AppendInt(b, int64(t.Day()), 10)
448 // FmtDateMedium returns the medium date representation of 't' for 'br'
449 func (br *br) FmtDateMedium(t time.Time) string {
451 b := make([]byte, 0, 32)
454 b = strconv.AppendInt(b, int64(t.Year()), 10)
456 b = strconv.AppendInt(b, int64(-t.Year()), 10)
459 b = append(b, []byte{0x20}...)
460 b = append(b, br.monthsAbbreviated[t.Month()]...)
461 b = append(b, []byte{0x20}...)
462 b = strconv.AppendInt(b, int64(t.Day()), 10)
467 // FmtDateLong returns the long date representation of 't' for 'br'
468 func (br *br) FmtDateLong(t time.Time) string {
470 b := make([]byte, 0, 32)
473 b = strconv.AppendInt(b, int64(t.Year()), 10)
475 b = strconv.AppendInt(b, int64(-t.Year()), 10)
478 b = append(b, []byte{0x20}...)
479 b = append(b, br.monthsWide[t.Month()]...)
480 b = append(b, []byte{0x20}...)
481 b = strconv.AppendInt(b, int64(t.Day()), 10)
486 // FmtDateFull returns the full date representation of 't' for 'br'
487 func (br *br) FmtDateFull(t time.Time) string {
489 b := make([]byte, 0, 32)
492 b = strconv.AppendInt(b, int64(t.Year()), 10)
494 b = strconv.AppendInt(b, int64(-t.Year()), 10)
497 b = append(b, []byte{0x20}...)
498 b = append(b, br.monthsWide[t.Month()]...)
499 b = append(b, []byte{0x20}...)
500 b = strconv.AppendInt(b, int64(t.Day()), 10)
501 b = append(b, []byte{0x2c, 0x20}...)
502 b = append(b, br.daysWide[t.Weekday()]...)
507 // FmtTimeShort returns the short time representation of 't' for 'br'
508 func (br *br) FmtTimeShort(t time.Time) string {
510 b := make([]byte, 0, 32)
516 b = strconv.AppendInt(b, int64(t.Hour()), 10)
517 b = append(b, br.timeSeparator...)
523 b = strconv.AppendInt(b, int64(t.Minute()), 10)
528 // FmtTimeMedium returns the medium time representation of 't' for 'br'
529 func (br *br) FmtTimeMedium(t time.Time) string {
531 b := make([]byte, 0, 32)
537 b = strconv.AppendInt(b, int64(t.Hour()), 10)
538 b = append(b, br.timeSeparator...)
544 b = strconv.AppendInt(b, int64(t.Minute()), 10)
545 b = append(b, br.timeSeparator...)
551 b = strconv.AppendInt(b, int64(t.Second()), 10)
556 // FmtTimeLong returns the long time representation of 't' for 'br'
557 func (br *br) FmtTimeLong(t time.Time) string {
559 b := make([]byte, 0, 32)
565 b = strconv.AppendInt(b, int64(t.Hour()), 10)
566 b = append(b, br.timeSeparator...)
572 b = strconv.AppendInt(b, int64(t.Minute()), 10)
573 b = append(b, br.timeSeparator...)
579 b = strconv.AppendInt(b, int64(t.Second()), 10)
580 b = append(b, []byte{0x20}...)
588 // FmtTimeFull returns the full time representation of 't' for 'br'
589 func (br *br) FmtTimeFull(t time.Time) string {
591 b := make([]byte, 0, 32)
597 b = strconv.AppendInt(b, int64(t.Hour()), 10)
598 b = append(b, br.timeSeparator...)
604 b = strconv.AppendInt(b, int64(t.Minute()), 10)
605 b = append(b, br.timeSeparator...)
611 b = strconv.AppendInt(b, int64(t.Second()), 10)
612 b = append(b, []byte{0x20}...)
616 if btz, ok := br.timezones[tz]; ok {
617 b = append(b, btz...)