1package ak 2 3import ( 4 "math" 5 "strconv" 6 "time" 7 8 "github.com/go-playground/locales" 9 "github.com/go-playground/locales/currency" 10) 11 12type 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 // idx = enum of currency code 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// New returns a new instance of translator for the 'ak' locale 43func New() locales.Translator { 44 return &ak{ 45 locale: "ak", 46 pluralsCardinal: []locales.PluralRule{2, 6}, 47 pluralsOrdinal: nil, 48 pluralsRange: []locales.PluralRule{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", "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", "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{"", "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{"PDT": "PDT", "HNPMX": "HNPMX", "AEST": "AEST", "AEDT": "AEDT", "JDT": "JDT", "MST": "MST", "BT": "BT", "HNEG": "HNEG", "HNOG": "HNOG", "HKST": "HKST", "HAST": "HAST", "EST": "EST", "EDT": "EDT", "ACWDT": "ACWDT", "LHDT": "LHDT", "WITA": "WITA", "CLT": "CLT", "HADT": "HADT", "CHADT": "CHADT", "CDT": "CDT", "SAST": "SAST", "HENOMX": "HENOMX", "CHAST": "CHAST", "LHST": "LHST", "VET": "VET", "ARST": "ARST", "COT": "COT", "TMST": "TMST", "OESZ": "OESZ", "GMT": "GMT", "UYT": "UYT", "ChST": "ChST", "BOT": "BOT", "CAT": "CAT", "UYST": "UYST", "AWDT": "AWDT", "WESZ": "WESZ", "MYT": "MYT", "ACWST": "ACWST", "COST": "COST", "WIT": "WIT", "ART": "ART", "∅∅∅": "∅∅∅", "NZDT": "NZDT", "ACDT": "ACDT", "HNPM": "HNPM", "MDT": "MDT", "SGT": "SGT", "WARST": "WARST", "AWST": "AWST", "PST": "PST", "NZST": "NZST", "GFT": "GFT", "AKST": "AKST", "HECU": "HECU", "EAT": "EAT", "AST": "AST", "WIB": "WIB", "AKDT": "AKDT", "HEEG": "HEEG", "MEZ": "MEZ", "HNT": "HNT", "HNNOMX": "HNNOMX", "HEPMX": "HEPMX", "ADT": "ADT", "ECT": "ECT", "HKT": "HKT", "IST": "IST", "HEPM": "HEPM", "CLST": "CLST", "HNCU": "HNCU", "CST": "CST", "WAST": "WAST", "ACST": "ACST", "MESZ": "MESZ", "WART": "WART", "OEZ": "OEZ", "TMT": "TMT", "GYT": "GYT", "WAT": "WAT", "WEZ": "WEZ", "JST": "JST", "HEOG": "HEOG", "HAT": "HAT", "SRT": "SRT"}, 64 } 65} 66 67// Locale returns the current translators string locale 68func (ak *ak) Locale() string { 69 return ak.locale 70} 71 72// PluralsCardinal returns the list of cardinal plural rules associated with 'ak' 73func (ak *ak) PluralsCardinal() []locales.PluralRule { 74 return ak.pluralsCardinal 75} 76 77// PluralsOrdinal returns the list of ordinal plural rules associated with 'ak' 78func (ak *ak) PluralsOrdinal() []locales.PluralRule { 79 return ak.pluralsOrdinal 80} 81 82// PluralsRange returns the list of range plural rules associated with 'ak' 83func (ak *ak) PluralsRange() []locales.PluralRule { 84 return ak.pluralsRange 85} 86 87// CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'ak' 88func (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// OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'ak' 100func (ak *ak) OrdinalPluralRule(num float64, v uint64) locales.PluralRule { 101 return locales.PluralRuleUnknown 102} 103 104// RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'ak' 105func (ak *ak) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule { 106 return locales.PluralRuleOther 107} 108 109// MonthAbbreviated returns the locales abbreviated month given the 'month' provided 110func (ak *ak) MonthAbbreviated(month time.Month) string { 111 return ak.monthsAbbreviated[month] 112} 113 114// MonthsAbbreviated returns the locales abbreviated months 115func (ak *ak) MonthsAbbreviated() []string { 116 return ak.monthsAbbreviated[1:] 117} 118 119// MonthNarrow returns the locales narrow month given the 'month' provided 120func (ak *ak) MonthNarrow(month time.Month) string { 121 return ak.monthsNarrow[month] 122} 123 124// MonthsNarrow returns the locales narrow months 125func (ak *ak) MonthsNarrow() []string { 126 return nil 127} 128 129// MonthWide returns the locales wide month given the 'month' provided 130func (ak *ak) MonthWide(month time.Month) string { 131 return ak.monthsWide[month] 132} 133 134// MonthsWide returns the locales wide months 135func (ak *ak) MonthsWide() []string { 136 return ak.monthsWide[1:] 137} 138 139// WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided 140func (ak *ak) WeekdayAbbreviated(weekday time.Weekday) string { 141 return ak.daysAbbreviated[weekday] 142} 143 144// WeekdaysAbbreviated returns the locales abbreviated weekdays 145func (ak *ak) WeekdaysAbbreviated() []string { 146 return ak.daysAbbreviated 147} 148 149// WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided 150func (ak *ak) WeekdayNarrow(weekday time.Weekday) string { 151 return ak.daysNarrow[weekday] 152} 153 154// WeekdaysNarrow returns the locales narrow weekdays 155func (ak *ak) WeekdaysNarrow() []string { 156 return ak.daysNarrow 157} 158 159// WeekdayShort returns the locales short weekday given the 'weekday' provided 160func (ak *ak) WeekdayShort(weekday time.Weekday) string { 161 return ak.daysShort[weekday] 162} 163 164// WeekdaysShort returns the locales short weekdays 165func (ak *ak) WeekdaysShort() []string { 166 return ak.daysShort 167} 168 169// WeekdayWide returns the locales wide weekday given the 'weekday' provided 170func (ak *ak) WeekdayWide(weekday time.Weekday) string { 171 return ak.daysWide[weekday] 172} 173 174// WeekdaysWide returns the locales wide weekdays 175func (ak *ak) WeekdaysWide() []string { 176 return ak.daysWide 177} 178 179// Decimal returns the decimal point of number 180func (ak *ak) Decimal() string { 181 return ak.decimal 182} 183 184// Group returns the group of number 185func (ak *ak) Group() string { 186 return ak.group 187} 188 189// Group returns the minus sign of number 190func (ak *ak) Minus() string { 191 return ak.minus 192} 193 194// FmtNumber returns 'num' with digits/precision of 'v' for 'ak' and handles both Whole and Real numbers based on 'v' 195func (ak *ak) FmtNumber(num float64, v uint64) string { 196 197 return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 198} 199 200// FmtPercent returns 'num' with digits/precision of 'v' for 'ak' and handles both Whole and Real numbers based on 'v' 201// NOTE: 'num' passed into FmtPercent is assumed to be in percent already 202func (ak *ak) FmtPercent(num float64, v uint64) string { 203 return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 204} 205 206// FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'ak' 207func (ak *ak) FmtCurrency(num float64, v uint64, currency currency.Type) string { 208 209 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 210 symbol := ak.currencies[currency] 211 l := len(s) + len(symbol) + 1 + 1*len(s[:len(s)-int(v)-1])/3 212 count := 0 213 inWhole := v == 0 214 b := make([]byte, 0, l) 215 216 for i := len(s) - 1; i >= 0; i-- { 217 218 if s[i] == '.' { 219 b = append(b, ak.decimal[0]) 220 inWhole = true 221 continue 222 } 223 224 if inWhole { 225 if count == 3 { 226 b = append(b, ak.group[0]) 227 count = 1 228 } else { 229 count++ 230 } 231 } 232 233 b = append(b, s[i]) 234 } 235 236 for j := len(symbol) - 1; j >= 0; j-- { 237 b = append(b, symbol[j]) 238 } 239 240 if num < 0 { 241 b = append(b, ak.minus[0]) 242 } 243 244 // reverse 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] 247 } 248 249 if int(v) < 2 { 250 251 if v == 0 { 252 b = append(b, ak.decimal...) 253 } 254 255 for i := 0; i < 2-int(v); i++ { 256 b = append(b, '0') 257 } 258 } 259 260 return string(b) 261} 262 263// FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'ak' 264// in accounting notation. 265func (ak *ak) FmtAccounting(num float64, v uint64, currency currency.Type) string { 266 267 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 268 symbol := ak.currencies[currency] 269 l := len(s) + len(symbol) + 1 + 1*len(s[:len(s)-int(v)-1])/3 270 count := 0 271 inWhole := v == 0 272 b := make([]byte, 0, l) 273 274 for i := len(s) - 1; i >= 0; i-- { 275 276 if s[i] == '.' { 277 b = append(b, ak.decimal[0]) 278 inWhole = true 279 continue 280 } 281 282 if inWhole { 283 if count == 3 { 284 b = append(b, ak.group[0]) 285 count = 1 286 } else { 287 count++ 288 } 289 } 290 291 b = append(b, s[i]) 292 } 293 294 if num < 0 { 295 296 for j := len(symbol) - 1; j >= 0; j-- { 297 b = append(b, symbol[j]) 298 } 299 300 b = append(b, ak.minus[0]) 301 302 } else { 303 304 for j := len(symbol) - 1; j >= 0; j-- { 305 b = append(b, symbol[j]) 306 } 307 308 } 309 310 // reverse 311 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { 312 b[i], b[j] = b[j], b[i] 313 } 314 315 if int(v) < 2 { 316 317 if v == 0 { 318 b = append(b, ak.decimal...) 319 } 320 321 for i := 0; i < 2-int(v); i++ { 322 b = append(b, '0') 323 } 324 } 325 326 return string(b) 327} 328 329// FmtDateShort returns the short date representation of 't' for 'ak' 330func (ak *ak) FmtDateShort(t time.Time) string { 331 332 b := make([]byte, 0, 32) 333 334 if t.Year() > 9 { 335 b = append(b, strconv.Itoa(t.Year())[2:]...) 336 } else { 337 b = append(b, strconv.Itoa(t.Year())[1:]...) 338 } 339 340 b = append(b, []byte{0x2f}...) 341 342 if t.Month() < 10 { 343 b = append(b, '0') 344 } 345 346 b = strconv.AppendInt(b, int64(t.Month()), 10) 347 348 b = append(b, []byte{0x2f}...) 349 350 if t.Day() < 10 { 351 b = append(b, '0') 352 } 353 354 b = strconv.AppendInt(b, int64(t.Day()), 10) 355 356 return string(b) 357} 358 359// FmtDateMedium returns the medium date representation of 't' for 'ak' 360func (ak *ak) FmtDateMedium(t time.Time) string { 361 362 b := make([]byte, 0, 32) 363 364 if t.Year() > 0 { 365 b = strconv.AppendInt(b, int64(t.Year()), 10) 366 } else { 367 b = strconv.AppendInt(b, int64(-t.Year()), 10) 368 } 369 370 b = append(b, []byte{0x20}...) 371 b = append(b, ak.monthsAbbreviated[t.Month()]...) 372 b = append(b, []byte{0x20}...) 373 b = strconv.AppendInt(b, int64(t.Day()), 10) 374 375 return string(b) 376} 377 378// FmtDateLong returns the long date representation of 't' for 'ak' 379func (ak *ak) FmtDateLong(t time.Time) string { 380 381 b := make([]byte, 0, 32) 382 383 if t.Year() > 0 { 384 b = strconv.AppendInt(b, int64(t.Year()), 10) 385 } else { 386 b = strconv.AppendInt(b, int64(-t.Year()), 10) 387 } 388 389 b = append(b, []byte{0x20}...) 390 b = append(b, ak.monthsWide[t.Month()]...) 391 b = append(b, []byte{0x20}...) 392 b = strconv.AppendInt(b, int64(t.Day()), 10) 393 394 return string(b) 395} 396 397// FmtDateFull returns the full date representation of 't' for 'ak' 398func (ak *ak) FmtDateFull(t time.Time) string { 399 400 b := make([]byte, 0, 32) 401 402 b = append(b, ak.daysWide[t.Weekday()]...) 403 b = append(b, []byte{0x2c, 0x20}...) 404 405 if t.Year() > 0 { 406 b = strconv.AppendInt(b, int64(t.Year()), 10) 407 } else { 408 b = strconv.AppendInt(b, int64(-t.Year()), 10) 409 } 410 411 b = append(b, []byte{0x20}...) 412 b = append(b, ak.monthsWide[t.Month()]...) 413 b = append(b, []byte{0x20}...) 414 415 if t.Day() < 10 { 416 b = append(b, '0') 417 } 418 419 b = strconv.AppendInt(b, int64(t.Day()), 10) 420 421 return string(b) 422} 423 424// FmtTimeShort returns the short time representation of 't' for 'ak' 425func (ak *ak) FmtTimeShort(t time.Time) string { 426 427 b := make([]byte, 0, 32) 428 429 h := t.Hour() 430 431 if h > 12 { 432 h -= 12 433 } 434 435 b = strconv.AppendInt(b, int64(h), 10) 436 b = append(b, ak.timeSeparator...) 437 438 if t.Minute() < 10 { 439 b = append(b, '0') 440 } 441 442 b = strconv.AppendInt(b, int64(t.Minute()), 10) 443 b = append(b, []byte{0x20}...) 444 445 if t.Hour() < 12 { 446 b = append(b, ak.periodsAbbreviated[0]...) 447 } else { 448 b = append(b, ak.periodsAbbreviated[1]...) 449 } 450 451 return string(b) 452} 453 454// FmtTimeMedium returns the medium time representation of 't' for 'ak' 455func (ak *ak) FmtTimeMedium(t time.Time) string { 456 457 b := make([]byte, 0, 32) 458 459 h := t.Hour() 460 461 if h > 12 { 462 h -= 12 463 } 464 465 b = strconv.AppendInt(b, int64(h), 10) 466 b = append(b, ak.timeSeparator...) 467 468 if t.Minute() < 10 { 469 b = append(b, '0') 470 } 471 472 b = strconv.AppendInt(b, int64(t.Minute()), 10) 473 b = append(b, ak.timeSeparator...) 474 475 if t.Second() < 10 { 476 b = append(b, '0') 477 } 478 479 b = strconv.AppendInt(b, int64(t.Second()), 10) 480 b = append(b, []byte{0x20}...) 481 482 if t.Hour() < 12 { 483 b = append(b, ak.periodsAbbreviated[0]...) 484 } else { 485 b = append(b, ak.periodsAbbreviated[1]...) 486 } 487 488 return string(b) 489} 490 491// FmtTimeLong returns the long time representation of 't' for 'ak' 492func (ak *ak) FmtTimeLong(t time.Time) string { 493 494 b := make([]byte, 0, 32) 495 496 h := t.Hour() 497 498 if h > 12 { 499 h -= 12 500 } 501 502 b = strconv.AppendInt(b, int64(h), 10) 503 b = append(b, ak.timeSeparator...) 504 505 if t.Minute() < 10 { 506 b = append(b, '0') 507 } 508 509 b = strconv.AppendInt(b, int64(t.Minute()), 10) 510 b = append(b, ak.timeSeparator...) 511 512 if t.Second() < 10 { 513 b = append(b, '0') 514 } 515 516 b = strconv.AppendInt(b, int64(t.Second()), 10) 517 b = append(b, []byte{0x20}...) 518 519 if t.Hour() < 12 { 520 b = append(b, ak.periodsAbbreviated[0]...) 521 } else { 522 b = append(b, ak.periodsAbbreviated[1]...) 523 } 524 525 b = append(b, []byte{0x20}...) 526 527 tz, _ := t.Zone() 528 b = append(b, tz...) 529 530 return string(b) 531} 532 533// FmtTimeFull returns the full time representation of 't' for 'ak' 534func (ak *ak) FmtTimeFull(t time.Time) string { 535 536 b := make([]byte, 0, 32) 537 538 h := t.Hour() 539 540 if h > 12 { 541 h -= 12 542 } 543 544 b = strconv.AppendInt(b, int64(h), 10) 545 b = append(b, ak.timeSeparator...) 546 547 if t.Minute() < 10 { 548 b = append(b, '0') 549 } 550 551 b = strconv.AppendInt(b, int64(t.Minute()), 10) 552 b = append(b, ak.timeSeparator...) 553 554 if t.Second() < 10 { 555 b = append(b, '0') 556 } 557 558 b = strconv.AppendInt(b, int64(t.Second()), 10) 559 b = append(b, []byte{0x20}...) 560 561 if t.Hour() < 12 { 562 b = append(b, ak.periodsAbbreviated[0]...) 563 } else { 564 b = append(b, ak.periodsAbbreviated[1]...) 565 } 566 567 b = append(b, []byte{0x20}...) 568 569 tz, _ := t.Zone() 570 571 if btz, ok := ak.timezones[tz]; ok { 572 b = append(b, btz...) 573 } else { 574 b = append(b, tz...) 575 } 576 577 return string(b) 578} 579