1 package ak
2
3 import (
4 "math"
5 "strconv"
6 "time"
7
8 "github.com/go-playground/locales"
9 "github.com/go-playground/locales/currency"
10 )
11
12 type ak struct {
13 locale string
14 pluralsCardinal []locales.PluralRule
15 pluralsOrdinal []locales.PluralRule
16 pluralsRange []locales.PluralRule
17 decimal string
18 group string
19 minus string
20 percent string
21 perMille string
22 timeSeparator string
23 inifinity string
24 currencies []string
25 monthsAbbreviated []string
26 monthsNarrow []string
27 monthsWide []string
28 daysAbbreviated []string
29 daysNarrow []string
30 daysShort []string
31 daysWide []string
32 periodsAbbreviated []string
33 periodsNarrow []string
34 periodsShort []string
35 periodsWide []string
36 erasAbbreviated []string
37 erasNarrow []string
38 erasWide []string
39 timezones map[string]string
40 }
41
42
43 func New() locales.Translator {
44 return &ak{
45 locale: "ak",
46 pluralsCardinal: []locales.PluralRule{2, 6},
47 pluralsOrdinal: nil,
48 pluralsRange: []locales.PluralRule{2, 6},
49 decimal: ".",
50 group: ",",
51 timeSeparator: ":",
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", "CNH", "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", "GH₵", "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", "MRU", "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", "STN", "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", "UYW", "UZS", "VEB", "VEF", "VES", "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{"", "S-Ɔ", "K-Ɔ", "E-Ɔ", "E-O", "E-K", "O-A", "A-K", "D-Ɔ", "F-Ɛ", "Ɔ-A", "Ɔ-O", "M-Ɔ"},
54 monthsWide: []string{"", "Sanda-Ɔpɛpɔn", "Kwakwar-Ɔgyefuo", "Ebɔw-Ɔbenem", "Ebɔbira-Oforisuo", "Esusow Aketseaba-Kɔtɔnimba", "Obirade-Ayɛwohomumu", "Ayɛwoho-Kitawonsa", "Difuu-Ɔsandaa", "Fankwa-Ɛbɔ", "Ɔbɛsɛ-Ahinime", "Ɔberɛfɛw-Obubuo", "Mumu-Ɔpɛnimba"},
55 daysAbbreviated: []string{"Kwe", "Dwo", "Ben", "Wuk", "Yaw", "Fia", "Mem"},
56 daysNarrow: []string{"K", "D", "B", "W", "Y", "F", "M"},
57 daysWide: []string{"Kwesida", "Dwowda", "Benada", "Wukuda", "Yawda", "Fida", "Memeneda"},
58 periodsAbbreviated: []string{"AN", "EW"},
59 periodsWide: []string{"AN", "EW"},
60 erasAbbreviated: []string{"AK", "KE"},
61 erasNarrow: []string{"", ""},
62 erasWide: []string{"Ansa Kristo", "Kristo Ekyiri"},
63 timezones: map[string]string{"ACDT": "ACDT", "ACST": "ACST", "ACWDT": "ACWDT", "ACWST": "ACWST", "ADT": "ADT", "AEDT": "AEDT", "AEST": "AEST", "AKDT": "AKDT", "AKST": "AKST", "ARST": "ARST", "ART": "ART", "AST": "AST", "AWDT": "AWDT", "AWST": "AWST", "BOT": "BOT", "BT": "BT", "CAT": "CAT", "CDT": "CDT", "CHADT": "CHADT", "CHAST": "CHAST", "CLST": "CLST", "CLT": "CLT", "COST": "COST", "COT": "COT", "CST": "CST", "ChST": "ChST", "EAT": "EAT", "ECT": "ECT", "EDT": "EDT", "EST": "EST", "GFT": "GFT", "GMT": "GMT", "GST": "GST", "GYT": "GYT", "HADT": "HADT", "HAST": "HAST", "HAT": "HAT", "HECU": "HECU", "HEEG": "HEEG", "HENOMX": "HENOMX", "HEOG": "HEOG", "HEPM": "HEPM", "HEPMX": "HEPMX", "HKST": "HKST", "HKT": "HKT", "HNCU": "HNCU", "HNEG": "HNEG", "HNNOMX": "HNNOMX", "HNOG": "HNOG", "HNPM": "HNPM", "HNPMX": "HNPMX", "HNT": "HNT", "IST": "IST", "JDT": "JDT", "JST": "JST", "LHDT": "LHDT", "LHST": "LHST", "MDT": "MDT", "MESZ": "MESZ", "MEZ": "MEZ", "MST": "MST", "MYT": "MYT", "NZDT": "NZDT", "NZST": "NZST", "OESZ": "OESZ", "OEZ": "OEZ", "PDT": "PDT", "PST": "PST", "SAST": "SAST", "SGT": "SGT", "SRT": "SRT", "TMST": "TMST", "TMT": "TMT", "UYST": "UYST", "UYT": "UYT", "VET": "VET", "WARST": "WARST", "WART": "WART", "WAST": "WAST", "WAT": "WAT", "WESZ": "WESZ", "WEZ": "WEZ", "WIB": "WIB", "WIT": "WIT", "WITA": "WITA", "∅∅∅": "∅∅∅"},
64 }
65 }
66
67
68 func (ak *ak) Locale() string {
69 return ak.locale
70 }
71
72
73 func (ak *ak) PluralsCardinal() []locales.PluralRule {
74 return ak.pluralsCardinal
75 }
76
77
78 func (ak *ak) PluralsOrdinal() []locales.PluralRule {
79 return ak.pluralsOrdinal
80 }
81
82
83 func (ak *ak) PluralsRange() []locales.PluralRule {
84 return ak.pluralsRange
85 }
86
87
88 func (ak *ak) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
89
90 n := math.Abs(num)
91
92 if n >= 0 && n <= 1 {
93 return locales.PluralRuleOne
94 }
95
96 return locales.PluralRuleOther
97 }
98
99
100 func (ak *ak) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
101 return locales.PluralRuleUnknown
102 }
103
104
105 func (ak *ak) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
106
107 start := ak.CardinalPluralRule(num1, v1)
108 end := ak.CardinalPluralRule(num2, v2)
109
110 if start == locales.PluralRuleOne && end == locales.PluralRuleOne {
111 return locales.PluralRuleOther
112 } else if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
113 return locales.PluralRuleOther
114 } else if start == locales.PluralRuleOther && end == locales.PluralRuleOne {
115 return locales.PluralRuleOne
116 }
117
118 return locales.PluralRuleOther
119
120 }
121
122
123 func (ak *ak) MonthAbbreviated(month time.Month) string {
124 return ak.monthsAbbreviated[month]
125 }
126
127
128 func (ak *ak) MonthsAbbreviated() []string {
129 return ak.monthsAbbreviated[1:]
130 }
131
132
133 func (ak *ak) MonthNarrow(month time.Month) string {
134 return ak.monthsNarrow[month]
135 }
136
137
138 func (ak *ak) MonthsNarrow() []string {
139 return nil
140 }
141
142
143 func (ak *ak) MonthWide(month time.Month) string {
144 return ak.monthsWide[month]
145 }
146
147
148 func (ak *ak) MonthsWide() []string {
149 return ak.monthsWide[1:]
150 }
151
152
153 func (ak *ak) WeekdayAbbreviated(weekday time.Weekday) string {
154 return ak.daysAbbreviated[weekday]
155 }
156
157
158 func (ak *ak) WeekdaysAbbreviated() []string {
159 return ak.daysAbbreviated
160 }
161
162
163 func (ak *ak) WeekdayNarrow(weekday time.Weekday) string {
164 return ak.daysNarrow[weekday]
165 }
166
167
168 func (ak *ak) WeekdaysNarrow() []string {
169 return ak.daysNarrow
170 }
171
172
173 func (ak *ak) WeekdayShort(weekday time.Weekday) string {
174 return ak.daysShort[weekday]
175 }
176
177
178 func (ak *ak) WeekdaysShort() []string {
179 return ak.daysShort
180 }
181
182
183 func (ak *ak) WeekdayWide(weekday time.Weekday) string {
184 return ak.daysWide[weekday]
185 }
186
187
188 func (ak *ak) WeekdaysWide() []string {
189 return ak.daysWide
190 }
191
192
193 func (ak *ak) Decimal() string {
194 return ak.decimal
195 }
196
197
198 func (ak *ak) Group() string {
199 return ak.group
200 }
201
202
203 func (ak *ak) Minus() string {
204 return ak.minus
205 }
206
207
208 func (ak *ak) FmtNumber(num float64, v uint64) string {
209
210 return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
211 }
212
213
214
215 func (ak *ak) FmtPercent(num float64, v uint64) string {
216 return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
217 }
218
219
220 func (ak *ak) FmtCurrency(num float64, v uint64, currency currency.Type) string {
221
222 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
223 symbol := ak.currencies[currency]
224 l := len(s) + len(symbol) + 1 + 1*len(s[:len(s)-int(v)-1])/3
225 count := 0
226 inWhole := v == 0
227 b := make([]byte, 0, l)
228
229 for i := len(s) - 1; i >= 0; i-- {
230
231 if s[i] == '.' {
232 b = append(b, ak.decimal[0])
233 inWhole = true
234 continue
235 }
236
237 if inWhole {
238 if count == 3 {
239 b = append(b, ak.group[0])
240 count = 1
241 } else {
242 count++
243 }
244 }
245
246 b = append(b, s[i])
247 }
248
249 for j := len(symbol) - 1; j >= 0; j-- {
250 b = append(b, symbol[j])
251 }
252
253 if num < 0 {
254 b = append(b, ak.minus[0])
255 }
256
257
258 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
259 b[i], b[j] = b[j], b[i]
260 }
261
262 if int(v) < 2 {
263
264 if v == 0 {
265 b = append(b, ak.decimal...)
266 }
267
268 for i := 0; i < 2-int(v); i++ {
269 b = append(b, '0')
270 }
271 }
272
273 return string(b)
274 }
275
276
277
278 func (ak *ak) FmtAccounting(num float64, v uint64, currency currency.Type) string {
279
280 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
281 symbol := ak.currencies[currency]
282 l := len(s) + len(symbol) + 1 + 1*len(s[:len(s)-int(v)-1])/3
283 count := 0
284 inWhole := v == 0
285 b := make([]byte, 0, l)
286
287 for i := len(s) - 1; i >= 0; i-- {
288
289 if s[i] == '.' {
290 b = append(b, ak.decimal[0])
291 inWhole = true
292 continue
293 }
294
295 if inWhole {
296 if count == 3 {
297 b = append(b, ak.group[0])
298 count = 1
299 } else {
300 count++
301 }
302 }
303
304 b = append(b, s[i])
305 }
306
307 if num < 0 {
308
309 for j := len(symbol) - 1; j >= 0; j-- {
310 b = append(b, symbol[j])
311 }
312
313 b = append(b, ak.minus[0])
314
315 } else {
316
317 for j := len(symbol) - 1; j >= 0; j-- {
318 b = append(b, symbol[j])
319 }
320
321 }
322
323
324 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
325 b[i], b[j] = b[j], b[i]
326 }
327
328 if int(v) < 2 {
329
330 if v == 0 {
331 b = append(b, ak.decimal...)
332 }
333
334 for i := 0; i < 2-int(v); i++ {
335 b = append(b, '0')
336 }
337 }
338
339 return string(b)
340 }
341
342
343 func (ak *ak) FmtDateShort(t time.Time) string {
344
345 b := make([]byte, 0, 32)
346
347 if t.Year() > 9 {
348 b = append(b, strconv.Itoa(t.Year())[2:]...)
349 } else {
350 b = append(b, strconv.Itoa(t.Year())[1:]...)
351 }
352
353 b = append(b, []byte{0x2f}...)
354
355 if t.Month() < 10 {
356 b = append(b, '0')
357 }
358
359 b = strconv.AppendInt(b, int64(t.Month()), 10)
360
361 b = append(b, []byte{0x2f}...)
362
363 if t.Day() < 10 {
364 b = append(b, '0')
365 }
366
367 b = strconv.AppendInt(b, int64(t.Day()), 10)
368
369 return string(b)
370 }
371
372
373 func (ak *ak) FmtDateMedium(t time.Time) string {
374
375 b := make([]byte, 0, 32)
376
377 if t.Year() > 0 {
378 b = strconv.AppendInt(b, int64(t.Year()), 10)
379 } else {
380 b = strconv.AppendInt(b, int64(-t.Year()), 10)
381 }
382
383 b = append(b, []byte{0x20}...)
384 b = append(b, ak.monthsAbbreviated[t.Month()]...)
385 b = append(b, []byte{0x20}...)
386 b = strconv.AppendInt(b, int64(t.Day()), 10)
387
388 return string(b)
389 }
390
391
392 func (ak *ak) FmtDateLong(t time.Time) string {
393
394 b := make([]byte, 0, 32)
395
396 if t.Year() > 0 {
397 b = strconv.AppendInt(b, int64(t.Year()), 10)
398 } else {
399 b = strconv.AppendInt(b, int64(-t.Year()), 10)
400 }
401
402 b = append(b, []byte{0x20}...)
403 b = append(b, ak.monthsWide[t.Month()]...)
404 b = append(b, []byte{0x20}...)
405 b = strconv.AppendInt(b, int64(t.Day()), 10)
406
407 return string(b)
408 }
409
410
411 func (ak *ak) FmtDateFull(t time.Time) string {
412
413 b := make([]byte, 0, 32)
414
415 b = append(b, ak.daysWide[t.Weekday()]...)
416 b = append(b, []byte{0x2c, 0x20}...)
417
418 if t.Year() > 0 {
419 b = strconv.AppendInt(b, int64(t.Year()), 10)
420 } else {
421 b = strconv.AppendInt(b, int64(-t.Year()), 10)
422 }
423
424 b = append(b, []byte{0x20}...)
425 b = append(b, ak.monthsWide[t.Month()]...)
426 b = append(b, []byte{0x20}...)
427
428 if t.Day() < 10 {
429 b = append(b, '0')
430 }
431
432 b = strconv.AppendInt(b, int64(t.Day()), 10)
433
434 return string(b)
435 }
436
437
438 func (ak *ak) FmtTimeShort(t time.Time) string {
439
440 b := make([]byte, 0, 32)
441
442 h := t.Hour()
443
444 if h > 12 {
445 h -= 12
446 }
447
448 b = strconv.AppendInt(b, int64(h), 10)
449 b = append(b, ak.timeSeparator...)
450
451 if t.Minute() < 10 {
452 b = append(b, '0')
453 }
454
455 b = strconv.AppendInt(b, int64(t.Minute()), 10)
456 b = append(b, []byte{0x20}...)
457
458 if t.Hour() < 12 {
459 b = append(b, ak.periodsAbbreviated[0]...)
460 } else {
461 b = append(b, ak.periodsAbbreviated[1]...)
462 }
463
464 return string(b)
465 }
466
467
468 func (ak *ak) FmtTimeMedium(t time.Time) string {
469
470 b := make([]byte, 0, 32)
471
472 h := t.Hour()
473
474 if h > 12 {
475 h -= 12
476 }
477
478 b = strconv.AppendInt(b, int64(h), 10)
479 b = append(b, ak.timeSeparator...)
480
481 if t.Minute() < 10 {
482 b = append(b, '0')
483 }
484
485 b = strconv.AppendInt(b, int64(t.Minute()), 10)
486 b = append(b, ak.timeSeparator...)
487
488 if t.Second() < 10 {
489 b = append(b, '0')
490 }
491
492 b = strconv.AppendInt(b, int64(t.Second()), 10)
493 b = append(b, []byte{0x20}...)
494
495 if t.Hour() < 12 {
496 b = append(b, ak.periodsAbbreviated[0]...)
497 } else {
498 b = append(b, ak.periodsAbbreviated[1]...)
499 }
500
501 return string(b)
502 }
503
504
505 func (ak *ak) FmtTimeLong(t time.Time) string {
506
507 b := make([]byte, 0, 32)
508
509 h := t.Hour()
510
511 if h > 12 {
512 h -= 12
513 }
514
515 b = strconv.AppendInt(b, int64(h), 10)
516 b = append(b, ak.timeSeparator...)
517
518 if t.Minute() < 10 {
519 b = append(b, '0')
520 }
521
522 b = strconv.AppendInt(b, int64(t.Minute()), 10)
523 b = append(b, ak.timeSeparator...)
524
525 if t.Second() < 10 {
526 b = append(b, '0')
527 }
528
529 b = strconv.AppendInt(b, int64(t.Second()), 10)
530 b = append(b, []byte{0x20}...)
531
532 if t.Hour() < 12 {
533 b = append(b, ak.periodsAbbreviated[0]...)
534 } else {
535 b = append(b, ak.periodsAbbreviated[1]...)
536 }
537
538 b = append(b, []byte{0x20}...)
539
540 tz, _ := t.Zone()
541 b = append(b, tz...)
542
543 return string(b)
544 }
545
546
547 func (ak *ak) FmtTimeFull(t time.Time) string {
548
549 b := make([]byte, 0, 32)
550
551 h := t.Hour()
552
553 if h > 12 {
554 h -= 12
555 }
556
557 b = strconv.AppendInt(b, int64(h), 10)
558 b = append(b, ak.timeSeparator...)
559
560 if t.Minute() < 10 {
561 b = append(b, '0')
562 }
563
564 b = strconv.AppendInt(b, int64(t.Minute()), 10)
565 b = append(b, ak.timeSeparator...)
566
567 if t.Second() < 10 {
568 b = append(b, '0')
569 }
570
571 b = strconv.AppendInt(b, int64(t.Second()), 10)
572 b = append(b, []byte{0x20}...)
573
574 if t.Hour() < 12 {
575 b = append(b, ak.periodsAbbreviated[0]...)
576 } else {
577 b = append(b, ak.periodsAbbreviated[1]...)
578 }
579
580 b = append(b, []byte{0x20}...)
581
582 tz, _ := t.Zone()
583
584 if btz, ok := ak.timezones[tz]; ok {
585 b = append(b, btz...)
586 } else {
587 b = append(b, tz...)
588 }
589
590 return string(b)
591 }
592
View as plain text