mzn.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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 ", "BYR", "BZD", "CA$", "CDF", "CHE ", "CHF", "CHW ", "CLE ", "CLF ", "CLP", "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", "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{"AWST": "AWST", "JDT": "JDT", "UYST": "UYST", "BT": "BT", "HKST": "HKST", "WARST": "WARST", "TMST": "TMST", "AWDT": "AWDT", "CST": "CST", "MEZ": "MEZ", "AEDT": "AEDT", "HADT": "HADT", "AKST": "AKST", "MYT": "MYT", "WAST": "WAST", "NZST": "NZST", "SGT": "SGT", "MDT": "MDT", "LHST": "LHST", "WESZ": "WESZ", "CHAST": "CHAST", "CLT": "CLT", "AST": "AST", "ADT": "ADT", "EAT": "EAT", "ACST": "ACST", "LHDT": "LHDT", "VET": "VET", "EST": "EST", "HAT": "HAT", "WIT": "WIT", "∅∅∅": "∅∅∅", "SRT": "SRT", "PDT": "PDT", "GYT": "GYT", "MESZ": "MESZ", "HAST": "HAST", "GFT": "GFT", "MST": "MST", "ACDT": "ACDT", "CDT": "CDT", "WEZ": "WEZ", "CHADT": "CHADT", "COST": "COST", "OESZ": "OESZ", "WITA": "WITA", "BOT": "BOT", "AKDT": "AKDT", "ACWST": "ACWST", "ChST": "ChST", "CLST": "CLST", "CAT": "CAT", "HNT": "HNT", "UYT": "UYT", "AEST": "AEST", "EDT": "EDT", "WIB": "WIB", "OEZ": "OEZ", "JST": "JST", "WART": "WART", "ARST": "ARST", "NZDT": "NZDT", "SAST": "SAST", "TMT": "TMT", "PST": "PST", "WAT": "WAT", "IST": "IST", "GMT": "GMT", "ART": "ART", "ACWDT": "ACWDT", "COT": "COT", "ECT": "ECT", "HKT": "HKT"},
  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 mzn.monthsNarrow[1:]
  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. // FmtNumber returns 'num' with digits/precision of 'v' for 'mzn' and handles both Whole and Real numbers based on 'v'
  140. func (mzn *mzn) FmtNumber(num float64, v uint64) string {
  141. return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  142. }
  143. // FmtPercent returns 'num' with digits/precision of 'v' for 'mzn' and handles both Whole and Real numbers based on 'v'
  144. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  145. func (mzn *mzn) FmtPercent(num float64, v uint64) string {
  146. return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  147. }
  148. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'mzn'
  149. func (mzn *mzn) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  150. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  151. symbol := mzn.currencies[currency]
  152. return string(append(append([]byte{}, symbol...), s...))
  153. }
  154. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'mzn'
  155. // in accounting notation.
  156. func (mzn *mzn) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  157. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  158. symbol := mzn.currencies[currency]
  159. return string(append(append([]byte{}, symbol...), s...))
  160. }
  161. // FmtDateShort returns the short date representation of 't' for 'mzn'
  162. func (mzn *mzn) FmtDateShort(t time.Time) string {
  163. b := make([]byte, 0, 32)
  164. return string(b)
  165. }
  166. // FmtDateMedium returns the medium date representation of 't' for 'mzn'
  167. func (mzn *mzn) FmtDateMedium(t time.Time) string {
  168. b := make([]byte, 0, 32)
  169. return string(b)
  170. }
  171. // FmtDateLong returns the long date representation of 't' for 'mzn'
  172. func (mzn *mzn) FmtDateLong(t time.Time) string {
  173. b := make([]byte, 0, 32)
  174. return string(b)
  175. }
  176. // FmtDateFull returns the full date representation of 't' for 'mzn'
  177. func (mzn *mzn) FmtDateFull(t time.Time) string {
  178. b := make([]byte, 0, 32)
  179. return string(b)
  180. }
  181. // FmtTimeShort returns the short time representation of 't' for 'mzn'
  182. func (mzn *mzn) FmtTimeShort(t time.Time) string {
  183. b := make([]byte, 0, 32)
  184. return string(b)
  185. }
  186. // FmtTimeMedium returns the medium time representation of 't' for 'mzn'
  187. func (mzn *mzn) FmtTimeMedium(t time.Time) string {
  188. b := make([]byte, 0, 32)
  189. return string(b)
  190. }
  191. // FmtTimeLong returns the long time representation of 't' for 'mzn'
  192. func (mzn *mzn) FmtTimeLong(t time.Time) string {
  193. b := make([]byte, 0, 32)
  194. return string(b)
  195. }
  196. // FmtTimeFull returns the full time representation of 't' for 'mzn'
  197. func (mzn *mzn) FmtTimeFull(t time.Time) string {
  198. b := make([]byte, 0, 32)
  199. return string(b)
  200. }