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 'kab' locale
43 func New() locales.Translator {
46 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", "DA", "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"},
53 monthsAbbreviated: []string{"", "Yen", "Fur", "Meɣ", "Yeb", "May", "Yun", "Yul", "Ɣuc", "Cte", "Tub", "Nun", "Duǧ"},
54 monthsNarrow: []string{"", "Y", "F", "M", "Y", "M", "Y", "Y", "Ɣ", "C", "T", "N", "D"},
55 monthsWide: []string{"", "Yennayer", "Fuṛar", "Meɣres", "Yebrir", "Mayyu", "Yunyu", "Yulyu", "Ɣuct", "Ctembeṛ", "Tubeṛ", "Nunembeṛ", "Duǧembeṛ"},
56 daysAbbreviated: []string{"Yan", "San", "Kraḍ", "Kuẓ", "Sam", "Sḍis", "Say"},
57 daysNarrow: []string{"Y", "S", "K", "K", "S", "S", "S"},
58 daysWide: []string{"Yanass", "Sanass", "Kraḍass", "Kuẓass", "Samass", "Sḍisass", "Sayass"},
59 periodsAbbreviated: []string{"n tufat", "n tmeddit"},
60 periodsWide: []string{"n tufat", "n tmeddit"},
61 erasAbbreviated: []string{"snd. T.Ɛ", "sld. T.Ɛ"},
62 erasNarrow: []string{"", ""},
63 erasWide: []string{"send talalit n Ɛisa", "seld talalit n Ɛisa"},
64 timezones: map[string]string{"WARST": "WARST", "ADT": "ADT", "CHAST": "CHAST", "SRT": "SRT", "WART": "WART", "HNT": "HNT", "BOT": "BOT", "MDT": "MDT", "HNEG": "HNEG", "ART": "ART", "HAT": "HAT", "WEZ": "WEZ", "HNCU": "HNCU", "CDT": "CDT", "AEST": "AEST", "PST": "PST", "COST": "COST", "TMT": "TMT", "OESZ": "OESZ", "EAT": "EAT", "AKST": "AKST", "ChST": "ChST", "HNPMX": "HNPMX", "UYST": "UYST", "WITA": "WITA", "ARST": "ARST", "CLST": "CLST", "UYT": "UYT", "VET": "VET", "HNNOMX": "HNNOMX", "ACDT": "ACDT", "∅∅∅": "∅∅∅", "SAST": "SAST", "GYT": "GYT", "CST": "CST", "LHST": "LHST", "AST": "AST", "HKT": "HKT", "EST": "EST", "WIB": "WIB", "CHADT": "CHADT", "AWST": "AWST", "CAT": "CAT", "EDT": "EDT", "SGT": "SGT", "HEPM": "HEPM", "PDT": "PDT", "MESZ": "MESZ", "HECU": "HECU", "HKST": "HKST", "ECT": "ECT", "OEZ": "OEZ", "HEOG": "HEOG", "HEEG": "HEEG", "ACWST": "ACWST", "NZST": "NZST", "JDT": "JDT", "MEZ": "MEZ", "WAT": "WAT", "AKDT": "AKDT", "GMT": "GMT", "HNPM": "HNPM", "ACST": "ACST", "HNOG": "HNOG", "COT": "COT", "HEPMX": "HEPMX", "MST": "MST", "NZDT": "NZDT", "LHDT": "LHDT", "JST": "JST", "WAST": "WAST", "CLT": "CLT", "GFT": "GFT", "MYT": "MYT", "HADT": "HADT", "TMST": "TMST", "ACWDT": "ACWDT", "HAST": "HAST", "HENOMX": "HENOMX", "IST": "IST", "AEDT": "AEDT", "BT": "BT", "AWDT": "AWDT", "WIT": "WIT", "WESZ": "WESZ"},
68 // Locale returns the current translators string locale
69 func (kab *kab) Locale() string {
73 // PluralsCardinal returns the list of cardinal plural rules associated with 'kab'
74 func (kab *kab) PluralsCardinal() []locales.PluralRule {
75 return kab.pluralsCardinal
78 // PluralsOrdinal returns the list of ordinal plural rules associated with 'kab'
79 func (kab *kab) PluralsOrdinal() []locales.PluralRule {
80 return kab.pluralsOrdinal
83 // PluralsRange returns the list of range plural rules associated with 'kab'
84 func (kab *kab) PluralsRange() []locales.PluralRule {
85 return kab.pluralsRange
88 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'kab'
89 func (kab *kab) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
95 return locales.PluralRuleOne
98 return locales.PluralRuleOther
101 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'kab'
102 func (kab *kab) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
103 return locales.PluralRuleUnknown
106 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'kab'
107 func (kab *kab) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
108 return locales.PluralRuleUnknown
111 // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
112 func (kab *kab) MonthAbbreviated(month time.Month) string {
113 return kab.monthsAbbreviated[month]
116 // MonthsAbbreviated returns the locales abbreviated months
117 func (kab *kab) MonthsAbbreviated() []string {
118 return kab.monthsAbbreviated[1:]
121 // MonthNarrow returns the locales narrow month given the 'month' provided
122 func (kab *kab) MonthNarrow(month time.Month) string {
123 return kab.monthsNarrow[month]
126 // MonthsNarrow returns the locales narrow months
127 func (kab *kab) MonthsNarrow() []string {
128 return kab.monthsNarrow[1:]
131 // MonthWide returns the locales wide month given the 'month' provided
132 func (kab *kab) MonthWide(month time.Month) string {
133 return kab.monthsWide[month]
136 // MonthsWide returns the locales wide months
137 func (kab *kab) MonthsWide() []string {
138 return kab.monthsWide[1:]
141 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
142 func (kab *kab) WeekdayAbbreviated(weekday time.Weekday) string {
143 return kab.daysAbbreviated[weekday]
146 // WeekdaysAbbreviated returns the locales abbreviated weekdays
147 func (kab *kab) WeekdaysAbbreviated() []string {
148 return kab.daysAbbreviated
151 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
152 func (kab *kab) WeekdayNarrow(weekday time.Weekday) string {
153 return kab.daysNarrow[weekday]
156 // WeekdaysNarrow returns the locales narrow weekdays
157 func (kab *kab) WeekdaysNarrow() []string {
158 return kab.daysNarrow
161 // WeekdayShort returns the locales short weekday given the 'weekday' provided
162 func (kab *kab) WeekdayShort(weekday time.Weekday) string {
163 return kab.daysShort[weekday]
166 // WeekdaysShort returns the locales short weekdays
167 func (kab *kab) WeekdaysShort() []string {
171 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
172 func (kab *kab) WeekdayWide(weekday time.Weekday) string {
173 return kab.daysWide[weekday]
176 // WeekdaysWide returns the locales wide weekdays
177 func (kab *kab) WeekdaysWide() []string {
181 // Decimal returns the decimal point of number
182 func (kab *kab) Decimal() string {
186 // Group returns the group of number
187 func (kab *kab) Group() string {
191 // Group returns the minus sign of number
192 func (kab *kab) Minus() string {
196 // FmtNumber returns 'num' with digits/precision of 'v' for 'kab' and handles both Whole and Real numbers based on 'v'
197 func (kab *kab) FmtNumber(num float64, v uint64) string {
199 return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
202 // FmtPercent returns 'num' with digits/precision of 'v' for 'kab' and handles both Whole and Real numbers based on 'v'
203 // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
204 func (kab *kab) FmtPercent(num float64, v uint64) string {
205 return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
208 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'kab'
209 func (kab *kab) FmtCurrency(num float64, v uint64, currency currency.Type) string {
211 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
212 symbol := kab.currencies[currency]
213 l := len(s) + len(symbol) + 1 + 2*len(s[:len(s)-int(v)-1])/3
216 b := make([]byte, 0, l)
218 for i := len(s) - 1; i >= 0; i-- {
221 b = append(b, kab.decimal[0])
228 for j := len(kab.group) - 1; j >= 0; j-- {
229 b = append(b, kab.group[j])
241 b = append(b, kab.minus[0])
245 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
246 b[i], b[j] = b[j], b[i]
252 b = append(b, kab.decimal...)
255 for i := 0; i < 2-int(v); i++ {
260 b = append(b, symbol...)
265 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'kab'
266 // in accounting notation.
267 func (kab *kab) FmtAccounting(num float64, v uint64, currency currency.Type) string {
269 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
270 symbol := kab.currencies[currency]
271 l := len(s) + len(symbol) + 1 + 2*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, kab.decimal[0])
286 for j := len(kab.group) - 1; j >= 0; j-- {
287 b = append(b, kab.group[j])
300 b = append(b, kab.minus[0])
305 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
306 b[i], b[j] = b[j], b[i]
312 b = append(b, kab.decimal...)
315 for i := 0; i < 2-int(v); i++ {
321 b = append(b, symbol...)
324 b = append(b, symbol...)
330 // FmtDateShort returns the short date representation of 't' for 'kab'
331 func (kab *kab) FmtDateShort(t time.Time) string {
333 b := make([]byte, 0, 32)
335 b = strconv.AppendInt(b, int64(t.Day()), 10)
336 b = append(b, []byte{0x2f}...)
337 b = strconv.AppendInt(b, int64(t.Month()), 10)
338 b = append(b, []byte{0x2f}...)
341 b = strconv.AppendInt(b, int64(t.Year()), 10)
343 b = strconv.AppendInt(b, int64(-t.Year()), 10)
349 // FmtDateMedium returns the medium date representation of 't' for 'kab'
350 func (kab *kab) FmtDateMedium(t time.Time) string {
352 b := make([]byte, 0, 32)
354 b = strconv.AppendInt(b, int64(t.Day()), 10)
355 b = append(b, []byte{0x20}...)
356 b = append(b, kab.monthsAbbreviated[t.Month()]...)
357 b = append(b, []byte{0x2c, 0x20}...)
360 b = strconv.AppendInt(b, int64(t.Year()), 10)
362 b = strconv.AppendInt(b, int64(-t.Year()), 10)
368 // FmtDateLong returns the long date representation of 't' for 'kab'
369 func (kab *kab) FmtDateLong(t time.Time) string {
371 b := make([]byte, 0, 32)
373 b = strconv.AppendInt(b, int64(t.Day()), 10)
374 b = append(b, []byte{0x20}...)
375 b = append(b, kab.monthsWide[t.Month()]...)
376 b = append(b, []byte{0x20}...)
379 b = strconv.AppendInt(b, int64(t.Year()), 10)
381 b = strconv.AppendInt(b, int64(-t.Year()), 10)
387 // FmtDateFull returns the full date representation of 't' for 'kab'
388 func (kab *kab) FmtDateFull(t time.Time) string {
390 b := make([]byte, 0, 32)
392 b = append(b, kab.daysWide[t.Weekday()]...)
393 b = append(b, []byte{0x20}...)
394 b = strconv.AppendInt(b, int64(t.Day()), 10)
395 b = append(b, []byte{0x20}...)
396 b = append(b, kab.monthsWide[t.Month()]...)
397 b = append(b, []byte{0x20}...)
400 b = strconv.AppendInt(b, int64(t.Year()), 10)
402 b = strconv.AppendInt(b, int64(-t.Year()), 10)
408 // FmtTimeShort returns the short time representation of 't' for 'kab'
409 func (kab *kab) FmtTimeShort(t time.Time) string {
411 b := make([]byte, 0, 32)
419 b = strconv.AppendInt(b, int64(h), 10)
420 b = append(b, kab.timeSeparator...)
426 b = strconv.AppendInt(b, int64(t.Minute()), 10)
427 b = append(b, []byte{0x20}...)
430 b = append(b, kab.periodsAbbreviated[0]...)
432 b = append(b, kab.periodsAbbreviated[1]...)
438 // FmtTimeMedium returns the medium time representation of 't' for 'kab'
439 func (kab *kab) FmtTimeMedium(t time.Time) string {
441 b := make([]byte, 0, 32)
449 b = strconv.AppendInt(b, int64(h), 10)
450 b = append(b, kab.timeSeparator...)
456 b = strconv.AppendInt(b, int64(t.Minute()), 10)
457 b = append(b, kab.timeSeparator...)
463 b = strconv.AppendInt(b, int64(t.Second()), 10)
464 b = append(b, []byte{0x20}...)
467 b = append(b, kab.periodsAbbreviated[0]...)
469 b = append(b, kab.periodsAbbreviated[1]...)
475 // FmtTimeLong returns the long time representation of 't' for 'kab'
476 func (kab *kab) FmtTimeLong(t time.Time) string {
478 b := make([]byte, 0, 32)
486 b = strconv.AppendInt(b, int64(h), 10)
487 b = append(b, kab.timeSeparator...)
493 b = strconv.AppendInt(b, int64(t.Minute()), 10)
494 b = append(b, kab.timeSeparator...)
500 b = strconv.AppendInt(b, int64(t.Second()), 10)
501 b = append(b, []byte{0x20}...)
504 b = append(b, kab.periodsAbbreviated[0]...)
506 b = append(b, kab.periodsAbbreviated[1]...)
509 b = append(b, []byte{0x20}...)
517 // FmtTimeFull returns the full time representation of 't' for 'kab'
518 func (kab *kab) FmtTimeFull(t time.Time) string {
520 b := make([]byte, 0, 32)
528 b = strconv.AppendInt(b, int64(h), 10)
529 b = append(b, kab.timeSeparator...)
535 b = strconv.AppendInt(b, int64(t.Minute()), 10)
536 b = append(b, kab.timeSeparator...)
542 b = strconv.AppendInt(b, int64(t.Second()), 10)
543 b = append(b, []byte{0x20}...)
546 b = append(b, kab.periodsAbbreviated[0]...)
548 b = append(b, kab.periodsAbbreviated[1]...)
551 b = append(b, []byte{0x20}...)
555 if btz, ok := kab.timezones[tz]; ok {
556 b = append(b, btz...)