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 'tk' locale
46 func New() locales.Translator {
49 pluralsCardinal: []locales.PluralRule{2, 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", "R$", "BRN", "BRR", "BRZ", "BSD", "BTN", "BUK", "BWP", "BYB", "BYN", "BYR", "BZD", "CA$", "CDF", "CHE", "CHF", "CHW", "CLE", "CLF", "CLP", "CNX", "CN¥", "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", "HK$", "HNL", "HRD", "HRK", "HTG", "HUF", "IDR", "IEP", "ILP", "ILR", "₪", "₹", "IQD", "IRR", "ISJ", "ISK", "ITL", "JMD", "JOD", "JP¥", "KES", "KGS", "KHR", "KMF", "KPW", "KRH", "KRO", "₩", "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", "NZ$", "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", "NT$", "TZS", "UAH", "UAK", "UGS", "UGX", "US$", "USN", "USS", "UYI", "UYP", "UYU", "UZS", "VEB", "VEF", "₫", "VNN", "VUV", "WST", "FCFA", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "EC$", "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{"", "ýan", "few", "mart", "apr", "maý", "iýun", "iýul", "awg", "sen", "okt", "noý", "dek"},
64 monthsNarrow: []string{"", "Ý", "F", "M", "A", "M", "I", "I", "A", "S", "O", "N", "D"},
65 monthsWide: []string{"", "ýanwar", "fewral", "mart", "aprel", "maý", "iýun", "iýul", "awgust", "sentýabr", "oktýabr", "noýabr", "dekabr"},
66 daysAbbreviated: []string{"ýb", "db", "sb", "çb", "pb", "an", "şb"},
67 daysNarrow: []string{"Ý", "D", "S", "Ç", "P", "A", "Ş"},
68 daysWide: []string{"ýekşenbe", "duşenbe", "sişenbe", "çarşenbe", "penşenbe", "anna", "şenbe"},
69 timezones: map[string]string{"CST": "Merkezi Amerika, standart wagt", "MYT": "Malaýziýa", "COT": "Kolumbiýa, standart wagt", "HKT": "Gonkong, standart wagt", "CLST": "Çili, tomusky wagt", "ACST": "Merkezi Awstraliýa, standart wagt", "ECT": "Ekwador", "BOT": "Boliwiýa", "UYST": "Urugwaý, tomusky wagt", "OEZ": "Gündogar Ýewropa, standart wagt", "IST": "Hindistan", "GFT": "Fransuz Gwiana", "EDT": "Günorta Amerika, tomusky wagt", "GMT": "Grinwiç boýunça orta wagt", "AWDT": "Günbatar Awstraliýa, tomusky wagt", "HNOG": "Günbatar Grenlandiýa, standart wagt", "MDT": "MDT", "HNNOMX": "D.g.-G.b. Meksika, standart wagt", "AST": "Atlantika, standart wagt", "ART": "Argentina, standart wagt", "HEEG": "Gündogar Grenlandiýa, tomusky wagt", "WAST": "Günbatar Afrika, tomusky wagt", "HNT": "Nýufaundlend, standart wagt", "BT": "Butan", "HAST": "Gawaý-Aleut, standart wagt", "JST": "Ýaponiýa, standart wagt", "HKST": "Gonkong, tomusky wagt", "EST": "Günorta Amerika, standart wagt", "HEPMX": "Meksikan Ýuwaş umman, tomusky wagt", "HNPM": "Sen Pýer we Mikelon, standart wagt", "HECU": "Kuba, tomusky wagt", "MEZ": "Merkezi Ýewropa, standart wagt", "OESZ": "Gündogar Ýewropa, tomusky wagt", "HNEG": "Gündogar Grenlandiýa, standart wagt", "AKDT": "Alýaska, tomusky wagt", "CAT": "Merkezi Afrika", "ChST": "Çamorro", "HNPMX": "Meksikan Ýuwaş umman, standart wagt", "JDT": "Ýaponiýa, tomusky wagt", "ADT": "Atlantika, tomusky wagt", "EAT": "Gündogar Afrika", "AKST": "Alýaska, standart wagt", "SGT": "Singapur, standart wagt", "MESZ": "Merkezi Ýewropa, tomusky wagt", "HADT": "Gawaý-Aleut, tomusky wagt", "PST": "Ýuwaş umman, standart wagt", "CHADT": "Çatem, tomusky wagt", "MST": "MST", "NZST": "Täze Zelandiýa, standart wagt", "WART": "Günbatar Argentina, standart wagt", "WITA": "Merkezi Indoneziýa", "CLT": "Çili, standart wagt", "VET": "Wenesuela", "SAST": "Günorta Afrika, standart wagt", "GYT": "Gaýana", "WEZ": "Günbatar Ýewropa, standart wagt", "WIB": "Günbatar Indoneziýa", "ACWDT": "Merkezi Awstraliýa, günbatar tarap, tomusky wagt", "LHST": "Lord-Hau, standart wagt", "ARST": "Argentina, tomusky wagt", "CHAST": "Çatem, standart wagt", "HNCU": "Kuba, standart wagt", "WARST": "Günbatar Argentina, tomusky wagt", "COST": "Kolumbiýa, tomusky wagt", "PDT": "Ýuwaş umman, tomusky wagt", "SRT": "Surinam", "AWST": "Günbatar Awstraliýa, standart wagt", "HENOMX": "D.g.-G.b. Meksika, tomusky wagt", "AEDT": "Gündogar Awstraliýa, tomusky wagt", "WAT": "Günbatar Afrika, standart wagt", "WESZ": "Günbatar Ýewropa, tomusky wagt", "CDT": "Merkezi Amerika, tomusky wagt", "TMT": "Türkmenistan, standart wagt", "TMST": "Türkmenistan, tomusky wagt", "HEOG": "Günbatar Grenlandiýa, tomusky wagt", "AEST": "Gündogar Awstraliýa, standart wagt", "ACDT": "Merkezi Awstraliýa, tomusky wagt", "UYT": "Urugwaý, standart wagt", "∅∅∅": "Azor adalary, tomusky wagt", "HAT": "Nýufaundlend, tomusky wagt", "HEPM": "Sen Pýer we Mikelon, tomusky wagt", "WIT": "Gündogar Indoneziýa", "LHDT": "Lord-Hau, tomusky wagt", "ACWST": "Merkezi Awstraliýa, günbatar tarap, standart wagt", "NZDT": "Täze Zelandiýa, tomusky wagt"},
73 // Locale returns the current translators string locale
74 func (tk *tk) Locale() string {
78 // PluralsCardinal returns the list of cardinal plural rules associated with 'tk'
79 func (tk *tk) PluralsCardinal() []locales.PluralRule {
80 return tk.pluralsCardinal
83 // PluralsOrdinal returns the list of ordinal plural rules associated with 'tk'
84 func (tk *tk) PluralsOrdinal() []locales.PluralRule {
85 return tk.pluralsOrdinal
88 // PluralsRange returns the list of range plural rules associated with 'tk'
89 func (tk *tk) PluralsRange() []locales.PluralRule {
90 return tk.pluralsRange
93 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'tk'
94 func (tk *tk) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
99 return locales.PluralRuleOne
102 return locales.PluralRuleOther
105 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'tk'
106 func (tk *tk) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
107 return locales.PluralRuleUnknown
110 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'tk'
111 func (tk *tk) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
112 return locales.PluralRuleUnknown
115 // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
116 func (tk *tk) MonthAbbreviated(month time.Month) string {
117 return tk.monthsAbbreviated[month]
120 // MonthsAbbreviated returns the locales abbreviated months
121 func (tk *tk) MonthsAbbreviated() []string {
122 return tk.monthsAbbreviated[1:]
125 // MonthNarrow returns the locales narrow month given the 'month' provided
126 func (tk *tk) MonthNarrow(month time.Month) string {
127 return tk.monthsNarrow[month]
130 // MonthsNarrow returns the locales narrow months
131 func (tk *tk) MonthsNarrow() []string {
132 return tk.monthsNarrow[1:]
135 // MonthWide returns the locales wide month given the 'month' provided
136 func (tk *tk) MonthWide(month time.Month) string {
137 return tk.monthsWide[month]
140 // MonthsWide returns the locales wide months
141 func (tk *tk) MonthsWide() []string {
142 return tk.monthsWide[1:]
145 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
146 func (tk *tk) WeekdayAbbreviated(weekday time.Weekday) string {
147 return tk.daysAbbreviated[weekday]
150 // WeekdaysAbbreviated returns the locales abbreviated weekdays
151 func (tk *tk) WeekdaysAbbreviated() []string {
152 return tk.daysAbbreviated
155 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
156 func (tk *tk) WeekdayNarrow(weekday time.Weekday) string {
157 return tk.daysNarrow[weekday]
160 // WeekdaysNarrow returns the locales narrow weekdays
161 func (tk *tk) WeekdaysNarrow() []string {
165 // WeekdayShort returns the locales short weekday given the 'weekday' provided
166 func (tk *tk) WeekdayShort(weekday time.Weekday) string {
167 return tk.daysShort[weekday]
170 // WeekdaysShort returns the locales short weekdays
171 func (tk *tk) WeekdaysShort() []string {
175 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
176 func (tk *tk) WeekdayWide(weekday time.Weekday) string {
177 return tk.daysWide[weekday]
180 // WeekdaysWide returns the locales wide weekdays
181 func (tk *tk) WeekdaysWide() []string {
185 // Decimal returns the decimal point of number
186 func (tk *tk) Decimal() string {
190 // Group returns the group of number
191 func (tk *tk) Group() string {
195 // Group returns the minus sign of number
196 func (tk *tk) Minus() string {
200 // FmtNumber returns 'num' with digits/precision of 'v' for 'tk' and handles both Whole and Real numbers based on 'v'
201 func (tk *tk) FmtNumber(num float64, v uint64) string {
203 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
204 l := len(s) + 2 + 2*len(s[:len(s)-int(v)-1])/3
207 b := make([]byte, 0, l)
209 for i := len(s) - 1; i >= 0; i-- {
212 b = append(b, tk.decimal[0])
219 for j := len(tk.group) - 1; j >= 0; j-- {
220 b = append(b, tk.group[j])
232 b = append(b, tk.minus[0])
236 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
237 b[i], b[j] = b[j], b[i]
243 // FmtPercent returns 'num' with digits/precision of 'v' for 'tk' and handles both Whole and Real numbers based on 'v'
244 // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
245 func (tk *tk) FmtPercent(num float64, v uint64) string {
246 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
248 b := make([]byte, 0, l)
250 for i := len(s) - 1; i >= 0; i-- {
253 b = append(b, tk.decimal[0])
261 b = append(b, tk.minus[0])
265 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
266 b[i], b[j] = b[j], b[i]
269 b = append(b, tk.percentSuffix...)
271 b = append(b, tk.percent...)
276 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'tk'
277 func (tk *tk) FmtCurrency(num float64, v uint64, currency currency.Type) string {
279 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
280 symbol := tk.currencies[currency]
281 l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
284 b := make([]byte, 0, l)
286 for i := len(s) - 1; i >= 0; i-- {
289 b = append(b, tk.decimal[0])
296 for j := len(tk.group) - 1; j >= 0; j-- {
297 b = append(b, tk.group[j])
309 b = append(b, tk.minus[0])
313 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
314 b[i], b[j] = b[j], b[i]
320 b = append(b, tk.decimal...)
323 for i := 0; i < 2-int(v); i++ {
328 b = append(b, tk.currencyPositiveSuffix...)
330 b = append(b, symbol...)
335 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'tk'
336 // in accounting notation.
337 func (tk *tk) FmtAccounting(num float64, v uint64, currency currency.Type) string {
339 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
340 symbol := tk.currencies[currency]
341 l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
344 b := make([]byte, 0, l)
346 for i := len(s) - 1; i >= 0; i-- {
349 b = append(b, tk.decimal[0])
356 for j := len(tk.group) - 1; j >= 0; j-- {
357 b = append(b, tk.group[j])
370 b = append(b, tk.minus[0])
375 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
376 b[i], b[j] = b[j], b[i]
382 b = append(b, tk.decimal...)
385 for i := 0; i < 2-int(v); i++ {
391 b = append(b, tk.currencyNegativeSuffix...)
392 b = append(b, symbol...)
395 b = append(b, tk.currencyPositiveSuffix...)
396 b = append(b, symbol...)
402 // FmtDateShort returns the short date representation of 't' for 'tk'
403 func (tk *tk) FmtDateShort(t time.Time) string {
405 b := make([]byte, 0, 32)
411 b = strconv.AppendInt(b, int64(t.Day()), 10)
412 b = append(b, []byte{0x2e}...)
418 b = strconv.AppendInt(b, int64(t.Month()), 10)
420 b = append(b, []byte{0x2e}...)
423 b = strconv.AppendInt(b, int64(t.Year()), 10)
425 b = strconv.AppendInt(b, int64(-t.Year()), 10)
431 // FmtDateMedium returns the medium date representation of 't' for 'tk'
432 func (tk *tk) FmtDateMedium(t time.Time) string {
434 b := make([]byte, 0, 32)
436 b = strconv.AppendInt(b, int64(t.Day()), 10)
437 b = append(b, []byte{0x20}...)
438 b = append(b, tk.monthsAbbreviated[t.Month()]...)
439 b = append(b, []byte{0x20}...)
442 b = strconv.AppendInt(b, int64(t.Year()), 10)
444 b = strconv.AppendInt(b, int64(-t.Year()), 10)
450 // FmtDateLong returns the long date representation of 't' for 'tk'
451 func (tk *tk) FmtDateLong(t time.Time) string {
453 b := make([]byte, 0, 32)
455 b = strconv.AppendInt(b, int64(t.Day()), 10)
456 b = append(b, []byte{0x20}...)
457 b = append(b, tk.monthsWide[t.Month()]...)
458 b = append(b, []byte{0x20}...)
461 b = strconv.AppendInt(b, int64(t.Year()), 10)
463 b = strconv.AppendInt(b, int64(-t.Year()), 10)
469 // FmtDateFull returns the full date representation of 't' for 'tk'
470 func (tk *tk) FmtDateFull(t time.Time) string {
472 b := make([]byte, 0, 32)
474 b = strconv.AppendInt(b, int64(t.Day()), 10)
475 b = append(b, []byte{0x20}...)
476 b = append(b, tk.monthsWide[t.Month()]...)
477 b = append(b, []byte{0x20}...)
480 b = strconv.AppendInt(b, int64(t.Year()), 10)
482 b = strconv.AppendInt(b, int64(-t.Year()), 10)
485 b = append(b, []byte{0x20}...)
486 b = append(b, tk.daysWide[t.Weekday()]...)
491 // FmtTimeShort returns the short time representation of 't' for 'tk'
492 func (tk *tk) FmtTimeShort(t time.Time) string {
494 b := make([]byte, 0, 32)
500 b = strconv.AppendInt(b, int64(t.Hour()), 10)
501 b = append(b, tk.timeSeparator...)
507 b = strconv.AppendInt(b, int64(t.Minute()), 10)
512 // FmtTimeMedium returns the medium time representation of 't' for 'tk'
513 func (tk *tk) FmtTimeMedium(t time.Time) string {
515 b := make([]byte, 0, 32)
521 b = strconv.AppendInt(b, int64(t.Hour()), 10)
522 b = append(b, tk.timeSeparator...)
528 b = strconv.AppendInt(b, int64(t.Minute()), 10)
529 b = append(b, tk.timeSeparator...)
535 b = strconv.AppendInt(b, int64(t.Second()), 10)
540 // FmtTimeLong returns the long time representation of 't' for 'tk'
541 func (tk *tk) FmtTimeLong(t time.Time) string {
543 b := make([]byte, 0, 32)
549 b = strconv.AppendInt(b, int64(t.Hour()), 10)
550 b = append(b, tk.timeSeparator...)
556 b = strconv.AppendInt(b, int64(t.Minute()), 10)
557 b = append(b, tk.timeSeparator...)
563 b = strconv.AppendInt(b, int64(t.Second()), 10)
564 b = append(b, []byte{0x20}...)
572 // FmtTimeFull returns the full time representation of 't' for 'tk'
573 func (tk *tk) FmtTimeFull(t time.Time) string {
575 b := make([]byte, 0, 32)
581 b = strconv.AppendInt(b, int64(t.Hour()), 10)
582 b = append(b, tk.timeSeparator...)
588 b = strconv.AppendInt(b, int64(t.Minute()), 10)
589 b = append(b, tk.timeSeparator...)
595 b = strconv.AppendInt(b, int64(t.Second()), 10)
596 b = append(b, []byte{0x20}...)
600 if btz, ok := tk.timezones[tz]; ok {
601 b = append(b, btz...)