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 'teo' 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", "USh", "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"},
53 currencyNegativePrefix: "(",
54 currencyNegativeSuffix: ")",
55 monthsAbbreviated: []string{"", "Rar", "Muk", "Kwa", "Dun", "Mar", "Mod", "Jol", "Ped", "Sok", "Tib", "Lab", "Poo"},
56 monthsNarrow: []string{"", "R", "M", "K", "D", "M", "M", "J", "P", "S", "T", "L", "P"},
57 monthsWide: []string{"", "Orara", "Omuk", "Okwamg’", "Odung’el", "Omaruk", "Omodok’king’ol", "Ojola", "Opedel", "Osokosokoma", "Otibar", "Olabor", "Opoo"},
58 daysAbbreviated: []string{"Jum", "Bar", "Aar", "Uni", "Ung", "Kan", "Sab"},
59 daysNarrow: []string{"J", "B", "A", "U", "U", "K", "S"},
60 daysWide: []string{"Nakaejuma", "Nakaebarasa", "Nakaare", "Nakauni", "Nakaung’on", "Nakakany", "Nakasabiti"},
61 periodsAbbreviated: []string{"Taparachu", "Ebongi"},
62 periodsWide: []string{"Taparachu", "Ebongi"},
63 erasAbbreviated: []string{"KK", "BK"},
64 erasNarrow: []string{"", ""},
65 erasWide: []string{"Kabla ya Christo", "Baada ya Christo"},
66 timezones: map[string]string{"HECU": "HECU", "AWST": "AWST", "TMST": "TMST", "AST": "AST", "AKST": "AKST", "ChST": "ChST", "PST": "PST", "CHAST": "CHAST", "HKST": "HKST", "COT": "COT", "AEDT": "AEDT", "SAST": "SAST", "CLT": "CLT", "SRT": "SRT", "UYT": "UYT", "WIT": "WIT", "JDT": "JDT", "WAST": "WAST", "WIB": "WIB", "CDT": "CDT", "HNNOMX": "HNNOMX", "HENOMX": "HENOMX", "EST": "EST", "MYT": "MYT", "LHDT": "LHDT", "CLST": "CLST", "WITA": "WITA", "JST": "JST", "WAT": "WAT", "HKT": "HKT", "UYST": "UYST", "HAST": "HAST", "HADT": "HADT", "NZDT": "NZDT", "HNPM": "HNPM", "MDT": "MDT", "AEST": "AEST", "EDT": "EDT", "WEZ": "WEZ", "HNEG": "HNEG", "GYT": "GYT", "ACDT": "ACDT", "HEPM": "HEPM", "MEZ": "MEZ", "HEOG": "HEOG", "HEEG": "HEEG", "HAT": "HAT", "MST": "MST", "ACWST": "ACWST", "OEZ": "OEZ", "TMT": "TMT", "VET": "VET", "ADT": "ADT", "GFT": "GFT", "WART": "WART", "ARST": "ARST", "ECT": "ECT", "GMT": "GMT", "HEPMX": "HEPMX", "PDT": "PDT", "BT": "BT", "BOT": "BOT", "CST": "CST", "ACWDT": "ACWDT", "ACST": "ACST", "∅∅∅": "∅∅∅", "WESZ": "WESZ", "HNCU": "HNCU", "NZST": "NZST", "OESZ": "OESZ", "EAT": "EAT", "COST": "COST", "WARST": "WARST", "ART": "ART", "AKDT": "AKDT", "AWDT": "AWDT", "MESZ": "MESZ", "LHST": "LHST", "HNPMX": "HNPMX", "HNOG": "HNOG", "HNT": "HNT", "CAT": "CAT", "SGT": "SGT", "CHADT": "CHADT", "IST": "IST"},
70 // Locale returns the current translators string locale
71 func (teo *teo) Locale() string {
75 // PluralsCardinal returns the list of cardinal plural rules associated with 'teo'
76 func (teo *teo) PluralsCardinal() []locales.PluralRule {
77 return teo.pluralsCardinal
80 // PluralsOrdinal returns the list of ordinal plural rules associated with 'teo'
81 func (teo *teo) PluralsOrdinal() []locales.PluralRule {
82 return teo.pluralsOrdinal
85 // PluralsRange returns the list of range plural rules associated with 'teo'
86 func (teo *teo) PluralsRange() []locales.PluralRule {
87 return teo.pluralsRange
90 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'teo'
91 func (teo *teo) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
96 return locales.PluralRuleOne
99 return locales.PluralRuleOther
102 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'teo'
103 func (teo *teo) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
104 return locales.PluralRuleUnknown
107 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'teo'
108 func (teo *teo) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
109 return locales.PluralRuleUnknown
112 // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
113 func (teo *teo) MonthAbbreviated(month time.Month) string {
114 return teo.monthsAbbreviated[month]
117 // MonthsAbbreviated returns the locales abbreviated months
118 func (teo *teo) MonthsAbbreviated() []string {
119 return teo.monthsAbbreviated[1:]
122 // MonthNarrow returns the locales narrow month given the 'month' provided
123 func (teo *teo) MonthNarrow(month time.Month) string {
124 return teo.monthsNarrow[month]
127 // MonthsNarrow returns the locales narrow months
128 func (teo *teo) MonthsNarrow() []string {
129 return teo.monthsNarrow[1:]
132 // MonthWide returns the locales wide month given the 'month' provided
133 func (teo *teo) MonthWide(month time.Month) string {
134 return teo.monthsWide[month]
137 // MonthsWide returns the locales wide months
138 func (teo *teo) MonthsWide() []string {
139 return teo.monthsWide[1:]
142 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
143 func (teo *teo) WeekdayAbbreviated(weekday time.Weekday) string {
144 return teo.daysAbbreviated[weekday]
147 // WeekdaysAbbreviated returns the locales abbreviated weekdays
148 func (teo *teo) WeekdaysAbbreviated() []string {
149 return teo.daysAbbreviated
152 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
153 func (teo *teo) WeekdayNarrow(weekday time.Weekday) string {
154 return teo.daysNarrow[weekday]
157 // WeekdaysNarrow returns the locales narrow weekdays
158 func (teo *teo) WeekdaysNarrow() []string {
159 return teo.daysNarrow
162 // WeekdayShort returns the locales short weekday given the 'weekday' provided
163 func (teo *teo) WeekdayShort(weekday time.Weekday) string {
164 return teo.daysShort[weekday]
167 // WeekdaysShort returns the locales short weekdays
168 func (teo *teo) WeekdaysShort() []string {
172 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
173 func (teo *teo) WeekdayWide(weekday time.Weekday) string {
174 return teo.daysWide[weekday]
177 // WeekdaysWide returns the locales wide weekdays
178 func (teo *teo) WeekdaysWide() []string {
182 // Decimal returns the decimal point of number
183 func (teo *teo) Decimal() string {
187 // Group returns the group of number
188 func (teo *teo) Group() string {
192 // Group returns the minus sign of number
193 func (teo *teo) Minus() string {
197 // FmtNumber returns 'num' with digits/precision of 'v' for 'teo' and handles both Whole and Real numbers based on 'v'
198 func (teo *teo) FmtNumber(num float64, v uint64) string {
200 return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
203 // FmtPercent returns 'num' with digits/precision of 'v' for 'teo' and handles both Whole and Real numbers based on 'v'
204 // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
205 func (teo *teo) FmtPercent(num float64, v uint64) string {
206 return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
209 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'teo'
210 func (teo *teo) FmtCurrency(num float64, v uint64, currency currency.Type) string {
212 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
213 symbol := teo.currencies[currency]
214 l := len(s) + len(symbol) + 0
217 b := make([]byte, 0, l)
219 for i := len(s) - 1; i >= 0; i-- {
222 b = append(b, teo.decimal[0])
229 b = append(b, teo.group[0])
239 for j := len(symbol) - 1; j >= 0; j-- {
240 b = append(b, symbol[j])
244 b = append(b, teo.minus[0])
248 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
249 b[i], b[j] = b[j], b[i]
255 b = append(b, teo.decimal...)
258 for i := 0; i < 2-int(v); i++ {
266 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'teo'
267 // in accounting notation.
268 func (teo *teo) FmtAccounting(num float64, v uint64, currency currency.Type) string {
270 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
271 symbol := teo.currencies[currency]
272 l := len(s) + len(symbol) + 2
275 b := make([]byte, 0, l)
277 for i := len(s) - 1; i >= 0; i-- {
280 b = append(b, teo.decimal[0])
287 b = append(b, teo.group[0])
299 for j := len(symbol) - 1; j >= 0; j-- {
300 b = append(b, symbol[j])
303 b = append(b, teo.currencyNegativePrefix[0])
307 for j := len(symbol) - 1; j >= 0; j-- {
308 b = append(b, symbol[j])
314 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
315 b[i], b[j] = b[j], b[i]
321 b = append(b, teo.decimal...)
324 for i := 0; i < 2-int(v); i++ {
330 b = append(b, teo.currencyNegativeSuffix...)
336 // FmtDateShort returns the short date representation of 't' for 'teo'
337 func (teo *teo) FmtDateShort(t time.Time) string {
339 b := make([]byte, 0, 32)
345 b = strconv.AppendInt(b, int64(t.Day()), 10)
346 b = append(b, []byte{0x2f}...)
352 b = strconv.AppendInt(b, int64(t.Month()), 10)
354 b = append(b, []byte{0x2f}...)
357 b = strconv.AppendInt(b, int64(t.Year()), 10)
359 b = strconv.AppendInt(b, int64(-t.Year()), 10)
365 // FmtDateMedium returns the medium date representation of 't' for 'teo'
366 func (teo *teo) FmtDateMedium(t time.Time) string {
368 b := make([]byte, 0, 32)
370 b = strconv.AppendInt(b, int64(t.Day()), 10)
371 b = append(b, []byte{0x20}...)
372 b = append(b, teo.monthsAbbreviated[t.Month()]...)
373 b = append(b, []byte{0x20}...)
376 b = strconv.AppendInt(b, int64(t.Year()), 10)
378 b = strconv.AppendInt(b, int64(-t.Year()), 10)
384 // FmtDateLong returns the long date representation of 't' for 'teo'
385 func (teo *teo) FmtDateLong(t time.Time) string {
387 b := make([]byte, 0, 32)
389 b = strconv.AppendInt(b, int64(t.Day()), 10)
390 b = append(b, []byte{0x20}...)
391 b = append(b, teo.monthsWide[t.Month()]...)
392 b = append(b, []byte{0x20}...)
395 b = strconv.AppendInt(b, int64(t.Year()), 10)
397 b = strconv.AppendInt(b, int64(-t.Year()), 10)
403 // FmtDateFull returns the full date representation of 't' for 'teo'
404 func (teo *teo) FmtDateFull(t time.Time) string {
406 b := make([]byte, 0, 32)
408 b = append(b, teo.daysWide[t.Weekday()]...)
409 b = append(b, []byte{0x2c, 0x20}...)
410 b = strconv.AppendInt(b, int64(t.Day()), 10)
411 b = append(b, []byte{0x20}...)
412 b = append(b, teo.monthsWide[t.Month()]...)
413 b = append(b, []byte{0x20}...)
416 b = strconv.AppendInt(b, int64(t.Year()), 10)
418 b = strconv.AppendInt(b, int64(-t.Year()), 10)
424 // FmtTimeShort returns the short time representation of 't' for 'teo'
425 func (teo *teo) FmtTimeShort(t time.Time) string {
427 b := make([]byte, 0, 32)
433 b = strconv.AppendInt(b, int64(t.Hour()), 10)
434 b = append(b, teo.timeSeparator...)
440 b = strconv.AppendInt(b, int64(t.Minute()), 10)
445 // FmtTimeMedium returns the medium time representation of 't' for 'teo'
446 func (teo *teo) FmtTimeMedium(t time.Time) string {
448 b := make([]byte, 0, 32)
454 b = strconv.AppendInt(b, int64(t.Hour()), 10)
455 b = append(b, teo.timeSeparator...)
461 b = strconv.AppendInt(b, int64(t.Minute()), 10)
462 b = append(b, teo.timeSeparator...)
468 b = strconv.AppendInt(b, int64(t.Second()), 10)
473 // FmtTimeLong returns the long time representation of 't' for 'teo'
474 func (teo *teo) FmtTimeLong(t time.Time) string {
476 b := make([]byte, 0, 32)
482 b = strconv.AppendInt(b, int64(t.Hour()), 10)
483 b = append(b, teo.timeSeparator...)
489 b = strconv.AppendInt(b, int64(t.Minute()), 10)
490 b = append(b, teo.timeSeparator...)
496 b = strconv.AppendInt(b, int64(t.Second()), 10)
497 b = append(b, []byte{0x20}...)
505 // FmtTimeFull returns the full time representation of 't' for 'teo'
506 func (teo *teo) FmtTimeFull(t time.Time) string {
508 b := make([]byte, 0, 32)
514 b = strconv.AppendInt(b, int64(t.Hour()), 10)
515 b = append(b, teo.timeSeparator...)
521 b = strconv.AppendInt(b, int64(t.Minute()), 10)
522 b = append(b, teo.timeSeparator...)
528 b = strconv.AppendInt(b, int64(t.Second()), 10)
529 b = append(b, []byte{0x20}...)
533 if btz, ok := teo.timezones[tz]; ok {
534 b = append(b, btz...)