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
24 currencies []string // idx = enum of currency code
25 currencyPositivePrefix string
26 currencyNegativePrefix string
27 monthsAbbreviated []string
30 daysAbbreviated []string
34 periodsAbbreviated []string
35 periodsNarrow []string
38 erasAbbreviated []string
41 timezones map[string]string
44 // New returns a new instance of translator for the 'bo' locale
45 func New() locales.Translator {
48 pluralsCardinal: []locales.PluralRule{6},
54 currencies: []string{"ADP", "AED", "AFA", "AFN", "ALK", "ALL", "AMD", "ANG", "AOA", "AOK", "AON", "AOR", "ARA", "ARL", "ARM", "ARP", "ARS", "ATS", "AUD", "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", "CAD", "CDF", "CHE", "CHF", "CHW", "CLE", "CLF", "CLP", "CNX", "¥", "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", "EUR", "FIM", "FJD", "FKP", "FRF", "GBP", "GEK", "GEL", "GHC", "GHS", "GIP", "GMD", "GNF", "GNS", "GQE", "GRD", "GTQ", "GWE", "GWP", "GYD", "HKD", "HNL", "HRD", "HRK", "HTG", "HUF", "IDR", "IEP", "ILP", "ILR", "ILS", "INR", "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", "MXN", "MXP", "MXV", "MYR", "MZE", "MZM", "MZN", "NAD", "NGN", "NIC", "NIO", "NLG", "NOK", "NPR", "NZD", "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", "USD", "USN", "USS", "UYI", "UYP", "UYU", "UZS", "VEB", "VEF", "VND", "VNN", "VUV", "WST", "XAF", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "XCD", "XDR", "XEU", "XFO", "XFU", "XOF", "XPD", "XPF", "XPT", "XRE", "XSU", "XTS", "XUA", "XXX", "YDD", "YER", "YUD", "YUM", "YUN", "YUR", "ZAL", "ZAR", "ZMK", "ZMW", "ZRN", "ZRZ", "ZWD", "ZWL", "ZWR"},
55 currencyPositivePrefix: " ",
56 currencyNegativePrefix: " ",
57 monthsAbbreviated: []string{"", "ཟླ་༡", "ཟླ་༢", "ཟླ་༣", "ཟླ་༤", "ཟླ་༥", "ཟླ་༦", "ཟླ་༧", "ཟླ་༨", "ཟླ་༩", "ཟླ་༡༠", "ཟླ་༡༡", "ཟླ་༡༢"},
58 monthsWide: []string{"", "ཟླ་བ་དང་པོ", "ཟླ་བ་གཉིས་པ", "ཟླ་བ་གསུམ་པ", "ཟླ་བ་བཞི་པ", "ཟླ་བ་ལྔ་པ", "ཟླ་བ་དྲུག་པ", "ཟླ་བ་བདུན་པ", "ཟླ་བ་བརྒྱད་པ", "ཟླ་བ་དགུ་པ", "ཟླ་བ་བཅུ་པ", "ཟླ་བ་བཅུ་གཅིག་པ", "ཟླ་བ་བཅུ་གཉིས་པ"},
59 daysAbbreviated: []string{"ཉི་མ་", "ཟླ་བ་", "མིག་དམར་", "ལྷག་པ་", "ཕུར་བུ་", "པ་སངས་", "སྤེན་པ་"},
60 daysNarrow: []string{"ཉི", "ཟླ", "མིག", "ལྷག", "ཕུར", "སངས", "སྤེན"},
61 daysWide: []string{"གཟའ་ཉི་མ་", "གཟའ་ཟླ་བ་", "གཟའ་མིག་དམར་", "གཟའ་ལྷག་པ་", "གཟའ་ཕུར་བུ་", "གཟའ་པ་སངས་", "གཟའ་སྤེན་པ་"},
62 periodsAbbreviated: []string{"སྔ་དྲོ་", "ཕྱི་དྲོ་"},
63 periodsWide: []string{"སྔ་དྲོ་", "ཕྱི་དྲོ་"},
64 erasAbbreviated: []string{"སྤྱི་ལོ་སྔོན་", "སྤྱི་ལོ་"},
65 erasNarrow: []string{"", ""},
66 erasWide: []string{"", ""},
67 timezones: map[string]string{"∅∅∅": "∅∅∅", "CST": "CST", "MESZ": "MESZ", "HEEG": "HEEG", "MST": "MST", "MYT": "MYT", "WIT": "WIT", "HAST": "HAST", "NZST": "NZST", "WART": "WART", "WAT": "WAT", "CHADT": "CHADT", "HNPM": "HNPM", "OESZ": "OESZ", "HKT": "HKT", "CLT": "CLT", "EST": "EST", "GYT": "GYT", "BT": "BT", "OEZ": "OEZ", "WITA": "WITA", "HEOG": "HEOG", "WEZ": "WEZ", "GMT": "GMT", "BOT": "BOT", "UYST": "UYST", "HADT": "HADT", "LHST": "LHST", "HENOMX": "HENOMX", "COT": "COT", "ACWDT": "ACWDT", "HNNOMX": "HNNOMX", "HAT": "HAT", "ACST": "ACST", "SGT": "SGT", "ChST": "ChST", "HECU": "HECU", "WARST": "WARST", "VET": "VET", "ARST": "ARST", "EAT": "EAT", "SAST": "SAST", "HNEG": "HNEG", "HNPMX": "HNPMX", "HEPMX": "HEPMX", "AWDT": "AWDT", "JDT": "JDT", "AKDT": "AKDT", "NZDT": "NZDT", "JST": "JST", "HKST": "HKST", "EDT": "EDT", "ECT": "ECT", "CAT": "CAT", "WESZ": "WESZ", "LHDT": "LHDT", "AST": "AST", "COST": "COST", "CDT": "CDT", "SRT": "SRT", "ACWST": "ACWST", "MEZ": "MEZ", "PDT": "PDT", "TMT": "TMT", "TMST": "TMST", "HNCU": "HNCU", "HEPM": "HEPM", "MDT": "MDT", "IST": "IST", "WIB": "WIB", "AWST": "AWST", "ACDT": "ACDT", "PST": "PST", "CHAST": "CHAST", "UYT": "UYT", "AEST": "AEST", "ADT": "ADT", "AEDT": "AEDT", "ART": "ART", "HNOG": "HNOG", "WAST": "WAST", "HNT": "HNT", "CLST": "CLST", "GFT": "GFT", "AKST": "AKST"},
71 // Locale returns the current translators string locale
72 func (bo *bo) Locale() string {
76 // PluralsCardinal returns the list of cardinal plural rules associated with 'bo'
77 func (bo *bo) PluralsCardinal() []locales.PluralRule {
78 return bo.pluralsCardinal
81 // PluralsOrdinal returns the list of ordinal plural rules associated with 'bo'
82 func (bo *bo) PluralsOrdinal() []locales.PluralRule {
83 return bo.pluralsOrdinal
86 // PluralsRange returns the list of range plural rules associated with 'bo'
87 func (bo *bo) PluralsRange() []locales.PluralRule {
88 return bo.pluralsRange
91 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'bo'
92 func (bo *bo) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
93 return locales.PluralRuleOther
96 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'bo'
97 func (bo *bo) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
98 return locales.PluralRuleUnknown
101 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'bo'
102 func (bo *bo) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
103 return locales.PluralRuleUnknown
106 // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
107 func (bo *bo) MonthAbbreviated(month time.Month) string {
108 return bo.monthsAbbreviated[month]
111 // MonthsAbbreviated returns the locales abbreviated months
112 func (bo *bo) MonthsAbbreviated() []string {
113 return bo.monthsAbbreviated[1:]
116 // MonthNarrow returns the locales narrow month given the 'month' provided
117 func (bo *bo) MonthNarrow(month time.Month) string {
118 return bo.monthsNarrow[month]
121 // MonthsNarrow returns the locales narrow months
122 func (bo *bo) MonthsNarrow() []string {
126 // MonthWide returns the locales wide month given the 'month' provided
127 func (bo *bo) MonthWide(month time.Month) string {
128 return bo.monthsWide[month]
131 // MonthsWide returns the locales wide months
132 func (bo *bo) MonthsWide() []string {
133 return bo.monthsWide[1:]
136 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
137 func (bo *bo) WeekdayAbbreviated(weekday time.Weekday) string {
138 return bo.daysAbbreviated[weekday]
141 // WeekdaysAbbreviated returns the locales abbreviated weekdays
142 func (bo *bo) WeekdaysAbbreviated() []string {
143 return bo.daysAbbreviated
146 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
147 func (bo *bo) WeekdayNarrow(weekday time.Weekday) string {
148 return bo.daysNarrow[weekday]
151 // WeekdaysNarrow returns the locales narrow weekdays
152 func (bo *bo) WeekdaysNarrow() []string {
156 // WeekdayShort returns the locales short weekday given the 'weekday' provided
157 func (bo *bo) WeekdayShort(weekday time.Weekday) string {
158 return bo.daysShort[weekday]
161 // WeekdaysShort returns the locales short weekdays
162 func (bo *bo) WeekdaysShort() []string {
166 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
167 func (bo *bo) WeekdayWide(weekday time.Weekday) string {
168 return bo.daysWide[weekday]
171 // WeekdaysWide returns the locales wide weekdays
172 func (bo *bo) WeekdaysWide() []string {
176 // Decimal returns the decimal point of number
177 func (bo *bo) Decimal() string {
181 // Group returns the group of number
182 func (bo *bo) Group() string {
186 // Group returns the minus sign of number
187 func (bo *bo) Minus() string {
191 // FmtNumber returns 'num' with digits/precision of 'v' for 'bo' and handles both Whole and Real numbers based on 'v'
192 func (bo *bo) FmtNumber(num float64, v uint64) string {
194 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
195 l := len(s) + 1 + 1*len(s[:len(s)-int(v)-1])/3
198 b := make([]byte, 0, l)
200 for i := len(s) - 1; i >= 0; i-- {
203 b = append(b, bo.decimal[0])
210 b = append(b, bo.group[0])
221 b = append(b, bo.minus[0])
225 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
226 b[i], b[j] = b[j], b[i]
232 // FmtPercent returns 'num' with digits/precision of 'v' for 'bo' and handles both Whole and Real numbers based on 'v'
233 // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
234 func (bo *bo) FmtPercent(num float64, v uint64) string {
235 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
237 b := make([]byte, 0, l)
239 for i := len(s) - 1; i >= 0; i-- {
242 b = append(b, bo.decimal[0])
250 b = append(b, bo.minus[0])
254 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
255 b[i], b[j] = b[j], b[i]
258 b = append(b, bo.percent...)
263 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'bo'
264 func (bo *bo) FmtCurrency(num float64, v uint64, currency currency.Type) string {
266 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
267 symbol := bo.currencies[currency]
268 l := len(s) + len(symbol) + 3 + 1*len(s[:len(s)-int(v)-1])/3
271 b := make([]byte, 0, l)
273 for i := len(s) - 1; i >= 0; i-- {
276 b = append(b, bo.decimal[0])
283 b = append(b, bo.group[0])
293 for j := len(symbol) - 1; j >= 0; j-- {
294 b = append(b, symbol[j])
297 for j := len(bo.currencyPositivePrefix) - 1; j >= 0; j-- {
298 b = append(b, bo.currencyPositivePrefix[j])
302 b = append(b, bo.minus[0])
306 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
307 b[i], b[j] = b[j], b[i]
313 b = append(b, bo.decimal...)
316 for i := 0; i < 2-int(v); i++ {
324 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'bo'
325 // in accounting notation.
326 func (bo *bo) FmtAccounting(num float64, v uint64, currency currency.Type) string {
328 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
329 symbol := bo.currencies[currency]
330 l := len(s) + len(symbol) + 3 + 1*len(s[:len(s)-int(v)-1])/3
333 b := make([]byte, 0, l)
335 for i := len(s) - 1; i >= 0; i-- {
338 b = append(b, bo.decimal[0])
345 b = append(b, bo.group[0])
357 for j := len(symbol) - 1; j >= 0; j-- {
358 b = append(b, symbol[j])
361 for j := len(bo.currencyNegativePrefix) - 1; j >= 0; j-- {
362 b = append(b, bo.currencyNegativePrefix[j])
365 b = append(b, bo.minus[0])
369 for j := len(symbol) - 1; j >= 0; j-- {
370 b = append(b, symbol[j])
373 for j := len(bo.currencyPositivePrefix) - 1; j >= 0; j-- {
374 b = append(b, bo.currencyPositivePrefix[j])
380 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
381 b[i], b[j] = b[j], b[i]
387 b = append(b, bo.decimal...)
390 for i := 0; i < 2-int(v); i++ {
398 // FmtDateShort returns the short date representation of 't' for 'bo'
399 func (bo *bo) FmtDateShort(t time.Time) string {
401 b := make([]byte, 0, 32)
404 b = strconv.AppendInt(b, int64(t.Year()), 10)
406 b = strconv.AppendInt(b, int64(-t.Year()), 10)
409 b = append(b, []byte{0x2d}...)
415 b = strconv.AppendInt(b, int64(t.Month()), 10)
417 b = append(b, []byte{0x2d}...)
423 b = strconv.AppendInt(b, int64(t.Day()), 10)
428 // FmtDateMedium returns the medium date representation of 't' for 'bo'
429 func (bo *bo) FmtDateMedium(t time.Time) string {
431 b := make([]byte, 0, 32)
434 b = strconv.AppendInt(b, int64(t.Year()), 10)
436 b = strconv.AppendInt(b, int64(-t.Year()), 10)
439 b = append(b, []byte{0x20, 0xe0, 0xbd, 0xa3, 0xe0, 0xbd, 0xbc, 0xe0, 0xbd, 0xa0, 0xe0, 0xbd, 0xb2, 0xe0, 0xbc, 0x8b}...)
440 b = append(b, bo.monthsAbbreviated[t.Month()]...)
441 b = append(b, []byte{0xe0, 0xbd, 0x9a, 0xe0, 0xbd, 0xba, 0xe0, 0xbd, 0xa6, 0xe0, 0xbc, 0x8b}...)
442 b = strconv.AppendInt(b, int64(t.Day()), 10)
447 // FmtDateLong returns the long date representation of 't' for 'bo'
448 func (bo *bo) FmtDateLong(t time.Time) string {
450 b := make([]byte, 0, 32)
452 b = append(b, []byte{0xe0, 0xbd, 0xa6, 0xe0, 0xbe, 0xa4, 0xe0, 0xbe, 0xb1, 0xe0, 0xbd, 0xb2, 0xe0, 0xbc, 0x8b, 0xe0, 0xbd, 0xa3, 0xe0, 0xbd, 0xbc, 0xe0, 0xbc, 0x8b}...)
455 b = strconv.AppendInt(b, int64(t.Year()), 10)
457 b = strconv.AppendInt(b, int64(-t.Year()), 10)
460 b = append(b, []byte{0x20}...)
461 b = append(b, bo.monthsWide[t.Month()]...)
462 b = append(b, []byte{0xe0, 0xbd, 0xa0, 0xe0, 0xbd, 0xb2, 0xe0, 0xbc, 0x8b, 0xe0, 0xbd, 0x9a, 0xe0, 0xbd, 0xba, 0xe0, 0xbd, 0xa6, 0xe0, 0xbc, 0x8b}...)
463 b = strconv.AppendInt(b, int64(t.Day()), 10)
468 // FmtDateFull returns the full date representation of 't' for 'bo'
469 func (bo *bo) FmtDateFull(t time.Time) string {
471 b := make([]byte, 0, 32)
474 b = strconv.AppendInt(b, int64(t.Year()), 10)
476 b = strconv.AppendInt(b, int64(-t.Year()), 10)
479 b = append(b, []byte{0x20}...)
480 b = append(b, bo.monthsWide[t.Month()]...)
481 b = append(b, []byte{0xe0, 0xbd, 0xa0, 0xe0, 0xbd, 0xb2, 0xe0, 0xbc, 0x8b, 0xe0, 0xbd, 0x9a, 0xe0, 0xbd, 0xba, 0xe0, 0xbd, 0xa6, 0xe0, 0xbc, 0x8b}...)
482 b = strconv.AppendInt(b, int64(t.Day()), 10)
483 b = append(b, []byte{0x2c, 0x20}...)
484 b = append(b, bo.daysWide[t.Weekday()]...)
489 // FmtTimeShort returns the short time representation of 't' for 'bo'
490 func (bo *bo) FmtTimeShort(t time.Time) string {
492 b := make([]byte, 0, 32)
500 b = strconv.AppendInt(b, int64(h), 10)
501 b = append(b, bo.timeSeparator...)
507 b = strconv.AppendInt(b, int64(t.Minute()), 10)
508 b = append(b, []byte{0x20}...)
511 b = append(b, bo.periodsAbbreviated[0]...)
513 b = append(b, bo.periodsAbbreviated[1]...)
519 // FmtTimeMedium returns the medium time representation of 't' for 'bo'
520 func (bo *bo) FmtTimeMedium(t time.Time) string {
522 b := make([]byte, 0, 32)
530 b = strconv.AppendInt(b, int64(h), 10)
531 b = append(b, bo.timeSeparator...)
537 b = strconv.AppendInt(b, int64(t.Minute()), 10)
538 b = append(b, bo.timeSeparator...)
544 b = strconv.AppendInt(b, int64(t.Second()), 10)
545 b = append(b, []byte{0x20}...)
548 b = append(b, bo.periodsAbbreviated[0]...)
550 b = append(b, bo.periodsAbbreviated[1]...)
556 // FmtTimeLong returns the long time representation of 't' for 'bo'
557 func (bo *bo) FmtTimeLong(t time.Time) string {
559 b := make([]byte, 0, 32)
567 b = strconv.AppendInt(b, int64(h), 10)
568 b = append(b, bo.timeSeparator...)
574 b = strconv.AppendInt(b, int64(t.Minute()), 10)
575 b = append(b, bo.timeSeparator...)
581 b = strconv.AppendInt(b, int64(t.Second()), 10)
582 b = append(b, []byte{0x20}...)
585 b = append(b, bo.periodsAbbreviated[0]...)
587 b = append(b, bo.periodsAbbreviated[1]...)
590 b = append(b, []byte{0x20}...)
598 // FmtTimeFull returns the full time representation of 't' for 'bo'
599 func (bo *bo) FmtTimeFull(t time.Time) string {
601 b := make([]byte, 0, 32)
609 b = strconv.AppendInt(b, int64(h), 10)
610 b = append(b, bo.timeSeparator...)
616 b = strconv.AppendInt(b, int64(t.Minute()), 10)
617 b = append(b, bo.timeSeparator...)
623 b = strconv.AppendInt(b, int64(t.Second()), 10)
624 b = append(b, []byte{0x20}...)
627 b = append(b, bo.periodsAbbreviated[0]...)
629 b = append(b, bo.periodsAbbreviated[1]...)
632 b = append(b, []byte{0x20}...)
636 if btz, ok := bo.timezones[tz]; ok {
637 b = append(b, btz...)