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 'ckb' locale
46 func New() locales.Translator {
49 pluralsCardinal: []locales.PluralRule{2, 6},
58 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"},
60 currencyPositiveSuffix: " ",
61 currencyNegativeSuffix: " ",
62 monthsAbbreviated: []string{"", "کانوونی دووەم", "شوبات", "ئازار", "نیسان", "ئایار", "حوزەیران", "تەمووز", "ئاب", "ئەیلوول", "تشرینی یەکەم", "تشرینی دووەم", "کانونی یەکەم"},
63 monthsNarrow: []string{"", "ک", "ش", "ئ", "ن", "ئ", "ح", "ت", "ئ", "ئ", "ت", "ت", "ک"},
64 monthsWide: []string{"", "کانوونی دووەم", "شوبات", "ئازار", "نیسان", "ئایار", "حوزەیران", "تەمووز", "ئاب", "ئەیلوول", "تشرینی یەکەم", "تشرینی دووەم", "کانونی یەکەم"},
65 daysAbbreviated: []string{"یەکشەممە", "دووشەممە", "سێشەممە", "چوارشەممە", "پێنجشەممە", "ھەینی", "شەممە"},
66 daysNarrow: []string{"ی", "د", "س", "چ", "پ", "ھ", "ش"},
67 daysShort: []string{"١ش", "٢ش", "٣ش", "٤ش", "٥ش", "ھ", "ش"},
68 daysWide: []string{"یەکشەممە", "دووشەممە", "سێشەممە", "چوارشەممە", "پێنجشەممە", "ھەینی", "شەممە"},
69 periodsAbbreviated: []string{"ب.ن", "د.ن"},
70 periodsNarrow: []string{"ب.ن", "د.ن"},
71 periodsWide: []string{"ب.ن", "د.ن"},
72 erasAbbreviated: []string{"پێش زایین", "زایینی"},
73 erasNarrow: []string{"پ.ن", "ز"},
74 erasWide: []string{"پێش زایین", "زایینی"},
75 timezones: map[string]string{"EDT": "EDT", "AKST": "AKST", "ACWST": "ACWST", "CST": "CST", "IST": "IST", "GYT": "GYT", "PDT": "PDT", "MDT": "MDT", "CHADT": "CHADT", "BOT": "BOT", "ARST": "ARST", "WAT": "WAT", "CLST": "CLST", "∅∅∅": "∅∅∅", "HEPMX": "HEPMX", "WITA": "WITA", "WAST": "WAST", "COT": "COT", "HNT": "HNT", "CAT": "CAT", "WIT": "WIT", "AWDT": "AWDT", "UYT": "UYT", "NZST": "NZST", "LHST": "LHST", "WARST": "WARST", "CLT": "CLT", "HNPMX": "HNPMX", "HEPM": "HEPM", "HAST": "HAST", "NZDT": "NZDT", "ECT": "ECT", "SRT": "SRT", "HNNOMX": "HNNOMX", "JDT": "JDT", "SAST": "SAST", "HKT": "HKT", "COST": "COST", "ChST": "ChST", "UYST": "UYST", "GMT": "GMT", "CHAST": "CHAST", "AWST": "AWST", "OESZ": "OESZ", "EAT": "EAT", "HAT": "HAT", "ACST": "ACST", "AKDT": "AKDT", "LHDT": "LHDT", "HNOG": "HNOG", "HNPM": "HNPM", "PST": "PST", "OEZ": "OEZ", "ART": "ART", "HADT": "HADT", "TMT": "TMT", "AEDT": "AEDT", "TMST": "TMST", "MESZ": "MESZ", "AEST": "AEST", "SGT": "SGT", "HNCU": "HNCU", "BT": "BT", "MST": "MST", "HENOMX": "HENOMX", "HEEG": "HEEG", "WESZ": "WESZ", "HECU": "HECU", "VET": "VET", "HEOG": "HEOG", "ADT": "ADT", "HNEG": "HNEG", "HKST": "HKST", "GFT": "GFT", "WEZ": "WEZ", "WART": "WART", "MEZ": "MEZ", "AST": "AST", "EST": "EST", "CDT": "CDT", "ACWDT": "ACWDT", "MYT": "MYT", "JST": "JST", "ACDT": "ACDT", "WIB": "WIB"},
79 // Locale returns the current translators string locale
80 func (ckb *ckb) Locale() string {
84 // PluralsCardinal returns the list of cardinal plural rules associated with 'ckb'
85 func (ckb *ckb) PluralsCardinal() []locales.PluralRule {
86 return ckb.pluralsCardinal
89 // PluralsOrdinal returns the list of ordinal plural rules associated with 'ckb'
90 func (ckb *ckb) PluralsOrdinal() []locales.PluralRule {
91 return ckb.pluralsOrdinal
94 // PluralsRange returns the list of range plural rules associated with 'ckb'
95 func (ckb *ckb) PluralsRange() []locales.PluralRule {
96 return ckb.pluralsRange
99 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'ckb'
100 func (ckb *ckb) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
105 return locales.PluralRuleOne
108 return locales.PluralRuleOther
111 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'ckb'
112 func (ckb *ckb) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
113 return locales.PluralRuleUnknown
116 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'ckb'
117 func (ckb *ckb) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
118 return locales.PluralRuleUnknown
121 // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
122 func (ckb *ckb) MonthAbbreviated(month time.Month) string {
123 return ckb.monthsAbbreviated[month]
126 // MonthsAbbreviated returns the locales abbreviated months
127 func (ckb *ckb) MonthsAbbreviated() []string {
128 return ckb.monthsAbbreviated[1:]
131 // MonthNarrow returns the locales narrow month given the 'month' provided
132 func (ckb *ckb) MonthNarrow(month time.Month) string {
133 return ckb.monthsNarrow[month]
136 // MonthsNarrow returns the locales narrow months
137 func (ckb *ckb) MonthsNarrow() []string {
138 return ckb.monthsNarrow[1:]
141 // MonthWide returns the locales wide month given the 'month' provided
142 func (ckb *ckb) MonthWide(month time.Month) string {
143 return ckb.monthsWide[month]
146 // MonthsWide returns the locales wide months
147 func (ckb *ckb) MonthsWide() []string {
148 return ckb.monthsWide[1:]
151 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
152 func (ckb *ckb) WeekdayAbbreviated(weekday time.Weekday) string {
153 return ckb.daysAbbreviated[weekday]
156 // WeekdaysAbbreviated returns the locales abbreviated weekdays
157 func (ckb *ckb) WeekdaysAbbreviated() []string {
158 return ckb.daysAbbreviated
161 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
162 func (ckb *ckb) WeekdayNarrow(weekday time.Weekday) string {
163 return ckb.daysNarrow[weekday]
166 // WeekdaysNarrow returns the locales narrow weekdays
167 func (ckb *ckb) WeekdaysNarrow() []string {
168 return ckb.daysNarrow
171 // WeekdayShort returns the locales short weekday given the 'weekday' provided
172 func (ckb *ckb) WeekdayShort(weekday time.Weekday) string {
173 return ckb.daysShort[weekday]
176 // WeekdaysShort returns the locales short weekdays
177 func (ckb *ckb) WeekdaysShort() []string {
181 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
182 func (ckb *ckb) WeekdayWide(weekday time.Weekday) string {
183 return ckb.daysWide[weekday]
186 // WeekdaysWide returns the locales wide weekdays
187 func (ckb *ckb) WeekdaysWide() []string {
191 // Decimal returns the decimal point of number
192 func (ckb *ckb) Decimal() string {
196 // Group returns the group of number
197 func (ckb *ckb) Group() string {
201 // Group returns the minus sign of number
202 func (ckb *ckb) Minus() string {
206 // FmtNumber returns 'num' with digits/precision of 'v' for 'ckb' and handles both Whole and Real numbers based on 'v'
207 func (ckb *ckb) FmtNumber(num float64, v uint64) string {
209 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
210 l := len(s) + 2 + 2*len(s[:len(s)-int(v)-1])/3
213 b := make([]byte, 0, l)
215 for i := len(s) - 1; i >= 0; i-- {
218 for j := len(ckb.decimal) - 1; j >= 0; j-- {
219 b = append(b, ckb.decimal[j])
227 for j := len(ckb.group) - 1; j >= 0; j-- {
228 b = append(b, ckb.group[j])
240 b = append(b, ckb.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 // FmtPercent returns 'num' with digits/precision of 'v' for 'ckb' and handles both Whole and Real numbers based on 'v'
252 // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
253 func (ckb *ckb) FmtPercent(num float64, v uint64) string {
254 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
256 b := make([]byte, 0, l)
258 for i := len(s) - 1; i >= 0; i-- {
261 for j := len(ckb.decimal) - 1; j >= 0; j-- {
262 b = append(b, ckb.decimal[j])
271 b = append(b, ckb.minus[0])
275 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
276 b[i], b[j] = b[j], b[i]
279 b = append(b, ckb.percentSuffix...)
281 b = append(b, ckb.percent...)
286 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'ckb'
287 func (ckb *ckb) FmtCurrency(num float64, v uint64, currency currency.Type) string {
289 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
290 symbol := ckb.currencies[currency]
291 l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
294 b := make([]byte, 0, l)
296 for i := len(s) - 1; i >= 0; i-- {
299 for j := len(ckb.decimal) - 1; j >= 0; j-- {
300 b = append(b, ckb.decimal[j])
308 for j := len(ckb.group) - 1; j >= 0; j-- {
309 b = append(b, ckb.group[j])
321 b = append(b, ckb.minus[0])
325 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
326 b[i], b[j] = b[j], b[i]
332 b = append(b, ckb.decimal...)
335 for i := 0; i < 2-int(v); i++ {
340 b = append(b, ckb.currencyPositiveSuffix...)
342 b = append(b, symbol...)
347 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'ckb'
348 // in accounting notation.
349 func (ckb *ckb) FmtAccounting(num float64, v uint64, currency currency.Type) string {
351 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
352 symbol := ckb.currencies[currency]
353 l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
356 b := make([]byte, 0, l)
358 for i := len(s) - 1; i >= 0; i-- {
361 for j := len(ckb.decimal) - 1; j >= 0; j-- {
362 b = append(b, ckb.decimal[j])
370 for j := len(ckb.group) - 1; j >= 0; j-- {
371 b = append(b, ckb.group[j])
384 b = append(b, ckb.minus[0])
389 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
390 b[i], b[j] = b[j], b[i]
396 b = append(b, ckb.decimal...)
399 for i := 0; i < 2-int(v); i++ {
405 b = append(b, ckb.currencyNegativeSuffix...)
406 b = append(b, symbol...)
409 b = append(b, ckb.currencyPositiveSuffix...)
410 b = append(b, symbol...)
416 // FmtDateShort returns the short date representation of 't' for 'ckb'
417 func (ckb *ckb) FmtDateShort(t time.Time) string {
419 b := make([]byte, 0, 32)
422 b = strconv.AppendInt(b, int64(t.Year()), 10)
424 b = strconv.AppendInt(b, int64(-t.Year()), 10)
427 b = append(b, []byte{0x2d}...)
433 b = strconv.AppendInt(b, int64(t.Month()), 10)
435 b = append(b, []byte{0x2d}...)
441 b = strconv.AppendInt(b, int64(t.Day()), 10)
446 // FmtDateMedium returns the medium date representation of 't' for 'ckb'
447 func (ckb *ckb) FmtDateMedium(t time.Time) string {
449 b := make([]byte, 0, 32)
452 b = strconv.AppendInt(b, int64(t.Year()), 10)
454 b = strconv.AppendInt(b, int64(-t.Year()), 10)
457 b = append(b, []byte{0x20}...)
458 b = append(b, ckb.monthsAbbreviated[t.Month()]...)
459 b = append(b, []byte{0x20}...)
460 b = strconv.AppendInt(b, int64(t.Day()), 10)
465 // FmtDateLong returns the long date representation of 't' for 'ckb'
466 func (ckb *ckb) FmtDateLong(t time.Time) string {
468 b := make([]byte, 0, 32)
470 b = strconv.AppendInt(b, int64(t.Day()), 10)
471 b = append(b, []byte{0xdb, 0x8c, 0x20}...)
472 b = append(b, ckb.monthsWide[t.Month()]...)
473 b = append(b, []byte{0xdb, 0x8c, 0x20}...)
476 b = strconv.AppendInt(b, int64(t.Year()), 10)
478 b = strconv.AppendInt(b, int64(-t.Year()), 10)
484 // FmtDateFull returns the full date representation of 't' for 'ckb'
485 func (ckb *ckb) FmtDateFull(t time.Time) string {
487 b := make([]byte, 0, 32)
490 b = strconv.AppendInt(b, int64(t.Year()), 10)
492 b = strconv.AppendInt(b, int64(-t.Year()), 10)
495 b = append(b, []byte{0x20}...)
496 b = append(b, ckb.monthsWide[t.Month()]...)
497 b = append(b, []byte{0x20}...)
498 b = strconv.AppendInt(b, int64(t.Day()), 10)
499 b = append(b, []byte{0x2c, 0x20}...)
500 b = append(b, ckb.daysWide[t.Weekday()]...)
505 // FmtTimeShort returns the short time representation of 't' for 'ckb'
506 func (ckb *ckb) FmtTimeShort(t time.Time) string {
508 b := make([]byte, 0, 32)
516 b = strconv.AppendInt(b, int64(h), 10)
517 b = append(b, ckb.timeSeparator...)
523 b = strconv.AppendInt(b, int64(t.Minute()), 10)
524 b = append(b, []byte{0x20}...)
527 b = append(b, ckb.periodsAbbreviated[0]...)
529 b = append(b, ckb.periodsAbbreviated[1]...)
535 // FmtTimeMedium returns the medium time representation of 't' for 'ckb'
536 func (ckb *ckb) FmtTimeMedium(t time.Time) string {
538 b := make([]byte, 0, 32)
546 b = strconv.AppendInt(b, int64(h), 10)
547 b = append(b, ckb.timeSeparator...)
553 b = strconv.AppendInt(b, int64(t.Minute()), 10)
554 b = append(b, ckb.timeSeparator...)
560 b = strconv.AppendInt(b, int64(t.Second()), 10)
561 b = append(b, []byte{0x20}...)
564 b = append(b, ckb.periodsAbbreviated[0]...)
566 b = append(b, ckb.periodsAbbreviated[1]...)
572 // FmtTimeLong returns the long time representation of 't' for 'ckb'
573 func (ckb *ckb) FmtTimeLong(t time.Time) string {
575 b := make([]byte, 0, 32)
583 b = strconv.AppendInt(b, int64(h), 10)
584 b = append(b, ckb.timeSeparator...)
590 b = strconv.AppendInt(b, int64(t.Minute()), 10)
591 b = append(b, ckb.timeSeparator...)
597 b = strconv.AppendInt(b, int64(t.Second()), 10)
598 b = append(b, []byte{0x20}...)
601 b = append(b, ckb.periodsAbbreviated[0]...)
603 b = append(b, ckb.periodsAbbreviated[1]...)
606 b = append(b, []byte{0x20}...)
614 // FmtTimeFull returns the full time representation of 't' for 'ckb'
615 func (ckb *ckb) FmtTimeFull(t time.Time) string {
617 b := make([]byte, 0, 32)
625 b = strconv.AppendInt(b, int64(h), 10)
626 b = append(b, ckb.timeSeparator...)
632 b = strconv.AppendInt(b, int64(t.Minute()), 10)
633 b = append(b, ckb.timeSeparator...)
639 b = strconv.AppendInt(b, int64(t.Second()), 10)
640 b = append(b, []byte{0x20}...)
643 b = append(b, ckb.periodsAbbreviated[0]...)
645 b = append(b, ckb.periodsAbbreviated[1]...)
648 b = append(b, []byte{0x20}...)
652 if btz, ok := ckb.timezones[tz]; ok {
653 b = append(b, btz...)