1package ak 2 3import ( 4 "math" 5 "strconv" 6 "time" 7 8 "github.com/gohugoio/locales" 9 "github.com/gohugoio/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{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// 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 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// MonthAbbreviated returns the locales abbreviated month given the 'month' provided 123func (ak *ak) MonthAbbreviated(month time.Month) string { 124 return ak.monthsAbbreviated[month] 125} 126 127// MonthsAbbreviated returns the locales abbreviated months 128func (ak *ak) MonthsAbbreviated() []string { 129 return ak.monthsAbbreviated[1:] 130} 131 132// MonthNarrow returns the locales narrow month given the 'month' provided 133func (ak *ak) MonthNarrow(month time.Month) string { 134 return ak.monthsNarrow[month] 135} 136 137// MonthsNarrow returns the locales narrow months 138func (ak *ak) MonthsNarrow() []string { 139 return nil 140} 141 142// MonthWide returns the locales wide month given the 'month' provided 143func (ak *ak) MonthWide(month time.Month) string { 144 return ak.monthsWide[month] 145} 146 147// MonthsWide returns the locales wide months 148func (ak *ak) MonthsWide() []string { 149 return ak.monthsWide[1:] 150} 151 152// WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided 153func (ak *ak) WeekdayAbbreviated(weekday time.Weekday) string { 154 return ak.daysAbbreviated[weekday] 155} 156 157// WeekdaysAbbreviated returns the locales abbreviated weekdays 158func (ak *ak) WeekdaysAbbreviated() []string { 159 return ak.daysAbbreviated 160} 161 162// WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided 163func (ak *ak) WeekdayNarrow(weekday time.Weekday) string { 164 return ak.daysNarrow[weekday] 165} 166 167// WeekdaysNarrow returns the locales narrow weekdays 168func (ak *ak) WeekdaysNarrow() []string { 169 return ak.daysNarrow 170} 171 172// WeekdayShort returns the locales short weekday given the 'weekday' provided 173func (ak *ak) WeekdayShort(weekday time.Weekday) string { 174 return ak.daysShort[weekday] 175} 176 177// WeekdaysShort returns the locales short weekdays 178func (ak *ak) WeekdaysShort() []string { 179 return ak.daysShort 180} 181 182// WeekdayWide returns the locales wide weekday given the 'weekday' provided 183func (ak *ak) WeekdayWide(weekday time.Weekday) string { 184 return ak.daysWide[weekday] 185} 186 187// WeekdaysWide returns the locales wide weekdays 188func (ak *ak) WeekdaysWide() []string { 189 return ak.daysWide 190} 191 192// Decimal returns the decimal point of number 193func (ak *ak) Decimal() string { 194 return ak.decimal 195} 196 197// Group returns the group of number 198func (ak *ak) Group() string { 199 return ak.group 200} 201 202// Group returns the minus sign of number 203func (ak *ak) Minus() string { 204 return ak.minus 205} 206 207// FmtNumber returns 'num' with digits/precision of 'v' for 'ak' and handles both Whole and Real numbers based on 'v' 208func (ak *ak) FmtNumber(num float64, v uint64) string { 209 210 return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 211} 212 213// FmtPercent returns 'num' with digits/precision of 'v' for 'ak' and handles both Whole and Real numbers based on 'v' 214// NOTE: 'num' passed into FmtPercent is assumed to be in percent already 215func (ak *ak) FmtPercent(num float64, v uint64) string { 216 return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) 217} 218 219// FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'ak' 220func (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 // reverse 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// FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'ak' 277// in accounting notation. 278func (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 // reverse 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// FmtDateShort returns the short date representation of 't' for 'ak' 343func (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// FmtDateMedium returns the medium date representation of 't' for 'ak' 373func (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// FmtDateLong returns the long date representation of 't' for 'ak' 392func (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// FmtDateFull returns the full date representation of 't' for 'ak' 411func (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// FmtTimeShort returns the short time representation of 't' for 'ak' 438func (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// FmtTimeMedium returns the medium time representation of 't' for 'ak' 468func (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// FmtTimeLong returns the long time representation of 't' for 'ak' 505func (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// FmtTimeFull returns the full time representation of 't' for 'ak' 547func (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