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 monthsAbbreviated []string
28 daysAbbreviated []string
32 periodsAbbreviated []string
33 periodsNarrow []string
36 erasAbbreviated []string
39 timezones map[string]string
42 // New returns a new instance of translator for the 'kw' locale
43 func New() locales.Translator {
46 pluralsCardinal: []locales.PluralRule{2, 3, 6},
50 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", "ZMW", "ZRN", "ZRZ", "ZWD", "ZWL", "ZWR"},
51 monthsAbbreviated: []string{"", "Gen", "Hwe", "Meu", "Ebr", "Me", "Met", "Gor", "Est", "Gwn", "Hed", "Du", "Kev"},
52 monthsWide: []string{"", "mis Genver", "mis Hwevrer", "mis Meurth", "mis Ebrel", "mis Me", "mis Metheven", "mis Gortheren", "mis Est", "mis Gwynngala", "mis Hedra", "mis Du", "mis Kevardhu"},
53 daysAbbreviated: []string{"Sul", "Lun", "Mth", "Mhr", "Yow", "Gwe", "Sad"},
54 daysWide: []string{"dy Sul", "dy Lun", "dy Meurth", "dy Merher", "dy Yow", "dy Gwener", "dy Sadorn"},
55 periodsAbbreviated: []string{"a.m.", "p.m."},
56 periodsWide: []string{"a.m.", "p.m."},
57 erasAbbreviated: []string{"RC", "AD"},
58 erasNarrow: []string{"", ""},
59 erasWide: []string{"", ""},
60 timezones: map[string]string{"JDT": "JDT", "HENOMX": "HENOMX", "AWDT": "AWDT", "TMST": "TMST", "HEPM": "HEPM", "BT": "BT", "UYT": "UYT", "OEZ": "OEZ", "GMT": "GMT", "HNCU": "HNCU", "CAT": "CAT", "WEZ": "WEZ", "MDT": "MDT", "AWST": "AWST", "MYT": "MYT", "MEZ": "MEZ", "HEEG": "HEEG", "AKST": "AKST", "NZST": "NZST", "WARST": "WARST", "WIB": "WIB", "MESZ": "MESZ", "HNNOMX": "HNNOMX", "IST": "IST", "ARST": "ARST", "COST": "COST", "EDT": "EDT", "PDT": "PDT", "CHAST": "CHAST", "JST": "JST", "HAT": "HAT", "HKT": "HKT", "HEPMX": "HEPMX", "HNPM": "HNPM", "HAST": "HAST", "HNOG": "HNOG", "HEOG": "HEOG", "ACWDT": "ACWDT", "COT": "COT", "AKDT": "AKDT", "HKST": "HKST", "EST": "EST", "ECT": "ECT", "SRT": "SRT", "WIT": "WIT", "SAST": "SAST", "WAT": "WAT", "ACWST": "ACWST", "SGT": "SGT", "MST": "MST", "WAST": "WAST", "CLT": "CLT", "ADT": "ADT", "EAT": "EAT", "CST": "CST", "VET": "VET", "GYT": "GYT", "ChST": "ChST", "ACDT": "ACDT", "WESZ": "WESZ", "BOT": "BOT", "TMT": "TMT", "WITA": "WITA", "WART": "WART", "∅∅∅": "∅∅∅", "GFT": "GFT", "HNT": "HNT", "HECU": "HECU", "HADT": "HADT", "OESZ": "OESZ", "LHST": "LHST", "AEST": "AEST", "HNEG": "HNEG", "HNPMX": "HNPMX", "PST": "PST", "CDT": "CDT", "NZDT": "NZDT", "LHDT": "LHDT", "CLST": "CLST", "ACST": "ACST", "ART": "ART", "CHADT": "CHADT", "UYST": "UYST", "AST": "AST", "AEDT": "AEDT"},
64 // Locale returns the current translators string locale
65 func (kw *kw) Locale() string {
69 // PluralsCardinal returns the list of cardinal plural rules associated with 'kw'
70 func (kw *kw) PluralsCardinal() []locales.PluralRule {
71 return kw.pluralsCardinal
74 // PluralsOrdinal returns the list of ordinal plural rules associated with 'kw'
75 func (kw *kw) PluralsOrdinal() []locales.PluralRule {
76 return kw.pluralsOrdinal
79 // PluralsRange returns the list of range plural rules associated with 'kw'
80 func (kw *kw) PluralsRange() []locales.PluralRule {
81 return kw.pluralsRange
84 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'kw'
85 func (kw *kw) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
90 return locales.PluralRuleOne
92 return locales.PluralRuleTwo
95 return locales.PluralRuleOther
98 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'kw'
99 func (kw *kw) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
100 return locales.PluralRuleUnknown
103 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'kw'
104 func (kw *kw) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
105 return locales.PluralRuleUnknown
108 // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
109 func (kw *kw) MonthAbbreviated(month time.Month) string {
110 return kw.monthsAbbreviated[month]
113 // MonthsAbbreviated returns the locales abbreviated months
114 func (kw *kw) MonthsAbbreviated() []string {
115 return kw.monthsAbbreviated[1:]
118 // MonthNarrow returns the locales narrow month given the 'month' provided
119 func (kw *kw) MonthNarrow(month time.Month) string {
120 return kw.monthsNarrow[month]
123 // MonthsNarrow returns the locales narrow months
124 func (kw *kw) MonthsNarrow() []string {
128 // MonthWide returns the locales wide month given the 'month' provided
129 func (kw *kw) MonthWide(month time.Month) string {
130 return kw.monthsWide[month]
133 // MonthsWide returns the locales wide months
134 func (kw *kw) MonthsWide() []string {
135 return kw.monthsWide[1:]
138 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
139 func (kw *kw) WeekdayAbbreviated(weekday time.Weekday) string {
140 return kw.daysAbbreviated[weekday]
143 // WeekdaysAbbreviated returns the locales abbreviated weekdays
144 func (kw *kw) WeekdaysAbbreviated() []string {
145 return kw.daysAbbreviated
148 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
149 func (kw *kw) WeekdayNarrow(weekday time.Weekday) string {
150 return kw.daysNarrow[weekday]
153 // WeekdaysNarrow returns the locales narrow weekdays
154 func (kw *kw) WeekdaysNarrow() []string {
158 // WeekdayShort returns the locales short weekday given the 'weekday' provided
159 func (kw *kw) WeekdayShort(weekday time.Weekday) string {
160 return kw.daysShort[weekday]
163 // WeekdaysShort returns the locales short weekdays
164 func (kw *kw) WeekdaysShort() []string {
168 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
169 func (kw *kw) WeekdayWide(weekday time.Weekday) string {
170 return kw.daysWide[weekday]
173 // WeekdaysWide returns the locales wide weekdays
174 func (kw *kw) WeekdaysWide() []string {
178 // Decimal returns the decimal point of number
179 func (kw *kw) Decimal() string {
183 // Group returns the group of number
184 func (kw *kw) Group() string {
188 // Group returns the minus sign of number
189 func (kw *kw) Minus() string {
193 // FmtNumber returns 'num' with digits/precision of 'v' for 'kw' and handles both Whole and Real numbers based on 'v'
194 func (kw *kw) FmtNumber(num float64, v uint64) string {
196 return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
199 // FmtPercent returns 'num' with digits/precision of 'v' for 'kw' and handles both Whole and Real numbers based on 'v'
200 // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
201 func (kw *kw) FmtPercent(num float64, v uint64) string {
202 return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
205 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'kw'
206 func (kw *kw) FmtCurrency(num float64, v uint64, currency currency.Type) string {
208 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
209 symbol := kw.currencies[currency]
210 l := len(s) + len(symbol) + 0
213 b := make([]byte, 0, l)
215 for i := len(s) - 1; i >= 0; i-- {
218 b = append(b, kw.decimal[0])
225 b = append(b, kw.group[0])
235 for j := len(symbol) - 1; j >= 0; j-- {
236 b = append(b, symbol[j])
240 b = append(b, kw.minus[0])
244 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
245 b[i], b[j] = b[j], b[i]
251 b = append(b, kw.decimal...)
254 for i := 0; i < 2-int(v); i++ {
262 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'kw'
263 // in accounting notation.
264 func (kw *kw) FmtAccounting(num float64, v uint64, currency currency.Type) string {
266 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
267 symbol := kw.currencies[currency]
268 l := len(s) + len(symbol) + 0
271 b := make([]byte, 0, l)
273 for i := len(s) - 1; i >= 0; i-- {
276 b = append(b, kw.decimal[0])
283 b = append(b, kw.group[0])
295 for j := len(symbol) - 1; j >= 0; j-- {
296 b = append(b, symbol[j])
299 b = append(b, kw.minus[0])
303 for j := len(symbol) - 1; j >= 0; j-- {
304 b = append(b, symbol[j])
310 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
311 b[i], b[j] = b[j], b[i]
317 b = append(b, kw.decimal...)
320 for i := 0; i < 2-int(v); i++ {
328 // FmtDateShort returns the short date representation of 't' for 'kw'
329 func (kw *kw) FmtDateShort(t time.Time) string {
331 b := make([]byte, 0, 32)
337 b = strconv.AppendInt(b, int64(t.Day()), 10)
338 b = append(b, []byte{0x2f}...)
344 b = strconv.AppendInt(b, int64(t.Month()), 10)
346 b = append(b, []byte{0x2f}...)
349 b = strconv.AppendInt(b, int64(t.Year()), 10)
351 b = strconv.AppendInt(b, int64(-t.Year()), 10)
357 // FmtDateMedium returns the medium date representation of 't' for 'kw'
358 func (kw *kw) FmtDateMedium(t time.Time) string {
360 b := make([]byte, 0, 32)
362 b = strconv.AppendInt(b, int64(t.Day()), 10)
363 b = append(b, []byte{0x20}...)
364 b = append(b, kw.monthsAbbreviated[t.Month()]...)
365 b = append(b, []byte{0x20}...)
368 b = strconv.AppendInt(b, int64(t.Year()), 10)
370 b = strconv.AppendInt(b, int64(-t.Year()), 10)
376 // FmtDateLong returns the long date representation of 't' for 'kw'
377 func (kw *kw) FmtDateLong(t time.Time) string {
379 b := make([]byte, 0, 32)
381 b = strconv.AppendInt(b, int64(t.Day()), 10)
382 b = append(b, []byte{0x20}...)
383 b = append(b, kw.monthsWide[t.Month()]...)
384 b = append(b, []byte{0x20}...)
387 b = strconv.AppendInt(b, int64(t.Year()), 10)
389 b = strconv.AppendInt(b, int64(-t.Year()), 10)
395 // FmtDateFull returns the full date representation of 't' for 'kw'
396 func (kw *kw) FmtDateFull(t time.Time) string {
398 b := make([]byte, 0, 32)
400 b = append(b, kw.daysWide[t.Weekday()]...)
401 b = append(b, []byte{0x20}...)
402 b = strconv.AppendInt(b, int64(t.Day()), 10)
403 b = append(b, []byte{0x20}...)
404 b = append(b, kw.monthsWide[t.Month()]...)
405 b = append(b, []byte{0x20}...)
408 b = strconv.AppendInt(b, int64(t.Year()), 10)
410 b = strconv.AppendInt(b, int64(-t.Year()), 10)
416 // FmtTimeShort returns the short time representation of 't' for 'kw'
417 func (kw *kw) FmtTimeShort(t time.Time) string {
419 b := make([]byte, 0, 32)
425 b = strconv.AppendInt(b, int64(t.Hour()), 10)
426 b = append(b, kw.timeSeparator...)
432 b = strconv.AppendInt(b, int64(t.Minute()), 10)
437 // FmtTimeMedium returns the medium time representation of 't' for 'kw'
438 func (kw *kw) FmtTimeMedium(t time.Time) string {
440 b := make([]byte, 0, 32)
446 b = strconv.AppendInt(b, int64(t.Hour()), 10)
447 b = append(b, kw.timeSeparator...)
453 b = strconv.AppendInt(b, int64(t.Minute()), 10)
454 b = append(b, kw.timeSeparator...)
460 b = strconv.AppendInt(b, int64(t.Second()), 10)
465 // FmtTimeLong returns the long time representation of 't' for 'kw'
466 func (kw *kw) FmtTimeLong(t time.Time) string {
468 b := make([]byte, 0, 32)
474 b = strconv.AppendInt(b, int64(t.Hour()), 10)
475 b = append(b, kw.timeSeparator...)
481 b = strconv.AppendInt(b, int64(t.Minute()), 10)
482 b = append(b, kw.timeSeparator...)
488 b = strconv.AppendInt(b, int64(t.Second()), 10)
489 b = append(b, []byte{0x20}...)
497 // FmtTimeFull returns the full time representation of 't' for 'kw'
498 func (kw *kw) FmtTimeFull(t time.Time) string {
500 b := make([]byte, 0, 32)
506 b = strconv.AppendInt(b, int64(t.Hour()), 10)
507 b = append(b, kw.timeSeparator...)
513 b = strconv.AppendInt(b, int64(t.Minute()), 10)
514 b = append(b, kw.timeSeparator...)
520 b = strconv.AppendInt(b, int64(t.Second()), 10)
521 b = append(b, []byte{0x20}...)
525 if btz, ok := kw.timezones[tz]; ok {
526 b = append(b, btz...)