rm.go 27 KB

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