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 currencyNegativePrefix string
26 currencyNegativeSuffix 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 'bem' locale
45 func New() locales.Translator {
48 pluralsCardinal: []locales.PluralRule{2, 6},
52 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", "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", "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", "K", "ZRN", "ZRZ", "ZWD", "ZWL", "ZWR"},
53 currencyNegativePrefix: "(",
54 currencyNegativeSuffix: ")",
55 monthsAbbreviated: []string{"", "Jan", "Feb", "Mac", "Epr", "Mei", "Jun", "Jul", "Oga", "Sep", "Okt", "Nov", "Dis"},
56 monthsNarrow: []string{"", "J", "F", "M", "E", "M", "J", "J", "O", "S", "O", "N", "D"},
57 monthsWide: []string{"", "Januari", "Februari", "Machi", "Epreo", "Mei", "Juni", "Julai", "Ogasti", "Septemba", "Oktoba", "Novemba", "Disemba"},
58 daysWide: []string{"Pa Mulungu", "Palichimo", "Palichibuli", "Palichitatu", "Palichine", "Palichisano", "Pachibelushi"},
59 periodsAbbreviated: []string{"uluchelo", "akasuba"},
60 periodsWide: []string{"uluchelo", "akasuba"},
61 erasAbbreviated: []string{"BC", "AD"},
62 erasNarrow: []string{"", ""},
63 erasWide: []string{"Before Yesu", "After Yesu"},
64 timezones: map[string]string{"NZST": "NZST", "CLT": "CLT", "COST": "COST", "BT": "BT", "UYT": "UYT", "MEZ": "MEZ", "AST": "AST", "HEEG": "HEEG", "HNPM": "HNPM", "CHAST": "CHAST", "MDT": "MDT", "MYT": "MYT", "HNPMX": "HNPMX", "ADT": "ADT", "EAT": "EAT", "HNT": "HNT", "ECT": "ECT", "OESZ": "OESZ", "AWST": "AWST", "WITA": "WITA", "JDT": "JDT", "ART": "ART", "ARST": "ARST", "ACST": "ACST", "ACDT": "ACDT", "HEPMX": "HEPMX", "ACWDT": "ACWDT", "HENOMX": "HENOMX", "HEOG": "HEOG", "WAT": "WAT", "EST": "EST", "AKST": "AKST", "∅∅∅": "∅∅∅", "WAST": "WAST", "PDT": "PDT", "ChST": "ChST", "OEZ": "OEZ", "HNOG": "HNOG", "WEZ": "WEZ", "GMT": "GMT", "ACWST": "ACWST", "WIT": "WIT", "VET": "VET", "HNEG": "HNEG", "SGT": "SGT", "HECU": "HECU", "NZDT": "NZDT", "HADT": "HADT", "JST": "JST", "HKT": "HKT", "HNCU": "HNCU", "HNNOMX": "HNNOMX", "GFT": "GFT", "HAT": "HAT", "CAT": "CAT", "AWDT": "AWDT", "BOT": "BOT", "SRT": "SRT", "MESZ": "MESZ", "HAST": "HAST", "AEDT": "AEDT", "SAST": "SAST", "EDT": "EDT", "WIB": "WIB", "WESZ": "WESZ", "CHADT": "CHADT", "HEPM": "HEPM", "UYST": "UYST", "LHST": "LHST", "WARST": "WARST", "PST": "PST", "TMT": "TMT", "TMST": "TMST", "LHDT": "LHDT", "WART": "WART", "IST": "IST", "COT": "COT", "AKDT": "AKDT", "CDT": "CDT", "MST": "MST", "AEST": "AEST", "HKST": "HKST", "CLST": "CLST", "GYT": "GYT", "CST": "CST"},
68 // Locale returns the current translators string locale
69 func (bem *bem) Locale() string {
73 // PluralsCardinal returns the list of cardinal plural rules associated with 'bem'
74 func (bem *bem) PluralsCardinal() []locales.PluralRule {
75 return bem.pluralsCardinal
78 // PluralsOrdinal returns the list of ordinal plural rules associated with 'bem'
79 func (bem *bem) PluralsOrdinal() []locales.PluralRule {
80 return bem.pluralsOrdinal
83 // PluralsRange returns the list of range plural rules associated with 'bem'
84 func (bem *bem) PluralsRange() []locales.PluralRule {
85 return bem.pluralsRange
88 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'bem'
89 func (bem *bem) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
94 return locales.PluralRuleOne
97 return locales.PluralRuleOther
100 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'bem'
101 func (bem *bem) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
102 return locales.PluralRuleUnknown
105 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'bem'
106 func (bem *bem) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
107 return locales.PluralRuleUnknown
110 // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
111 func (bem *bem) MonthAbbreviated(month time.Month) string {
112 return bem.monthsAbbreviated[month]
115 // MonthsAbbreviated returns the locales abbreviated months
116 func (bem *bem) MonthsAbbreviated() []string {
117 return bem.monthsAbbreviated[1:]
120 // MonthNarrow returns the locales narrow month given the 'month' provided
121 func (bem *bem) MonthNarrow(month time.Month) string {
122 return bem.monthsNarrow[month]
125 // MonthsNarrow returns the locales narrow months
126 func (bem *bem) MonthsNarrow() []string {
127 return bem.monthsNarrow[1:]
130 // MonthWide returns the locales wide month given the 'month' provided
131 func (bem *bem) MonthWide(month time.Month) string {
132 return bem.monthsWide[month]
135 // MonthsWide returns the locales wide months
136 func (bem *bem) MonthsWide() []string {
137 return bem.monthsWide[1:]
140 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
141 func (bem *bem) WeekdayAbbreviated(weekday time.Weekday) string {
142 return bem.daysAbbreviated[weekday]
145 // WeekdaysAbbreviated returns the locales abbreviated weekdays
146 func (bem *bem) WeekdaysAbbreviated() []string {
147 return bem.daysAbbreviated
150 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
151 func (bem *bem) WeekdayNarrow(weekday time.Weekday) string {
152 return bem.daysNarrow[weekday]
155 // WeekdaysNarrow returns the locales narrow weekdays
156 func (bem *bem) WeekdaysNarrow() []string {
157 return bem.daysNarrow
160 // WeekdayShort returns the locales short weekday given the 'weekday' provided
161 func (bem *bem) WeekdayShort(weekday time.Weekday) string {
162 return bem.daysShort[weekday]
165 // WeekdaysShort returns the locales short weekdays
166 func (bem *bem) WeekdaysShort() []string {
170 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
171 func (bem *bem) WeekdayWide(weekday time.Weekday) string {
172 return bem.daysWide[weekday]
175 // WeekdaysWide returns the locales wide weekdays
176 func (bem *bem) WeekdaysWide() []string {
180 // Decimal returns the decimal point of number
181 func (bem *bem) Decimal() string {
185 // Group returns the group of number
186 func (bem *bem) Group() string {
190 // Group returns the minus sign of number
191 func (bem *bem) Minus() string {
195 // FmtNumber returns 'num' with digits/precision of 'v' for 'bem' and handles both Whole and Real numbers based on 'v'
196 func (bem *bem) FmtNumber(num float64, v uint64) string {
198 return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
201 // FmtPercent returns 'num' with digits/precision of 'v' for 'bem' and handles both Whole and Real numbers based on 'v'
202 // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
203 func (bem *bem) FmtPercent(num float64, v uint64) string {
204 return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
207 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'bem'
208 func (bem *bem) FmtCurrency(num float64, v uint64, currency currency.Type) string {
210 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
211 symbol := bem.currencies[currency]
212 l := len(s) + len(symbol) + 0
215 b := make([]byte, 0, l)
217 for i := len(s) - 1; i >= 0; i-- {
220 b = append(b, bem.decimal[0])
227 b = append(b, bem.group[0])
237 for j := len(symbol) - 1; j >= 0; j-- {
238 b = append(b, symbol[j])
242 b = append(b, bem.minus[0])
246 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
247 b[i], b[j] = b[j], b[i]
253 b = append(b, bem.decimal...)
256 for i := 0; i < 2-int(v); i++ {
264 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'bem'
265 // in accounting notation.
266 func (bem *bem) FmtAccounting(num float64, v uint64, currency currency.Type) string {
268 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
269 symbol := bem.currencies[currency]
270 l := len(s) + len(symbol) + 2
273 b := make([]byte, 0, l)
275 for i := len(s) - 1; i >= 0; i-- {
278 b = append(b, bem.decimal[0])
285 b = append(b, bem.group[0])
297 for j := len(symbol) - 1; j >= 0; j-- {
298 b = append(b, symbol[j])
301 b = append(b, bem.currencyNegativePrefix[0])
305 for j := len(symbol) - 1; j >= 0; j-- {
306 b = append(b, symbol[j])
312 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
313 b[i], b[j] = b[j], b[i]
319 b = append(b, bem.decimal...)
322 for i := 0; i < 2-int(v); i++ {
328 b = append(b, bem.currencyNegativeSuffix...)
334 // FmtDateShort returns the short date representation of 't' for 'bem'
335 func (bem *bem) FmtDateShort(t time.Time) string {
337 b := make([]byte, 0, 32)
343 b = strconv.AppendInt(b, int64(t.Day()), 10)
344 b = append(b, []byte{0x2f}...)
350 b = strconv.AppendInt(b, int64(t.Month()), 10)
352 b = append(b, []byte{0x2f}...)
355 b = strconv.AppendInt(b, int64(t.Year()), 10)
357 b = strconv.AppendInt(b, int64(-t.Year()), 10)
363 // FmtDateMedium returns the medium date representation of 't' for 'bem'
364 func (bem *bem) FmtDateMedium(t time.Time) string {
366 b := make([]byte, 0, 32)
368 b = strconv.AppendInt(b, int64(t.Day()), 10)
369 b = append(b, []byte{0x20}...)
370 b = append(b, bem.monthsAbbreviated[t.Month()]...)
371 b = append(b, []byte{0x20}...)
374 b = strconv.AppendInt(b, int64(t.Year()), 10)
376 b = strconv.AppendInt(b, int64(-t.Year()), 10)
382 // FmtDateLong returns the long date representation of 't' for 'bem'
383 func (bem *bem) FmtDateLong(t time.Time) string {
385 b := make([]byte, 0, 32)
387 b = strconv.AppendInt(b, int64(t.Day()), 10)
388 b = append(b, []byte{0x20}...)
389 b = append(b, bem.monthsWide[t.Month()]...)
390 b = append(b, []byte{0x20}...)
393 b = strconv.AppendInt(b, int64(t.Year()), 10)
395 b = strconv.AppendInt(b, int64(-t.Year()), 10)
401 // FmtDateFull returns the full date representation of 't' for 'bem'
402 func (bem *bem) FmtDateFull(t time.Time) string {
404 b := make([]byte, 0, 32)
406 b = append(b, bem.daysWide[t.Weekday()]...)
407 b = append(b, []byte{0x2c, 0x20}...)
408 b = strconv.AppendInt(b, int64(t.Day()), 10)
409 b = append(b, []byte{0x20}...)
410 b = append(b, bem.monthsWide[t.Month()]...)
411 b = append(b, []byte{0x20}...)
414 b = strconv.AppendInt(b, int64(t.Year()), 10)
416 b = strconv.AppendInt(b, int64(-t.Year()), 10)
422 // FmtTimeShort returns the short time representation of 't' for 'bem'
423 func (bem *bem) FmtTimeShort(t time.Time) string {
425 b := make([]byte, 0, 32)
433 b = strconv.AppendInt(b, int64(h), 10)
434 b = append(b, bem.timeSeparator...)
440 b = strconv.AppendInt(b, int64(t.Minute()), 10)
441 b = append(b, []byte{0x20}...)
444 b = append(b, bem.periodsAbbreviated[0]...)
446 b = append(b, bem.periodsAbbreviated[1]...)
452 // FmtTimeMedium returns the medium time representation of 't' for 'bem'
453 func (bem *bem) FmtTimeMedium(t time.Time) string {
455 b := make([]byte, 0, 32)
463 b = strconv.AppendInt(b, int64(h), 10)
464 b = append(b, bem.timeSeparator...)
470 b = strconv.AppendInt(b, int64(t.Minute()), 10)
471 b = append(b, bem.timeSeparator...)
477 b = strconv.AppendInt(b, int64(t.Second()), 10)
478 b = append(b, []byte{0x20}...)
481 b = append(b, bem.periodsAbbreviated[0]...)
483 b = append(b, bem.periodsAbbreviated[1]...)
489 // FmtTimeLong returns the long time representation of 't' for 'bem'
490 func (bem *bem) FmtTimeLong(t time.Time) string {
492 b := make([]byte, 0, 32)
500 b = strconv.AppendInt(b, int64(h), 10)
501 b = append(b, bem.timeSeparator...)
507 b = strconv.AppendInt(b, int64(t.Minute()), 10)
508 b = append(b, bem.timeSeparator...)
514 b = strconv.AppendInt(b, int64(t.Second()), 10)
515 b = append(b, []byte{0x20}...)
518 b = append(b, bem.periodsAbbreviated[0]...)
520 b = append(b, bem.periodsAbbreviated[1]...)
523 b = append(b, []byte{0x20}...)
531 // FmtTimeFull returns the full time representation of 't' for 'bem'
532 func (bem *bem) FmtTimeFull(t time.Time) string {
534 b := make([]byte, 0, 32)
542 b = strconv.AppendInt(b, int64(h), 10)
543 b = append(b, bem.timeSeparator...)
549 b = strconv.AppendInt(b, int64(t.Minute()), 10)
550 b = append(b, bem.timeSeparator...)
556 b = strconv.AppendInt(b, int64(t.Second()), 10)
557 b = append(b, []byte{0x20}...)
560 b = append(b, bem.periodsAbbreviated[0]...)
562 b = append(b, bem.periodsAbbreviated[1]...)
565 b = append(b, []byte{0x20}...)
569 if btz, ok := bem.timezones[tz]; ok {
570 b = append(b, btz...)