ps.go 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. package ps
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type ps struct {
  10. locale string
  11. pluralsCardinal []locales.PluralRule
  12. pluralsOrdinal []locales.PluralRule
  13. pluralsRange []locales.PluralRule
  14. decimal []byte
  15. group []byte
  16. minus []byte
  17. percent []byte
  18. perMille []byte
  19. timeSeparator []byte
  20. inifinity []byte
  21. currencies [][]byte // idx = enum of currency code
  22. currencyPositiveSuffix []byte
  23. currencyNegativeSuffix []byte
  24. monthsAbbreviated [][]byte
  25. monthsNarrow [][]byte
  26. monthsWide [][]byte
  27. daysAbbreviated [][]byte
  28. daysNarrow [][]byte
  29. daysShort [][]byte
  30. daysWide [][]byte
  31. periodsAbbreviated [][]byte
  32. periodsNarrow [][]byte
  33. periodsShort [][]byte
  34. periodsWide [][]byte
  35. erasAbbreviated [][]byte
  36. erasNarrow [][]byte
  37. erasWide [][]byte
  38. timezones map[string][]byte
  39. }
  40. // New returns a new instance of translator for the 'ps' locale
  41. func New() locales.Translator {
  42. return &ps{
  43. locale: "ps",
  44. pluralsCardinal: []locales.PluralRule{2, 6},
  45. pluralsOrdinal: nil,
  46. pluralsRange: nil,
  47. decimal: []byte{0xd9, 0xab},
  48. group: []byte{0xd9, 0xac},
  49. minus: []byte{},
  50. percent: []byte{0xd9, 0xaa},
  51. perMille: []byte{},
  52. timeSeparator: []byte{0x3a},
  53. currencies: [][]uint8{{0x41, 0x44, 0x50, 0x20}, {0x41, 0x45, 0x44, 0x20}, {0x41, 0x46, 0x41, 0x20}, {0xd8, 0x8b}, {0x41, 0x4c, 0x4b, 0x20}, {0x41, 0x4c, 0x4c, 0x20}, {0x41, 0x4d, 0x44, 0x20}, {0x41, 0x4e, 0x47, 0x20}, {0x41, 0x4f, 0x41, 0x20}, {0x41, 0x4f, 0x4b, 0x20}, {0x41, 0x4f, 0x4e, 0x20}, {0x41, 0x4f, 0x52, 0x20}, {0x41, 0x52, 0x41, 0x20}, {0x41, 0x52, 0x4c, 0x20}, {0x41, 0x52, 0x4d, 0x20}, {0x41, 0x52, 0x50, 0x20}, {0x41, 0x52, 0x53, 0x20}, {0x41, 0x54, 0x53, 0x20}, {0x41, 0x55, 0x44, 0x20}, {0x41, 0x57, 0x47, 0x20}, {0x41, 0x5a, 0x4d, 0x20}, {0x41, 0x5a, 0x4e, 0x20}, {0x42, 0x41, 0x44, 0x20}, {0x42, 0x41, 0x4d, 0x20}, {0x42, 0x41, 0x4e, 0x20}, {0x42, 0x42, 0x44, 0x20}, {0x42, 0x44, 0x54, 0x20}, {0x42, 0x45, 0x43, 0x20}, {0x42, 0x45, 0x46, 0x20}, {0x42, 0x45, 0x4c, 0x20}, {0x42, 0x47, 0x4c, 0x20}, {0x42, 0x47, 0x4d, 0x20}, {0x42, 0x47, 0x4e, 0x20}, {0x42, 0x47, 0x4f, 0x20}, {0x42, 0x48, 0x44, 0x20}, {0x42, 0x49, 0x46, 0x20}, {0x42, 0x4d, 0x44, 0x20}, {0x42, 0x4e, 0x44, 0x20}, {0x42, 0x4f, 0x42, 0x20}, {0x42, 0x4f, 0x4c, 0x20}, {0x42, 0x4f, 0x50, 0x20}, {0x42, 0x4f, 0x56, 0x20}, {0x42, 0x52, 0x42, 0x20}, {0x42, 0x52, 0x43, 0x20}, {0x42, 0x52, 0x45, 0x20}, {0x42, 0x52, 0x4c, 0x20}, {0x42, 0x52, 0x4e, 0x20}, {0x42, 0x52, 0x52, 0x20}, {0x42, 0x52, 0x5a, 0x20}, {0x42, 0x53, 0x44, 0x20}, {0x42, 0x54, 0x4e, 0x20}, {0x42, 0x55, 0x4b, 0x20}, {0x42, 0x57, 0x50, 0x20}, {0x42, 0x59, 0x42, 0x20}, {0x42, 0x59, 0x52, 0x20}, {0x42, 0x5a, 0x44, 0x20}, {0x43, 0x41, 0x44, 0x20}, {0x43, 0x44, 0x46, 0x20}, {0x43, 0x48, 0x45, 0x20}, {0x43, 0x48, 0x46, 0x20}, {0x43, 0x48, 0x57, 0x20}, {0x43, 0x4c, 0x45, 0x20}, {0x43, 0x4c, 0x46, 0x20}, {0x43, 0x4c, 0x50, 0x20}, {0x43, 0x4e, 0x58, 0x20}, {0x43, 0x4e, 0x59, 0x20}, {0x43, 0x4f, 0x50, 0x20}, {0x43, 0x4f, 0x55, 0x20}, {0x43, 0x52, 0x43, 0x20}, {0x43, 0x53, 0x44, 0x20}, {0x43, 0x53, 0x4b, 0x20}, {0x43, 0x55, 0x43, 0x20}, {0x43, 0x55, 0x50, 0x20}, {0x43, 0x56, 0x45, 0x20}, {0x43, 0x59, 0x50, 0x20}, {0x43, 0x5a, 0x4b, 0x20}, {0x44, 0x44, 0x4d, 0x20}, {0x44, 0x45, 0x4d, 0x20}, {0x44, 0x4a, 0x46, 0x20}, {0x44, 0x4b, 0x4b, 0x20}, {0x44, 0x4f, 0x50, 0x20}, {0x44, 0x5a, 0x44, 0x20}, {0x45, 0x43, 0x53, 0x20}, {0x45, 0x43, 0x56, 0x20}, {0x45, 0x45, 0x4b, 0x20}, {0x45, 0x47, 0x50, 0x20}, {0x45, 0x52, 0x4e, 0x20}, {0x45, 0x53, 0x41, 0x20}, {0x45, 0x53, 0x42, 0x20}, {0x45, 0x53, 0x50, 0x20}, {0x45, 0x54, 0x42, 0x20}, {0x45, 0x55, 0x52, 0x20}, {0x46, 0x49, 0x4d, 0x20}, {0x46, 0x4a, 0x44, 0x20}, {0x46, 0x4b, 0x50, 0x20}, {0x46, 0x52, 0x46, 0x20}, {0x47, 0x42, 0x50, 0x20}, {0x47, 0x45, 0x4b, 0x20}, {0x47, 0x45, 0x4c, 0x20}, {0x47, 0x48, 0x43, 0x20}, {0x47, 0x48, 0x53, 0x20}, {0x47, 0x49, 0x50, 0x20}, {0x47, 0x4d, 0x44, 0x20}, {0x47, 0x4e, 0x46, 0x20}, {0x47, 0x4e, 0x53, 0x20}, {0x47, 0x51, 0x45, 0x20}, {0x47, 0x52, 0x44, 0x20}, {0x47, 0x54, 0x51, 0x20}, {0x47, 0x57, 0x45, 0x20}, {0x47, 0x57, 0x50, 0x20}, {0x47, 0x59, 0x44, 0x20}, {0x48, 0x4b, 0x44, 0x20}, {0x48, 0x4e, 0x4c, 0x20}, {0x48, 0x52, 0x44, 0x20}, {0x48, 0x52, 0x4b, 0x20}, {0x48, 0x54, 0x47, 0x20}, {0x48, 0x55, 0x46, 0x20}, {0x49, 0x44, 0x52, 0x20}, {0x49, 0x45, 0x50, 0x20}, {0x49, 0x4c, 0x50, 0x20}, {0x49, 0x4c, 0x52, 0x20}, {0x49, 0x4c, 0x53, 0x20}, {0x49, 0x4e, 0x52, 0x20}, {0x49, 0x51, 0x44, 0x20}, {0x49, 0x52, 0x52, 0x20}, {0x49, 0x53, 0x4a, 0x20}, {0x49, 0x53, 0x4b, 0x20}, {0x49, 0x54, 0x4c, 0x20}, {0x4a, 0x4d, 0x44, 0x20}, {0x4a, 0x4f, 0x44, 0x20}, {0x4a, 0x50, 0x59, 0x20}, {0x4b, 0x45, 0x53, 0x20}, {0x4b, 0x47, 0x53, 0x20}, {0x4b, 0x48, 0x52, 0x20}, {0x4b, 0x4d, 0x46, 0x20}, {0x4b, 0x50, 0x57, 0x20}, {0x4b, 0x52, 0x48, 0x20}, {0x4b, 0x52, 0x4f, 0x20}, {0x4b, 0x52, 0x57, 0x20}, {0x4b, 0x57, 0x44, 0x20}, {0x4b, 0x59, 0x44, 0x20}, {0x4b, 0x5a, 0x54, 0x20}, {0x4c, 0x41, 0x4b, 0x20}, {0x4c, 0x42, 0x50, 0x20}, {0x4c, 0x4b, 0x52, 0x20}, {0x4c, 0x52, 0x44, 0x20}, {0x4c, 0x53, 0x4c, 0x20}, {0x4c, 0x54, 0x4c, 0x20}, {0x4c, 0x54, 0x54, 0x20}, {0x4c, 0x55, 0x43, 0x20}, {0x4c, 0x55, 0x46, 0x20}, {0x4c, 0x55, 0x4c, 0x20}, {0x4c, 0x56, 0x4c, 0x20}, {0x4c, 0x56, 0x52, 0x20}, {0x4c, 0x59, 0x44, 0x20}, {0x4d, 0x41, 0x44, 0x20}, {0x4d, 0x41, 0x46, 0x20}, {0x4d, 0x43, 0x46, 0x20}, {0x4d, 0x44, 0x43, 0x20}, {0x4d, 0x44, 0x4c, 0x20}, {0x4d, 0x47, 0x41, 0x20}, {0x4d, 0x47, 0x46, 0x20}, {0x4d, 0x4b, 0x44, 0x20}, {0x4d, 0x4b, 0x4e, 0x20}, {0x4d, 0x4c, 0x46, 0x20}, {0x4d, 0x4d, 0x4b, 0x20}, {0x4d, 0x4e, 0x54, 0x20}, {0x4d, 0x4f, 0x50, 0x20}, {0x4d, 0x52, 0x4f, 0x20}, {0x4d, 0x54, 0x4c, 0x20}, {0x4d, 0x54, 0x50, 0x20}, {0x4d, 0x55, 0x52, 0x20}, {0x4d, 0x56, 0x50, 0x20}, {0x4d, 0x56, 0x52, 0x20}, {0x4d, 0x57, 0x4b, 0x20}, {0x4d, 0x58, 0x4e, 0x20}, {0x4d, 0x58, 0x50, 0x20}, {0x4d, 0x58, 0x56, 0x20}, {0x4d, 0x59, 0x52, 0x20}, {0x4d, 0x5a, 0x45, 0x20}, {0x4d, 0x5a, 0x4d, 0x20}, {0x4d, 0x5a, 0x4e, 0x20}, {0x4e, 0x41, 0x44, 0x20}, {0x4e, 0x47, 0x4e, 0x20}, {0x4e, 0x49, 0x43, 0x20}, {0x4e, 0x49, 0x4f, 0x20}, {0x4e, 0x4c, 0x47, 0x20}, {0x4e, 0x4f, 0x4b, 0x20}, {0x4e, 0x50, 0x52, 0x20}, {0x4e, 0x5a, 0x44, 0x20}, {0x4f, 0x4d, 0x52, 0x20}, {0x50, 0x41, 0x42, 0x20}, {0x50, 0x45, 0x49, 0x20}, {0x50, 0x45, 0x4e, 0x20}, {0x50, 0x45, 0x53, 0x20}, {0x50, 0x47, 0x4b, 0x20}, {0x50, 0x48, 0x50, 0x20}, {0x50, 0x4b, 0x52, 0x20}, {0x50, 0x4c, 0x4e, 0x20}, {0x50, 0x4c, 0x5a, 0x20}, {0x50, 0x54, 0x45, 0x20}, {0x50, 0x59, 0x47, 0x20}, {0x51, 0x41, 0x52, 0x20}, {0x52, 0x48, 0x44, 0x20}, {0x52, 0x4f, 0x4c, 0x20}, {0x52, 0x4f, 0x4e, 0x20}, {0x52, 0x53, 0x44, 0x20}, {0x52, 0x55, 0x42, 0x20}, {0x52, 0x55, 0x52, 0x20}, {0x52, 0x57, 0x46, 0x20}, {0x53, 0x41, 0x52, 0x20}, {0x53, 0x42, 0x44, 0x20}, {0x53, 0x43, 0x52, 0x20}, {0x53, 0x44, 0x44, 0x20}, {0x53, 0x44, 0x47, 0x20}, {0x53, 0x44, 0x50, 0x20}, {0x53, 0x45, 0x4b, 0x20}, {0x53, 0x47, 0x44, 0x20}, {0x53, 0x48, 0x50, 0x20}, {0x53, 0x49, 0x54, 0x20}, {0x53, 0x4b, 0x4b, 0x20}, {0x53, 0x4c, 0x4c, 0x20}, {0x53, 0x4f, 0x53, 0x20}, {0x53, 0x52, 0x44, 0x20}, {0x53, 0x52, 0x47, 0x20}, {0x53, 0x53, 0x50, 0x20}, {0x53, 0x54, 0x44, 0x20}, {0x53, 0x55, 0x52, 0x20}, {0x53, 0x56, 0x43, 0x20}, {0x53, 0x59, 0x50, 0x20}, {0x53, 0x5a, 0x4c, 0x20}, {0x54, 0x48, 0x42, 0x20}, {0x54, 0x4a, 0x52, 0x20}, {0x54, 0x4a, 0x53, 0x20}, {0x54, 0x4d, 0x4d, 0x20}, {0x54, 0x4d, 0x54, 0x20}, {0x54, 0x4e, 0x44, 0x20}, {0x54, 0x4f, 0x50, 0x20}, {0x54, 0x50, 0x45, 0x20}, {0x54, 0x52, 0x4c, 0x20}, {0x54, 0x52, 0x59, 0x20}, {0x54, 0x54, 0x44, 0x20}, {0x54, 0x57, 0x44, 0x20}, {0x54, 0x5a, 0x53, 0x20}, {0x55, 0x41, 0x48, 0x20}, {0x55, 0x41, 0x4b, 0x20}, {0x55, 0x47, 0x53, 0x20}, {0x55, 0x47, 0x58, 0x20}, {0x55, 0x53, 0x44, 0x20}, {0x55, 0x53, 0x4e, 0x20}, {0x55, 0x53, 0x53, 0x20}, {0x55, 0x59, 0x49, 0x20}, {0x55, 0x59, 0x50, 0x20}, {0x55, 0x59, 0x55, 0x20}, {0x55, 0x5a, 0x53, 0x20}, {0x56, 0x45, 0x42, 0x20}, {0x56, 0x45, 0x46, 0x20}, {0x56, 0x4e, 0x44, 0x20}, {0x56, 0x4e, 0x4e, 0x20}, {0x56, 0x55, 0x56, 0x20}, {0x57, 0x53, 0x54, 0x20}, {0x58, 0x41, 0x46, 0x20}, {0x58, 0x41, 0x47, 0x20}, {0x58, 0x41, 0x55, 0x20}, {0x58, 0x42, 0x41, 0x20}, {0x58, 0x42, 0x42, 0x20}, {0x58, 0x42, 0x43, 0x20}, {0x58, 0x42, 0x44, 0x20}, {0x58, 0x43, 0x44, 0x20}, {0x58, 0x44, 0x52, 0x20}, {0x58, 0x45, 0x55, 0x20}, {0x58, 0x46, 0x4f, 0x20}, {0x58, 0x46, 0x55, 0x20}, {0x58, 0x4f, 0x46, 0x20}, {0x58, 0x50, 0x44, 0x20}, {0x58, 0x50, 0x46, 0x20}, {0x58, 0x50, 0x54, 0x20}, {0x58, 0x52, 0x45, 0x20}, {0x58, 0x53, 0x55, 0x20}, {0x58, 0x54, 0x53, 0x20}, {0x58, 0x55, 0x41, 0x20}, {0x58, 0x58, 0x58, 0x20}, {0x59, 0x44, 0x44, 0x20}, {0x59, 0x45, 0x52, 0x20}, {0x59, 0x55, 0x44, 0x20}, {0x59, 0x55, 0x4d, 0x20}, {0x59, 0x55, 0x4e, 0x20}, {0x59, 0x55, 0x52, 0x20}, {0x5a, 0x41, 0x4c, 0x20}, {0x5a, 0x41, 0x52, 0x20}, {0x5a, 0x4d, 0x4b, 0x20}, {0x5a, 0x4d, 0x57, 0x20}, {0x5a, 0x52, 0x4e, 0x20}, {0x5a, 0x52, 0x5a, 0x20}, {0x5a, 0x57, 0x44, 0x20}, {0x5a, 0x57, 0x4c, 0x20}, {0x5a, 0x57, 0x52, 0x20}},
  54. currencyPositiveSuffix: []byte{0xc2, 0xa0},
  55. currencyNegativeSuffix: []byte{0xc2, 0xa0},
  56. monthsWide: [][]uint8{[]uint8(nil), {0xd8, 0xac, 0xd9, 0x86, 0xd9, 0x88, 0xd8, 0xb1, 0xd9, 0x8a}, {0xd9, 0x81, 0xd8, 0xa8, 0xd8, 0xb1, 0xd9, 0x88, 0xd8, 0xb1, 0xd9, 0x8a}, {0xd9, 0x85, 0xd8, 0xa7, 0xd8, 0xb1, 0xda, 0x86}, {0xd8, 0xa7, 0xd9, 0xbe, 0xd8, 0xb1, 0xdb, 0x8c, 0xd9, 0x84}, {0xd9, 0x85, 0xdb, 0x8c}, {0xd8, 0xac, 0xd9, 0x88, 0xd9, 0x86}, {0xd8, 0xac, 0xd9, 0x88, 0xd9, 0x84, 0xd8, 0xa7, 0xdb, 0x8c}, {0xd8, 0xa7, 0xda, 0xab, 0xd8, 0xb3, 0xd8, 0xaa}, {0xd8, 0xb3, 0xd9, 0xbe, 0xd8, 0xaa, 0xd9, 0x85, 0xd8, 0xa8, 0xd8, 0xb1}, {0xd8, 0xa7, 0xda, 0xa9, 0xd8, 0xaa, 0xd9, 0x88, 0xd8, 0xa8, 0xd8, 0xb1}, {0xd9, 0x86, 0xd9, 0x88, 0xd9, 0x85, 0xd8, 0xa8, 0xd8, 0xb1}, {0xd8, 0xaf, 0xd8, 0xb3, 0xd9, 0x85, 0xd8, 0xa8, 0xd8, 0xb1}},
  57. daysWide: [][]uint8{{0xdb, 0x8c, 0xda, 0xa9, 0xd8, 0xb4, 0xd9, 0x86, 0xd8, 0xa8, 0xd9, 0x87}, {0xd8, 0xaf, 0xd9, 0x88, 0xd8, 0xb4, 0xd9, 0x86, 0xd8, 0xa8, 0xd9, 0x87}, {0xd8, 0xb3, 0xd9, 0x87, 0xe2, 0x80, 0x8c, 0xd8, 0xb4, 0xd9, 0x86, 0xd8, 0xa8, 0xd9, 0x87}, {0xda, 0x86, 0xd9, 0x87, 0xd8, 0xa7, 0xd8, 0xb1, 0xd8, 0xb4, 0xd9, 0x86, 0xd8, 0xa8, 0xd9, 0x87}, {0xd9, 0xbe, 0xd9, 0x86, 0xd8, 0xac, 0xd8, 0xb4, 0xd9, 0x86, 0xd8, 0xa8, 0xd9, 0x87}, {0xd8, 0xac, 0xd9, 0x85, 0xd8, 0xb9, 0xd9, 0x87}, {0xd8, 0xb4, 0xd9, 0x86, 0xd8, 0xa8, 0xd9, 0x87}},
  58. periodsAbbreviated: [][]uint8{{0xd8, 0xba, 0x2e, 0xd9, 0x85, 0x2e}, {0xd8, 0xba, 0x2e, 0xd9, 0x88, 0x2e}},
  59. periodsWide: [][]uint8{{0xd8, 0xba, 0x2e, 0xd9, 0x85, 0x2e}, {0xd8, 0xba, 0x2e, 0xd9, 0x88, 0x2e}},
  60. erasAbbreviated: [][]uint8{{0xd9, 0x82, 0x2e, 0xd9, 0x85, 0x2e}, {0xd9, 0x85, 0x2e}},
  61. erasNarrow: [][]uint8{[]uint8(nil), []uint8(nil)},
  62. erasWide: [][]uint8{[]uint8(nil), []uint8(nil)},
  63. timezones: map[string][]uint8{"GYT": {0x47, 0x59, 0x54}, "OEZ": {0x4f, 0x45, 0x5a}, "AKDT": {0x41, 0x4b, 0x44, 0x54}, "MYT": {0x4d, 0x59, 0x54}, "∅∅∅": {0xe2, 0x88, 0x85, 0xe2, 0x88, 0x85, 0xe2, 0x88, 0x85}, "WIT": {0x57, 0x49, 0x54}, "ACWST": {0x41, 0x43, 0x57, 0x53, 0x54}, "CLT": {0x43, 0x4c, 0x54}, "HAT": {0x48, 0x41, 0x54}, "ACWDT": {0x41, 0x43, 0x57, 0x44, 0x54}, "TMT": {0x54, 0x4d, 0x54}, "EAT": {0x45, 0x41, 0x54}, "GMT": {0xda, 0xaf, 0xd8, 0xb1, 0xd9, 0x8a, 0xd9, 0x86, 0xd9, 0x88, 0xd9, 0x8a, 0xda, 0x86, 0x20, 0xd9, 0x88, 0xd8, 0xae, 0xd8, 0xaa}, "UYST": {0x55, 0x59, 0x53, 0x54}, "ACDT": {0x41, 0x43, 0x44, 0x54}, "NZST": {0x4e, 0x5a, 0x53, 0x54}, "LHST": {0x4c, 0x48, 0x53, 0x54}, "AEDT": {0x41, 0x45, 0x44, 0x54}, "BT": {0x42, 0x54}, "CDT": {0x43, 0x44, 0x54}, "ADT": {0x41, 0x44, 0x54}, "CLST": {0x43, 0x4c, 0x53, 0x54}, "TMST": {0x54, 0x4d, 0x53, 0x54}, "UYT": {0x55, 0x59, 0x54}, "HKST": {0x48, 0x4b, 0x53, 0x54}, "CAT": {0x43, 0x41, 0x54}, "MEZ": {0x4d, 0x45, 0x5a}, "MESZ": {0x4d, 0x45, 0x53, 0x5a}, "HADT": {0x48, 0x41, 0x44, 0x54}, "WIB": {0x57, 0x49, 0x42}, "PDT": {0x50, 0x44, 0x54}, "WAT": {0x57, 0x41, 0x54}, "AWDT": {0x41, 0x57, 0x44, 0x54}, "VET": {0x56, 0x45, 0x54}, "IST": {0x49, 0x53, 0x54}, "AEST": {0x41, 0x45, 0x53, 0x54}, "COST": {0x43, 0x4f, 0x53, 0x54}, "MDT": {0x4d, 0x44, 0x54}, "ARST": {0x41, 0x52, 0x53, 0x54}, "LHDT": {0x4c, 0x48, 0x44, 0x54}, "ChST": {0x43, 0x68, 0x53, 0x54}, "ECT": {0x45, 0x43, 0x54}, "SAST": {0x53, 0x41, 0x53, 0x54}, "BOT": {0x42, 0x4f, 0x54}, "AST": {0x41, 0x53, 0x54}, "HKT": {0x48, 0x4b, 0x54}, "SRT": {0x53, 0x52, 0x54}, "AWST": {0x41, 0x57, 0x53, 0x54}, "COT": {0x43, 0x4f, 0x54}, "ACST": {0x41, 0x43, 0x53, 0x54}, "WITA": {0x57, 0x49, 0x54, 0x41}, "CST": {0x43, 0x53, 0x54}, "EST": {0x45, 0x53, 0x54}, "JST": {0x4a, 0x53, 0x54}, "EDT": {0x45, 0x44, 0x54}, "NZDT": {0x4e, 0x5a, 0x44, 0x54}, "WARST": {0x57, 0x41, 0x52, 0x53, 0x54}, "HAST": {0x48, 0x41, 0x53, 0x54}, "MST": {0x4d, 0x53, 0x54}, "PST": {0x50, 0x53, 0x54}, "ART": {0x41, 0x52, 0x54}, "GFT": {0x47, 0x46, 0x54}, "WAST": {0x57, 0x41, 0x53, 0x54}, "JDT": {0x4a, 0x44, 0x54}, "WEZ": {0xe2, 0x88, 0x85, 0xe2, 0x88, 0x85, 0xe2, 0x88, 0x85}, "WESZ": {0xe2, 0x88, 0x85, 0xe2, 0x88, 0x85, 0xe2, 0x88, 0x85}, "CHADT": {0x43, 0x48, 0x41, 0x44, 0x54}, "OESZ": {0x4f, 0x45, 0x53, 0x5a}, "SGT": {0x53, 0x47, 0x54}, "WART": {0x57, 0x41, 0x52, 0x54}, "CHAST": {0x43, 0x48, 0x41, 0x53, 0x54}, "AKST": {0x41, 0x4b, 0x53, 0x54}, "HNT": {0x48, 0x4e, 0x54}},
  64. }
  65. }
  66. // Locale returns the current translators string locale
  67. func (ps *ps) Locale() string {
  68. return ps.locale
  69. }
  70. // PluralsCardinal returns the list of cardinal plural rules associated with 'ps'
  71. func (ps *ps) PluralsCardinal() []locales.PluralRule {
  72. return ps.pluralsCardinal
  73. }
  74. // PluralsOrdinal returns the list of ordinal plural rules associated with 'ps'
  75. func (ps *ps) PluralsOrdinal() []locales.PluralRule {
  76. return ps.pluralsOrdinal
  77. }
  78. // PluralsRange returns the list of range plural rules associated with 'ps'
  79. func (ps *ps) PluralsRange() []locales.PluralRule {
  80. return ps.pluralsRange
  81. }
  82. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'ps'
  83. func (ps *ps) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  84. n := math.Abs(num)
  85. if n == 1 {
  86. return locales.PluralRuleOne
  87. }
  88. return locales.PluralRuleOther
  89. }
  90. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'ps'
  91. func (ps *ps) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  92. return locales.PluralRuleUnknown
  93. }
  94. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'ps'
  95. func (ps *ps) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  96. return locales.PluralRuleUnknown
  97. }
  98. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  99. func (ps *ps) MonthAbbreviated(month time.Month) []byte {
  100. return ps.monthsAbbreviated[month]
  101. }
  102. // MonthsAbbreviated returns the locales abbreviated months
  103. func (ps *ps) MonthsAbbreviated() [][]byte {
  104. return ps.monthsAbbreviated[1:]
  105. }
  106. // MonthNarrow returns the locales narrow month given the 'month' provided
  107. func (ps *ps) MonthNarrow(month time.Month) []byte {
  108. return ps.monthsNarrow[month]
  109. }
  110. // MonthsNarrow returns the locales narrow months
  111. func (ps *ps) MonthsNarrow() [][]byte {
  112. return ps.monthsNarrow[1:]
  113. }
  114. // MonthWide returns the locales wide month given the 'month' provided
  115. func (ps *ps) MonthWide(month time.Month) []byte {
  116. return ps.monthsWide[month]
  117. }
  118. // MonthsWide returns the locales wide months
  119. func (ps *ps) MonthsWide() [][]byte {
  120. return ps.monthsWide[1:]
  121. }
  122. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  123. func (ps *ps) WeekdayAbbreviated(weekday time.Weekday) []byte {
  124. return ps.daysAbbreviated[weekday]
  125. }
  126. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  127. func (ps *ps) WeekdaysAbbreviated() [][]byte {
  128. return ps.daysAbbreviated
  129. }
  130. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  131. func (ps *ps) WeekdayNarrow(weekday time.Weekday) []byte {
  132. return ps.daysNarrow[weekday]
  133. }
  134. // WeekdaysNarrow returns the locales narrow weekdays
  135. func (ps *ps) WeekdaysNarrow() [][]byte {
  136. return ps.daysNarrow
  137. }
  138. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  139. func (ps *ps) WeekdayShort(weekday time.Weekday) []byte {
  140. return ps.daysShort[weekday]
  141. }
  142. // WeekdaysShort returns the locales short weekdays
  143. func (ps *ps) WeekdaysShort() [][]byte {
  144. return ps.daysShort
  145. }
  146. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  147. func (ps *ps) WeekdayWide(weekday time.Weekday) []byte {
  148. return ps.daysWide[weekday]
  149. }
  150. // WeekdaysWide returns the locales wide weekdays
  151. func (ps *ps) WeekdaysWide() [][]byte {
  152. return ps.daysWide
  153. }
  154. // FmtNumber returns 'num' with digits/precision of 'v' for 'ps' and handles both Whole and Real numbers based on 'v'
  155. // returned as a []byte just in case the caller wishes to add more and can help
  156. // avoid allocations; otherwise just cast as string.
  157. func (ps *ps) FmtNumber(num float64, v uint64) []byte {
  158. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  159. return []byte(s)
  160. }
  161. // FmtPercent returns 'num' with digits/precision of 'v' for 'ps' and handles both Whole and Real numbers based on 'v'
  162. // returned as a []byte just in case the caller wishes to add more and can help
  163. // avoid allocations; otherwise just cast as string.
  164. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  165. func (ps *ps) FmtPercent(num float64, v uint64) []byte {
  166. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  167. return []byte(s)
  168. }
  169. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'ps'
  170. // returned as a []byte just in case the caller wishes to add more and can help
  171. // avoid allocations; otherwise just cast as string.
  172. func (ps *ps) FmtCurrency(num float64, v uint64, currency currency.Type) []byte {
  173. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  174. symbol := ps.currencies[currency]
  175. l := len(s) + len(ps.decimal) + len(ps.group)*len(s[:len(s)-int(v)-1])/3
  176. count := 0
  177. inWhole := v == 0
  178. b := make([]byte, 0, l)
  179. for i := len(s) - 1; i >= 0; i-- {
  180. if s[i] == '.' {
  181. for j := len(ps.decimal) - 1; j >= 0; j-- {
  182. b = append(b, ps.decimal[j])
  183. }
  184. inWhole = true
  185. continue
  186. }
  187. if inWhole {
  188. if count == 3 {
  189. for j := len(ps.group) - 1; j >= 0; j-- {
  190. b = append(b, ps.group[j])
  191. }
  192. count = 1
  193. } else {
  194. count++
  195. }
  196. }
  197. b = append(b, s[i])
  198. }
  199. if num < 0 {
  200. for j := len(ps.minus) - 1; j >= 0; j-- {
  201. b = append(b, ps.minus[j])
  202. }
  203. }
  204. // reverse
  205. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  206. b[i], b[j] = b[j], b[i]
  207. }
  208. if int(v) < 2 {
  209. if v == 0 {
  210. b = append(b, ps.decimal...)
  211. }
  212. for i := 0; i < 2-int(v); i++ {
  213. b = append(b, '0')
  214. }
  215. }
  216. b = append(b, ps.currencyPositiveSuffix...)
  217. b = append(b, symbol...)
  218. return b
  219. }
  220. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'ps'
  221. // in accounting notation. returned as a []byte just in case the caller wishes to add more and can help
  222. // avoid allocations; otherwise just cast as string.
  223. func (ps *ps) FmtAccounting(num float64, v uint64, currency currency.Type) []byte {
  224. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  225. symbol := ps.currencies[currency]
  226. l := len(s) + len(ps.decimal) + len(ps.group)*len(s[:len(s)-int(v)-1])/3
  227. count := 0
  228. inWhole := v == 0
  229. b := make([]byte, 0, l)
  230. for i := len(s) - 1; i >= 0; i-- {
  231. if s[i] == '.' {
  232. for j := len(ps.decimal) - 1; j >= 0; j-- {
  233. b = append(b, ps.decimal[j])
  234. }
  235. inWhole = true
  236. continue
  237. }
  238. if inWhole {
  239. if count == 3 {
  240. for j := len(ps.group) - 1; j >= 0; j-- {
  241. b = append(b, ps.group[j])
  242. }
  243. count = 1
  244. } else {
  245. count++
  246. }
  247. }
  248. b = append(b, s[i])
  249. }
  250. if num < 0 {
  251. for j := len(ps.minus) - 1; j >= 0; j-- {
  252. b = append(b, ps.minus[j])
  253. }
  254. }
  255. // reverse
  256. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  257. b[i], b[j] = b[j], b[i]
  258. }
  259. if int(v) < 2 {
  260. if v == 0 {
  261. b = append(b, ps.decimal...)
  262. }
  263. for i := 0; i < 2-int(v); i++ {
  264. b = append(b, '0')
  265. }
  266. }
  267. if num < 0 {
  268. b = append(b, ps.currencyNegativeSuffix...)
  269. b = append(b, symbol...)
  270. } else {
  271. b = append(b, ps.currencyPositiveSuffix...)
  272. b = append(b, symbol...)
  273. }
  274. return b
  275. }
  276. // FmtDateShort returns the short date representation of 't' for 'ps'
  277. // returned as a []byte just in case the caller wishes to add more and can help
  278. // avoid allocations; otherwise just cast as string.
  279. func (ps *ps) FmtDateShort(t time.Time) []byte {
  280. b := make([]byte, 0, 32)
  281. b = strconv.AppendInt(b, int64(t.Year()), 10)
  282. b = append(b, []byte{0x2f}...)
  283. b = strconv.AppendInt(b, int64(t.Month()), 10)
  284. b = append(b, []byte{0x2f}...)
  285. b = strconv.AppendInt(b, int64(t.Day()), 10)
  286. return b
  287. }
  288. // FmtDateMedium returns the medium date representation of 't' for 'ps'
  289. // returned as a []byte just in case the caller wishes to add more and can help
  290. // avoid allocations; otherwise just cast as string.
  291. func (ps *ps) FmtDateMedium(t time.Time) []byte {
  292. b := make([]byte, 0, 32)
  293. b = strconv.AppendInt(b, int64(t.Day()), 10)
  294. b = append(b, []byte{0x20}...)
  295. b = append(b, ps.monthsAbbreviated[t.Month()]...)
  296. b = append(b, []byte{0x20}...)
  297. b = strconv.AppendInt(b, int64(t.Year()), 10)
  298. return b
  299. }
  300. // FmtDateLong returns the long date representation of 't' for 'ps'
  301. // returned as a []byte just in case the caller wishes to add more and can help
  302. // avoid allocations; otherwise just cast as string.
  303. func (ps *ps) FmtDateLong(t time.Time) []byte {
  304. b := make([]byte, 0, 32)
  305. b = append(b, []byte{0xd8, 0xaf, 0x20}...)
  306. b = strconv.AppendInt(b, int64(t.Year()), 10)
  307. b = append(b, []byte{0x20, 0xd8, 0xaf, 0x20}...)
  308. b = append(b, ps.monthsWide[t.Month()]...)
  309. b = append(b, []byte{0x20}...)
  310. b = strconv.AppendInt(b, int64(t.Day()), 10)
  311. return b
  312. }
  313. // FmtDateFull returns the full date representation of 't' for 'ps'
  314. // returned as a []byte just in case the caller wishes to add more and can help
  315. // avoid allocations; otherwise just cast as string.
  316. func (ps *ps) FmtDateFull(t time.Time) []byte {
  317. b := make([]byte, 0, 32)
  318. b = append(b, ps.daysWide[t.Weekday()]...)
  319. b = append(b, []byte{0x20, 0xd8, 0xaf, 0x20}...)
  320. b = strconv.AppendInt(b, int64(t.Year()), 10)
  321. b = append(b, []byte{0x20, 0xd8, 0xaf, 0x20}...)
  322. b = append(b, ps.monthsWide[t.Month()]...)
  323. b = append(b, []byte{0x20}...)
  324. b = strconv.AppendInt(b, int64(t.Day()), 10)
  325. return b
  326. }
  327. // FmtTimeShort returns the short time representation of 't' for 'ps'
  328. // returned as a []byte just in case the caller wishes to add more and can help
  329. // avoid allocations; otherwise just cast as string.
  330. func (ps *ps) FmtTimeShort(t time.Time) []byte {
  331. b := make([]byte, 0, 32)
  332. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  333. b = append(b, ps.timeSeparator...)
  334. if t.Minute() < 10 {
  335. b = append(b, '0')
  336. }
  337. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  338. return b
  339. }
  340. // FmtTimeMedium returns the medium time representation of 't' for 'ps'
  341. // returned as a []byte just in case the caller wishes to add more and can help
  342. // avoid allocations; otherwise just cast as string.
  343. func (ps *ps) FmtTimeMedium(t time.Time) []byte {
  344. b := make([]byte, 0, 32)
  345. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  346. b = append(b, ps.timeSeparator...)
  347. if t.Minute() < 10 {
  348. b = append(b, '0')
  349. }
  350. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  351. b = append(b, ps.timeSeparator...)
  352. if t.Second() < 10 {
  353. b = append(b, '0')
  354. }
  355. b = strconv.AppendInt(b, int64(t.Second()), 10)
  356. return b
  357. }
  358. // FmtTimeLong returns the long time representation of 't' for 'ps'
  359. // returned as a []byte just in case the caller wishes to add more and can help
  360. // avoid allocations; otherwise just cast as string.
  361. func (ps *ps) FmtTimeLong(t time.Time) []byte {
  362. b := make([]byte, 0, 32)
  363. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  364. b = append(b, ps.timeSeparator...)
  365. if t.Minute() < 10 {
  366. b = append(b, '0')
  367. }
  368. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  369. b = append(b, ps.timeSeparator...)
  370. if t.Second() < 10 {
  371. b = append(b, '0')
  372. }
  373. b = strconv.AppendInt(b, int64(t.Second()), 10)
  374. b = append(b, []byte{0x20, 0x28}...)
  375. tz, _ := t.Zone()
  376. b = append(b, tz...)
  377. b = append(b, []byte{0x29}...)
  378. return b
  379. }
  380. // FmtTimeFull returns the full time representation of 't' for 'ps'
  381. // returned as a []byte just in case the caller wishes to add more and can help
  382. // avoid allocations; otherwise just cast as string.
  383. func (ps *ps) FmtTimeFull(t time.Time) []byte {
  384. b := make([]byte, 0, 32)
  385. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  386. b = append(b, ps.timeSeparator...)
  387. if t.Minute() < 10 {
  388. b = append(b, '0')
  389. }
  390. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  391. b = append(b, ps.timeSeparator...)
  392. if t.Second() < 10 {
  393. b = append(b, '0')
  394. }
  395. b = strconv.AppendInt(b, int64(t.Second()), 10)
  396. b = append(b, []byte{0x20, 0x28}...)
  397. tz, _ := t.Zone()
  398. if btz, ok := ps.timezones[tz]; ok {
  399. b = append(b, btz...)
  400. } else {
  401. b = append(b, tz...)
  402. }
  403. b = append(b, []byte{0x29}...)
  404. return b
  405. }