mzn.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. package mzn
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type mzn struct {
  10. locale string
  11. pluralsCardinal []locales.PluralRule
  12. pluralsOrdinal []locales.PluralRule
  13. pluralsRange []locales.PluralRule
  14. decimal string
  15. group string
  16. minus string
  17. percent string
  18. perMille string
  19. timeSeparator string
  20. inifinity string
  21. currencies []string // idx = enum of currency code
  22. monthsAbbreviated []string
  23. monthsNarrow []string
  24. monthsWide []string
  25. daysAbbreviated []string
  26. daysNarrow []string
  27. daysShort []string
  28. daysWide []string
  29. periodsAbbreviated []string
  30. periodsNarrow []string
  31. periodsShort []string
  32. periodsWide []string
  33. erasAbbreviated []string
  34. erasNarrow []string
  35. erasWide []string
  36. timezones map[string]string
  37. }
  38. // New returns a new instance of translator for the 'mzn' locale
  39. func New() locales.Translator {
  40. return &mzn{
  41. locale: "mzn",
  42. pluralsCardinal: nil,
  43. pluralsOrdinal: nil,
  44. pluralsRange: nil,
  45. timeSeparator: ":",
  46. 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", "R$", "BRN", "BRR", "BRZ", "BSD", "BTN", "BUK", "BWP", "BYB", "BYN", "BYR", "BZD", "CA$", "CDF", "CHE", "CHF", "CHW", "CLE", "CLF", "CLP", "CNH", "CNX", "CN¥", "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", "€", "FIM", "FJD", "FKP", "FRF", "£", "GEK", "GEL", "GHC", "GHS", "GIP", "GMD", "GNF", "GNS", "GQE", "GRD", "GTQ", "GWE", "GWP", "GYD", "HK$", "HNL", "HRD", "HRK", "HTG", "HUF", "IDR", "IEP", "ILP", "ILR", "₪", "₹", "IQD", "IRR", "ISJ", "ISK", "ITL", "JMD", "JOD", "JP¥", "KES", "KGS", "KHR", "KMF", "KPW", "KRH", "KRO", "₩", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LTL", "LTT", "LUC", "LUF", "LUL", "LVL", "LVR", "LYD", "MAD", "MAF", "MCF", "MDC", "MDL", "MGA", "MGF", "MKD", "MKN", "MLF", "MMK", "MNT", "MOP", "MRO", "MTL", "MTP", "MUR", "MVP", "MVR", "MWK", "MX$", "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", "NT$", "TZS", "UAH", "UAK", "UGS", "UGX", "$", "USN", "USS", "UYI", "UYP", "UYU", "UZS", "VEB", "VEF", "₫", "VNN", "VUV", "WST", "FCFA", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "EC$", "XDR", "XEU", "XFO", "XFU", "CFA", "XPD", "XPF", "XPT", "XRE", "XSU", "XTS", "XUA", "XXX", "YDD", "YER", "YUD", "YUM", "YUN", "YUR", "ZAL", "ZAR", "ZMK", "ZMW", "ZRN", "ZRZ", "ZWD", "ZWL", "ZWR"},
  47. monthsAbbreviated: []string{"", "ژانویه", "فوریه", "مارس", "آوریل", "مه", "ژوئن", "ژوئیه", "اوت", "سپتامبر", "اکتبر", "نوامبر", "دسامبر"},
  48. monthsWide: []string{"", "ژانویه", "فوریه", "مارس", "آوریل", "مه", "ژوئن", "ژوئیه", "اوت", "سپتامبر", "اکتبر", "نوامبر", "دسامبر"},
  49. erasAbbreviated: []string{"پ.م", "م."},
  50. erasNarrow: []string{"", ""},
  51. erasWide: []string{"قبل میلاد", "بعد میلاد"},
  52. timezones: map[string]string{"JDT": "JDT", "NZDT": "NZDT", "HEPM": "HEPM", "HNCU": "HNCU", "AST": "AST", "SAST": "SAST", "HEEG": "HEEG", "ACST": "ACST", "HNPM": "HNPM", "BOT": "BOT", "JST": "JST", "AKDT": "AKDT", "ACWST": "ACWST", "CHADT": "CHADT", "MST": "MST", "WESZ": "WESZ", "EDT": "EDT", "WART": "WART", "COST": "COST", "HEPMX": "HEPMX", "EST": "EST", "CAT": "CAT", "HAST": "HAST", "HADT": "HADT", "AWST": "AWST", "HKT": "HKT", "WARST": "WARST", "TMST": "TMST", "CHAST": "CHAST", "SGT": "SGT", "MESZ": "MESZ", "CST": "CST", "IST": "IST", "UYST": "UYST", "AEDT": "AEDT", "WAT": "WAT", "LHST": "LHST", "HNT": "HNT", "COT": "COT", "∅∅∅": "∅∅∅", "ART": "ART", "WEZ": "WEZ", "MYT": "MYT", "HNOG": "HNOG", "HEOG": "HEOG", "TMT": "TMT", "UYT": "UYT", "ChST": "ChST", "PDT": "PDT", "MEZ": "MEZ", "HAT": "HAT", "VET": "VET", "WIT": "WIT", "AEST": "AEST", "HNEG": "HNEG", "ACDT": "ACDT", "WITA": "WITA", "HENOMX": "HENOMX", "ARST": "ARST", "GMT": "GMT", "GFT": "GFT", "WIB": "WIB", "WAST": "WAST", "NZST": "NZST", "HNNOMX": "HNNOMX", "GYT": "GYT", "PST": "PST", "MDT": "MDT", "AKST": "AKST", "OESZ": "OESZ", "AWDT": "AWDT", "BT": "BT", "HKST": "HKST", "SRT": "SRT", "EAT": "EAT", "CLT": "CLT", "CLST": "CLST", "HECU": "HECU", "CDT": "CDT", "ACWDT": "ACWDT", "ECT": "ECT", "LHDT": "LHDT", "OEZ": "OEZ", "HNPMX": "HNPMX", "ADT": "ADT"},
  53. }
  54. }
  55. // Locale returns the current translators string locale
  56. func (mzn *mzn) Locale() string {
  57. return mzn.locale
  58. }
  59. // PluralsCardinal returns the list of cardinal plural rules associated with 'mzn'
  60. func (mzn *mzn) PluralsCardinal() []locales.PluralRule {
  61. return mzn.pluralsCardinal
  62. }
  63. // PluralsOrdinal returns the list of ordinal plural rules associated with 'mzn'
  64. func (mzn *mzn) PluralsOrdinal() []locales.PluralRule {
  65. return mzn.pluralsOrdinal
  66. }
  67. // PluralsRange returns the list of range plural rules associated with 'mzn'
  68. func (mzn *mzn) PluralsRange() []locales.PluralRule {
  69. return mzn.pluralsRange
  70. }
  71. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'mzn'
  72. func (mzn *mzn) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  73. return locales.PluralRuleUnknown
  74. }
  75. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'mzn'
  76. func (mzn *mzn) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  77. return locales.PluralRuleUnknown
  78. }
  79. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'mzn'
  80. func (mzn *mzn) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  81. return locales.PluralRuleUnknown
  82. }
  83. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  84. func (mzn *mzn) MonthAbbreviated(month time.Month) string {
  85. return mzn.monthsAbbreviated[month]
  86. }
  87. // MonthsAbbreviated returns the locales abbreviated months
  88. func (mzn *mzn) MonthsAbbreviated() []string {
  89. return mzn.monthsAbbreviated[1:]
  90. }
  91. // MonthNarrow returns the locales narrow month given the 'month' provided
  92. func (mzn *mzn) MonthNarrow(month time.Month) string {
  93. return mzn.monthsNarrow[month]
  94. }
  95. // MonthsNarrow returns the locales narrow months
  96. func (mzn *mzn) MonthsNarrow() []string {
  97. return nil
  98. }
  99. // MonthWide returns the locales wide month given the 'month' provided
  100. func (mzn *mzn) MonthWide(month time.Month) string {
  101. return mzn.monthsWide[month]
  102. }
  103. // MonthsWide returns the locales wide months
  104. func (mzn *mzn) MonthsWide() []string {
  105. return mzn.monthsWide[1:]
  106. }
  107. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  108. func (mzn *mzn) WeekdayAbbreviated(weekday time.Weekday) string {
  109. return mzn.daysAbbreviated[weekday]
  110. }
  111. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  112. func (mzn *mzn) WeekdaysAbbreviated() []string {
  113. return mzn.daysAbbreviated
  114. }
  115. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  116. func (mzn *mzn) WeekdayNarrow(weekday time.Weekday) string {
  117. return mzn.daysNarrow[weekday]
  118. }
  119. // WeekdaysNarrow returns the locales narrow weekdays
  120. func (mzn *mzn) WeekdaysNarrow() []string {
  121. return mzn.daysNarrow
  122. }
  123. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  124. func (mzn *mzn) WeekdayShort(weekday time.Weekday) string {
  125. return mzn.daysShort[weekday]
  126. }
  127. // WeekdaysShort returns the locales short weekdays
  128. func (mzn *mzn) WeekdaysShort() []string {
  129. return mzn.daysShort
  130. }
  131. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  132. func (mzn *mzn) WeekdayWide(weekday time.Weekday) string {
  133. return mzn.daysWide[weekday]
  134. }
  135. // WeekdaysWide returns the locales wide weekdays
  136. func (mzn *mzn) WeekdaysWide() []string {
  137. return mzn.daysWide
  138. }
  139. // Decimal returns the decimal point of number
  140. func (mzn *mzn) Decimal() string {
  141. return mzn.decimal
  142. }
  143. // Group returns the group of number
  144. func (mzn *mzn) Group() string {
  145. return mzn.group
  146. }
  147. // Group returns the minus sign of number
  148. func (mzn *mzn) Minus() string {
  149. return mzn.minus
  150. }
  151. // FmtNumber returns 'num' with digits/precision of 'v' for 'mzn' and handles both Whole and Real numbers based on 'v'
  152. func (mzn *mzn) FmtNumber(num float64, v uint64) string {
  153. return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  154. }
  155. // FmtPercent returns 'num' with digits/precision of 'v' for 'mzn' and handles both Whole and Real numbers based on 'v'
  156. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  157. func (mzn *mzn) FmtPercent(num float64, v uint64) string {
  158. return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  159. }
  160. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'mzn'
  161. func (mzn *mzn) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  162. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  163. symbol := mzn.currencies[currency]
  164. return string(append(append([]byte{}, symbol...), s...))
  165. }
  166. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'mzn'
  167. // in accounting notation.
  168. func (mzn *mzn) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  169. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  170. symbol := mzn.currencies[currency]
  171. return string(append(append([]byte{}, symbol...), s...))
  172. }
  173. // FmtDateShort returns the short date representation of 't' for 'mzn'
  174. func (mzn *mzn) FmtDateShort(t time.Time) string {
  175. b := make([]byte, 0, 32)
  176. return string(b)
  177. }
  178. // FmtDateMedium returns the medium date representation of 't' for 'mzn'
  179. func (mzn *mzn) FmtDateMedium(t time.Time) string {
  180. b := make([]byte, 0, 32)
  181. return string(b)
  182. }
  183. // FmtDateLong returns the long date representation of 't' for 'mzn'
  184. func (mzn *mzn) FmtDateLong(t time.Time) string {
  185. b := make([]byte, 0, 32)
  186. return string(b)
  187. }
  188. // FmtDateFull returns the full date representation of 't' for 'mzn'
  189. func (mzn *mzn) FmtDateFull(t time.Time) string {
  190. b := make([]byte, 0, 32)
  191. return string(b)
  192. }
  193. // FmtTimeShort returns the short time representation of 't' for 'mzn'
  194. func (mzn *mzn) FmtTimeShort(t time.Time) string {
  195. b := make([]byte, 0, 32)
  196. return string(b)
  197. }
  198. // FmtTimeMedium returns the medium time representation of 't' for 'mzn'
  199. func (mzn *mzn) FmtTimeMedium(t time.Time) string {
  200. b := make([]byte, 0, 32)
  201. return string(b)
  202. }
  203. // FmtTimeLong returns the long time representation of 't' for 'mzn'
  204. func (mzn *mzn) FmtTimeLong(t time.Time) string {
  205. b := make([]byte, 0, 32)
  206. return string(b)
  207. }
  208. // FmtTimeFull returns the full time representation of 't' for 'mzn'
  209. func (mzn *mzn) FmtTimeFull(t time.Time) string {
  210. b := make([]byte, 0, 32)
  211. return string(b)
  212. }