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 'ii' locale
45 func New() locales.Translator {
48 pluralsCardinal: []locales.PluralRule{6},
56 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"},
57 currencyPositivePrefix: " ",
58 currencyNegativePrefix: " ",
59 monthsAbbreviated: []string{"", "ꋍꆪ", "ꑍꆪ", "ꌕꆪ", "ꇖꆪ", "ꉬꆪ", "ꃘꆪ", "ꏃꆪ", "ꉆꆪ", "ꈬꆪ", "ꊰꆪ", "ꊰꊪꆪ", "ꊰꑋꆪ"},
60 monthsNarrow: []string{"", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"},
61 monthsWide: []string{"", "ꋍꆪ", "ꑍꆪ", "ꌕꆪ", "ꇖꆪ", "ꉬꆪ", "ꃘꆪ", "ꏃꆪ", "ꉆꆪ", "ꈬꆪ", "ꊰꆪ", "ꊰꊪꆪ", "ꊰꑋꆪ"},
62 daysAbbreviated: []string{"ꑭꆏ", "ꆏꋍ", "ꆏꑍ", "ꆏꌕ", "ꆏꇖ", "ꆏꉬ", "ꆏꃘ"},
63 daysNarrow: []string{"ꆏ", "ꋍ", "ꑍ", "ꌕ", "ꇖ", "ꉬ", "ꃘ"},
64 daysWide: []string{"ꑭꆏꑍ", "ꆏꊂꋍ", "ꆏꊂꑍ", "ꆏꊂꌕ", "ꆏꊂꇖ", "ꆏꊂꉬ", "ꆏꊂꃘ"},
65 periodsAbbreviated: []string{"ꎸꄑ", "ꁯꋒ"},
66 periodsWide: []string{"ꎸꄑ", "ꁯꋒ"},
67 erasAbbreviated: []string{"ꃅꋊꂿ", "ꃅꋊꊂ"},
68 erasNarrow: []string{"", ""},
69 erasWide: []string{"", ""},
70 timezones: map[string]string{"SRT": "SRT", "HEEG": "HEEG", "ADT": "ADT", "ART": "ART", "UYST": "UYST", "LHDT": "LHDT", "ACWST": "ACWST", "MEZ": "MEZ", "CLT": "CLT", "COST": "COST", "WESZ": "WESZ", "HEPM": "HEPM", "AWDT": "AWDT", "HNOG": "HNOG", "ACST": "ACST", "∅∅∅": "∅∅∅", "MDT": "MDT", "HAST": "HAST", "VET": "VET", "GFT": "GFT", "GMT": "GMT", "MST": "MST", "HEPMX": "HEPMX", "AWST": "AWST", "OEZ": "OEZ", "LHST": "LHST", "WART": "WART", "HNT": "HNT", "SGT": "SGT", "ChST": "ChST", "EST": "EST", "MYT": "MYT", "WIT": "WIT", "GYT": "GYT", "CHADT": "CHADT", "HNCU": "HNCU", "HNNOMX": "HNNOMX", "HNEG": "HNEG", "AKDT": "AKDT", "CST": "CST", "HEOG": "HEOG", "HKST": "HKST", "CDT": "CDT", "HENOMX": "HENOMX", "JST": "JST", "WAT": "WAT", "CAT": "CAT", "WITA": "WITA", "JDT": "JDT", "SAST": "SAST", "ECT": "ECT", "TMST": "TMST", "NZST": "NZST", "NZDT": "NZDT", "AST": "AST", "AEST": "AEST", "WIB": "WIB", "CHAST": "CHAST", "IST": "IST", "AEDT": "AEDT", "WAST": "WAST", "HAT": "HAT", "BOT": "BOT", "HADT": "HADT", "HNPMX": "HNPMX", "PDT": "PDT", "HECU": "HECU", "OESZ": "OESZ", "EAT": "EAT", "CLST": "CLST", "AKST": "AKST", "ACDT": "ACDT", "EDT": "EDT", "BT": "BT", "ACWDT": "ACWDT", "MESZ": "MESZ", "TMT": "TMT", "WARST": "WARST", "ARST": "ARST", "WEZ": "WEZ", "PST": "PST", "HKT": "HKT", "COT": "COT", "HNPM": "HNPM", "UYT": "UYT"},
74 // Locale returns the current translators string locale
75 func (ii *ii) Locale() string {
79 // PluralsCardinal returns the list of cardinal plural rules associated with 'ii'
80 func (ii *ii) PluralsCardinal() []locales.PluralRule {
81 return ii.pluralsCardinal
84 // PluralsOrdinal returns the list of ordinal plural rules associated with 'ii'
85 func (ii *ii) PluralsOrdinal() []locales.PluralRule {
86 return ii.pluralsOrdinal
89 // PluralsRange returns the list of range plural rules associated with 'ii'
90 func (ii *ii) PluralsRange() []locales.PluralRule {
91 return ii.pluralsRange
94 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'ii'
95 func (ii *ii) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
96 return locales.PluralRuleOther
99 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'ii'
100 func (ii *ii) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
101 return locales.PluralRuleUnknown
104 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'ii'
105 func (ii *ii) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
106 return locales.PluralRuleUnknown
109 // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
110 func (ii *ii) MonthAbbreviated(month time.Month) string {
111 return ii.monthsAbbreviated[month]
114 // MonthsAbbreviated returns the locales abbreviated months
115 func (ii *ii) MonthsAbbreviated() []string {
116 return ii.monthsAbbreviated[1:]
119 // MonthNarrow returns the locales narrow month given the 'month' provided
120 func (ii *ii) MonthNarrow(month time.Month) string {
121 return ii.monthsNarrow[month]
124 // MonthsNarrow returns the locales narrow months
125 func (ii *ii) MonthsNarrow() []string {
126 return ii.monthsNarrow[1:]
129 // MonthWide returns the locales wide month given the 'month' provided
130 func (ii *ii) MonthWide(month time.Month) string {
131 return ii.monthsWide[month]
134 // MonthsWide returns the locales wide months
135 func (ii *ii) MonthsWide() []string {
136 return ii.monthsWide[1:]
139 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
140 func (ii *ii) WeekdayAbbreviated(weekday time.Weekday) string {
141 return ii.daysAbbreviated[weekday]
144 // WeekdaysAbbreviated returns the locales abbreviated weekdays
145 func (ii *ii) WeekdaysAbbreviated() []string {
146 return ii.daysAbbreviated
149 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
150 func (ii *ii) WeekdayNarrow(weekday time.Weekday) string {
151 return ii.daysNarrow[weekday]
154 // WeekdaysNarrow returns the locales narrow weekdays
155 func (ii *ii) WeekdaysNarrow() []string {
159 // WeekdayShort returns the locales short weekday given the 'weekday' provided
160 func (ii *ii) WeekdayShort(weekday time.Weekday) string {
161 return ii.daysShort[weekday]
164 // WeekdaysShort returns the locales short weekdays
165 func (ii *ii) WeekdaysShort() []string {
169 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
170 func (ii *ii) WeekdayWide(weekday time.Weekday) string {
171 return ii.daysWide[weekday]
174 // WeekdaysWide returns the locales wide weekdays
175 func (ii *ii) WeekdaysWide() []string {
179 // Decimal returns the decimal point of number
180 func (ii *ii) Decimal() string {
184 // Group returns the group of number
185 func (ii *ii) Group() string {
189 // Group returns the minus sign of number
190 func (ii *ii) Minus() string {
194 // FmtNumber returns 'num' with digits/precision of 'v' for 'ii' and handles both Whole and Real numbers based on 'v'
195 func (ii *ii) FmtNumber(num float64, v uint64) string {
197 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
198 l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
201 b := make([]byte, 0, l)
203 for i := len(s) - 1; i >= 0; i-- {
206 b = append(b, ii.decimal[0])
213 b = append(b, ii.group[0])
224 b = append(b, ii.minus[0])
228 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
229 b[i], b[j] = b[j], b[i]
235 // FmtPercent returns 'num' with digits/precision of 'v' for 'ii' and handles both Whole and Real numbers based on 'v'
236 // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
237 func (ii *ii) FmtPercent(num float64, v uint64) string {
238 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
240 b := make([]byte, 0, l)
242 for i := len(s) - 1; i >= 0; i-- {
245 b = append(b, ii.decimal[0])
253 b = append(b, ii.minus[0])
257 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
258 b[i], b[j] = b[j], b[i]
261 b = append(b, ii.percent...)
266 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'ii'
267 func (ii *ii) FmtCurrency(num float64, v uint64, currency currency.Type) string {
269 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
270 symbol := ii.currencies[currency]
271 l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
274 b := make([]byte, 0, l)
276 for i := len(s) - 1; i >= 0; i-- {
279 b = append(b, ii.decimal[0])
286 b = append(b, ii.group[0])
296 for j := len(symbol) - 1; j >= 0; j-- {
297 b = append(b, symbol[j])
300 for j := len(ii.currencyPositivePrefix) - 1; j >= 0; j-- {
301 b = append(b, ii.currencyPositivePrefix[j])
305 b = append(b, ii.minus[0])
309 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
310 b[i], b[j] = b[j], b[i]
316 b = append(b, ii.decimal...)
319 for i := 0; i < 2-int(v); i++ {
327 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'ii'
328 // in accounting notation.
329 func (ii *ii) FmtAccounting(num float64, v uint64, currency currency.Type) string {
331 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
332 symbol := ii.currencies[currency]
333 l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
336 b := make([]byte, 0, l)
338 for i := len(s) - 1; i >= 0; i-- {
341 b = append(b, ii.decimal[0])
348 b = append(b, ii.group[0])
360 for j := len(symbol) - 1; j >= 0; j-- {
361 b = append(b, symbol[j])
364 for j := len(ii.currencyNegativePrefix) - 1; j >= 0; j-- {
365 b = append(b, ii.currencyNegativePrefix[j])
368 b = append(b, ii.minus[0])
372 for j := len(symbol) - 1; j >= 0; j-- {
373 b = append(b, symbol[j])
376 for j := len(ii.currencyPositivePrefix) - 1; j >= 0; j-- {
377 b = append(b, ii.currencyPositivePrefix[j])
383 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
384 b[i], b[j] = b[j], b[i]
390 b = append(b, ii.decimal...)
393 for i := 0; i < 2-int(v); i++ {
401 // FmtDateShort returns the short date representation of 't' for 'ii'
402 func (ii *ii) FmtDateShort(t time.Time) string {
404 b := make([]byte, 0, 32)
407 b = strconv.AppendInt(b, int64(t.Year()), 10)
409 b = strconv.AppendInt(b, int64(-t.Year()), 10)
412 b = append(b, []byte{0x2d}...)
418 b = strconv.AppendInt(b, int64(t.Month()), 10)
420 b = append(b, []byte{0x2d}...)
426 b = strconv.AppendInt(b, int64(t.Day()), 10)
431 // FmtDateMedium returns the medium date representation of 't' for 'ii'
432 func (ii *ii) FmtDateMedium(t time.Time) string {
434 b := make([]byte, 0, 32)
437 b = strconv.AppendInt(b, int64(t.Year()), 10)
439 b = strconv.AppendInt(b, int64(-t.Year()), 10)
442 b = append(b, []byte{0x20}...)
443 b = append(b, ii.monthsAbbreviated[t.Month()]...)
444 b = append(b, []byte{0x20}...)
445 b = strconv.AppendInt(b, int64(t.Day()), 10)
450 // FmtDateLong returns the long date representation of 't' for 'ii'
451 func (ii *ii) FmtDateLong(t time.Time) string {
453 b := make([]byte, 0, 32)
456 b = strconv.AppendInt(b, int64(t.Year()), 10)
458 b = strconv.AppendInt(b, int64(-t.Year()), 10)
461 b = append(b, []byte{0x20}...)
462 b = append(b, ii.monthsWide[t.Month()]...)
463 b = append(b, []byte{0x20}...)
464 b = strconv.AppendInt(b, int64(t.Day()), 10)
469 // FmtDateFull returns the full date representation of 't' for 'ii'
470 func (ii *ii) FmtDateFull(t time.Time) string {
472 b := make([]byte, 0, 32)
475 b = strconv.AppendInt(b, int64(t.Year()), 10)
477 b = strconv.AppendInt(b, int64(-t.Year()), 10)
480 b = append(b, []byte{0x20}...)
481 b = append(b, ii.monthsWide[t.Month()]...)
482 b = append(b, []byte{0x20}...)
483 b = strconv.AppendInt(b, int64(t.Day()), 10)
484 b = append(b, []byte{0x2c, 0x20}...)
485 b = append(b, ii.daysWide[t.Weekday()]...)
490 // FmtTimeShort returns the short time representation of 't' for 'ii'
491 func (ii *ii) FmtTimeShort(t time.Time) string {
493 b := make([]byte, 0, 32)
501 b = strconv.AppendInt(b, int64(h), 10)
502 b = append(b, ii.timeSeparator...)
508 b = strconv.AppendInt(b, int64(t.Minute()), 10)
509 b = append(b, []byte{0x20}...)
512 b = append(b, ii.periodsAbbreviated[0]...)
514 b = append(b, ii.periodsAbbreviated[1]...)
520 // FmtTimeMedium returns the medium time representation of 't' for 'ii'
521 func (ii *ii) FmtTimeMedium(t time.Time) string {
523 b := make([]byte, 0, 32)
531 b = strconv.AppendInt(b, int64(h), 10)
532 b = append(b, ii.timeSeparator...)
538 b = strconv.AppendInt(b, int64(t.Minute()), 10)
539 b = append(b, ii.timeSeparator...)
545 b = strconv.AppendInt(b, int64(t.Second()), 10)
546 b = append(b, []byte{0x20}...)
549 b = append(b, ii.periodsAbbreviated[0]...)
551 b = append(b, ii.periodsAbbreviated[1]...)
557 // FmtTimeLong returns the long time representation of 't' for 'ii'
558 func (ii *ii) FmtTimeLong(t time.Time) string {
560 b := make([]byte, 0, 32)
568 b = strconv.AppendInt(b, int64(h), 10)
569 b = append(b, ii.timeSeparator...)
575 b = strconv.AppendInt(b, int64(t.Minute()), 10)
576 b = append(b, ii.timeSeparator...)
582 b = strconv.AppendInt(b, int64(t.Second()), 10)
583 b = append(b, []byte{0x20}...)
586 b = append(b, ii.periodsAbbreviated[0]...)
588 b = append(b, ii.periodsAbbreviated[1]...)
591 b = append(b, []byte{0x20}...)
599 // FmtTimeFull returns the full time representation of 't' for 'ii'
600 func (ii *ii) FmtTimeFull(t time.Time) string {
602 b := make([]byte, 0, 32)
610 b = strconv.AppendInt(b, int64(h), 10)
611 b = append(b, ii.timeSeparator...)
617 b = strconv.AppendInt(b, int64(t.Minute()), 10)
618 b = append(b, ii.timeSeparator...)
624 b = strconv.AppendInt(b, int64(t.Second()), 10)
625 b = append(b, []byte{0x20}...)
628 b = append(b, ii.periodsAbbreviated[0]...)
630 b = append(b, ii.periodsAbbreviated[1]...)
633 b = append(b, []byte{0x20}...)
637 if btz, ok := ii.timezones[tz]; ok {
638 b = append(b, btz...)