bem.go 26 KB

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