ug_CN.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. package ug_CN
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type ug_CN 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. currencyNegativePrefix string
  23. currencyNegativeSuffix string
  24. monthsAbbreviated []string
  25. monthsNarrow []string
  26. monthsWide []string
  27. daysAbbreviated []string
  28. daysNarrow []string
  29. daysShort []string
  30. daysWide []string
  31. periodsAbbreviated []string
  32. periodsNarrow []string
  33. periodsShort []string
  34. periodsWide []string
  35. erasAbbreviated []string
  36. erasNarrow []string
  37. erasWide []string
  38. timezones map[string]string
  39. }
  40. // New returns a new instance of translator for the 'ug_CN' locale
  41. func New() locales.Translator {
  42. return &ug_CN{
  43. locale: "ug_CN",
  44. pluralsCardinal: []locales.PluralRule{2, 6},
  45. pluralsOrdinal: nil,
  46. pluralsRange: []locales.PluralRule{2, 6},
  47. decimal: ".",
  48. group: ",",
  49. minus: "-",
  50. percent: "%",
  51. perMille: "‰",
  52. timeSeparator: ":",
  53. inifinity: "∞",
  54. 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", "BRL", "BRN", "BRR", "BRZ", "BSD", "BTN", "BUK", "BWP", "BYB", "BYN", "BYR", "BZD", "CAD", "CDF", "CHE", "CHF", "CHW", "CLE", "CLF", "CLP", "CNH", "CNX", "CNY", "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", "EUR", "FIM", "FJD", "FKP", "FRF", "GBP", "GEK", "GEL", "GHC", "GHS", "GIP", "GMD", "GNF", "GNS", "GQE", "GRD", "GTQ", "GWE", "GWP", "GYD", "HKD", "HNL", "HRD", "HRK", "HTG", "HUF", "IDR", "IEP", "ILP", "ILR", "ILS", "INR", "IQD", "IRR", "ISJ", "ISK", "ITL", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRH", "KRO", "KRW", "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", "MXN", "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", "TWD", "TZS", "UAH", "UAK", "UGS", "UGX", "USD", "USN", "USS", "UYI", "UYP", "UYU", "UZS", "VEB", "VEF", "VND", "VNN", "VUV", "WST", "XAF", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "XCD", "XDR", "XEU", "XFO", "XFU", "XOF", "XPD", "XPF", "XPT", "XRE", "XSU", "XTS", "XUA", "XXX", "YDD", "YER", "YUD", "YUM", "YUN", "YUR", "ZAL", "ZAR", "ZMK", "ZMW", "ZRN", "ZRZ", "ZWD", "ZWL", "ZWR"},
  55. currencyNegativePrefix: "(",
  56. currencyNegativeSuffix: ")",
  57. monthsAbbreviated: []string{"", "يانۋار", "فېۋرال", "مارت", "ئاپرېل", "ماي", "ئىيۇن", "ئىيۇل", "ئاۋغۇست", "سېنتەبىر", "ئۆكتەبىر", "نويابىر", "دېكابىر"},
  58. monthsNarrow: []string{"", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"},
  59. monthsWide: []string{"", "يانۋار", "فېۋرال", "مارت", "ئاپرېل", "ماي", "ئىيۇن", "ئىيۇل", "ئاۋغۇست", "سېنتەبىر", "ئۆكتەبىر", "نويابىر", "دېكابىر"},
  60. daysAbbreviated: []string{"يە", "دۈ", "سە", "چا", "پە", "جۈ", "شە"},
  61. daysNarrow: []string{"ي", "د", "س", "چ", "پ", "ج", "ش"},
  62. daysShort: []string{"ي", "د", "س", "چ", "پ", "ج", "ش"},
  63. daysWide: []string{"يەكشەنبە", "دۈشەنبە", "سەيشەنبە", "چارشەنبە", "پەيشەنبە", "جۈمە", "شەنبە"},
  64. periodsAbbreviated: []string{"چ.ب", "چ.ك"},
  65. periodsNarrow: []string{"ب", "ك"},
  66. periodsWide: []string{"چۈشتىن بۇرۇن", "چۈشتىن كېيىن"},
  67. erasAbbreviated: []string{"BCE", "مىلادىيە"},
  68. erasNarrow: []string{"BCE", "مىلادىيە"},
  69. erasWide: []string{"مىلادىيەدىن بۇرۇن", "مىلادىيە"},
  70. timezones: map[string]string{"CST": "ئوتتۇرا قىسىم ئۆلچەملىك ۋاقتى", "CDT": "ئوتتۇرا قىسىم يازلىق ۋاقتى", "WAT": "غەربىي ئافرىقا ئۆلچەملىك ۋاقتى", "VET": "ۋېنېزۇئېلا ۋاقتى", "EAT": "شەرقىي ئافرىقا ۋاقتى", "COT": "كولومبىيە ئۆلچەملىك ۋاقتى", "COST": "كولومبىيە يازلىق ۋاقتى", "GYT": "گىۋىيانا ۋاقتى", "WAST": "غەربىي ئافرىقا يازلىق ۋاقتى", "WEZ": "غەربىي ياۋروپا ئۆلچەملىك ۋاقتى", "WESZ": "غەربىي ياۋروپا يازلىق ۋاقتى", "SGT": "سىنگاپور ۋاقتى", "HEOG": "غەربىي گىرېنلاند يازلىق ۋاقتى", "MESZ": "ئوتتۇرا ياۋروپا يازلىق ۋاقتى", "WITA": "ئوتتۇرا ھىندونېزىيە ۋاقتى", "ARST": "ئارگېنتىنا يازلىق ۋاقتى", "UYT": "ئۇرۇگۋاي ئۆلچەملىك ۋاقتى", "BT": "بۇتان ۋاقتى", "ECT": "ئېكۋادور ۋاقتى", "EDT": "شەرقىي قىسىم يازلىق ۋاقتى", "HNEG": "شەرقىي گىرېنلاند ئۆلچەملىك ۋاقتى", "CAT": "ئوتتۇرا ئافرىقا ۋاقتى", "HAST": "ھاۋاي-ئالېيۇت ئۆلچەملىك ۋاقتى", "AKDT": "ئالياسكا يازلىق ۋاقتى", "ACST": "ئاۋسترالىيە ئوتتۇرا قىسىم ئۆلچەملىك ۋاقتى", "WIT": "شەرقىي ھىندونېزىيە ۋاقتى", "NZDT": "يېڭى زېلاندىيە يازلىق ۋاقتى", "MST": "ئاۋمېن ئۆلچەملىك ۋاقتى", "SRT": "سۇرىنام ۋاقتى", "ART": "ئارگېنتىنا ئۆلچەملىك ۋاقتى", "CHADT": "چاتام يازلىق ۋاقتى", "HEPMX": "مېكسىكا تىنچ ئوكيان يازلىق ۋاقتى", "AEST": "ئاۋسترالىيە شەرقىي قىسىم ئۆلچەملىك ۋاقتى", "MYT": "مالايشىيا ۋاقتى", "AKST": "ئالياسكا ئۆلچەملىك ۋاقتى", "HKST": "شياڭگاڭ يازلىق ۋاقتى", "WART": "غەربىي ئارگېنتىنا ئۆلچەملىك ۋاقتى", "HNNOMX": "مېكسىكا غەربىي شىمالىي قىسىم ئۆلچەملىك ۋاقتى", "HECU": "كۇبا يازلىق ۋاقتى", "MDT": "ئاۋمېن يازلىق ۋاقتى", "GMT": "گىرىنۋىچ ۋاقتى", "HNCU": "كۇبا ئۆلچەملىك ۋاقتى", "AWST": "ئاۋسترالىيە غەربىي قىسىم ئۆلچەملىك ۋاقتى", "SAST": "جەنۇبىي ئافرىقا ئۆلچەملىك ۋاقتى", "∅∅∅": "ئاكرى يازلىق ۋاقتى", "WARST": "غەربىي ئارگېنتىنا يازلىق ۋاقتى", "HNPM": "ساينىت پىئېر ۋە مىكېلون ئۆلچەملىك ۋاقتى", "UYST": "ئۇرۇگۋاي يازلىق ۋاقتى", "PDT": "تىنچ ئوكيان يازلىق ۋاقتى", "WIB": "غەربىي ھىندونېزىيە ۋاقتى", "JDT": "ياپونىيە يازلىق ۋاقتى", "LHST": "لورد-خاي ئۆلچەملىك ۋاقتى", "LHDT": "لورد-خاي يازلىق ۋاقتى", "OEZ": "شەرقىي ياۋروپا ئۆلچەملىك ۋاقتى", "HADT": "ھاۋاي-ئالېيۇت يازلىق ۋاقتى", "ACDT": "ئاۋسترالىيە ئوتتۇرا قىسىم يازلىق ۋاقتى", "CLST": "چىلى يازلىق ۋاقتى", "PST": "تىنچ ئوكيان ئۆلچەملىك ۋاقتى", "AWDT": "ئاۋسترالىيە غەربىي قىسىم يازلىق ۋاقتى", "JST": "ياپونىيە ئۆلچەملىك ۋاقتى", "HEEG": "شەرقىي گىرېنلاند يازلىق ۋاقتى", "HAT": "نىۋفوئۇنلاند يازلىق ۋاقتى", "TMST": "تۈركمەنىستان يازلىق ۋاقتى", "HNPMX": "مېكسىكا تىنچ ئوكيان ئۆلچەملىك ۋاقتى", "ADT": "ئاتلانتىك ئوكيان يازلىق ۋاقتى", "HNOG": "غەربىي گىرېنلاند ئۆلچەملىك ۋاقتى", "HNT": "نىۋفوئۇنلاند ئۆلچەملىك ۋاقتى", "ChST": "چاموررو ئۆلچەملىك ۋاقتى", "NZST": "يېڭى زېلاندىيە ئۆلچەملىك ۋاقتى", "ACWST": "ئاۋستىرالىيە ئوتتۇرا غەربىي قىسىم ئۆلچەملىك ۋاقتى", "MEZ": "ئوتتۇرا ياۋروپا ئۆلچەملىك ۋاقتى", "IST": "ھىندىستان ئۆلچەملىك ۋاقتى", "CHAST": "چاتام ئۆلچەملىك ۋاقتى", "OESZ": "شەرقىي ياۋروپا يازلىق ۋاقتى", "AEDT": "ئاۋسترالىيە شەرقىي قىسىم يازلىق ۋاقتى", "BOT": "بولىۋىيە ۋاقتى", "GFT": "فىرانسىيەگە قاراشلىق گىۋىيانا ۋاقتى", "EST": "شەرقىي قىسىم ئۆلچەملىك ۋاقتى", "ACWDT": "ئاۋسترالىيە ئوتتۇرا غەربىي قىسىم يازلىق ۋاقتى", "HEPM": "ساينىت پىئېر ۋە مىكېلون يازلىق ۋاقتى", "CLT": "چىلى ئۆلچەملىك ۋاقتى", "HKT": "شياڭگاڭ ئۆلچەملىك ۋاقتى", "HENOMX": "مېكسىكا غەربىي شىمالىي قىسىم يازلىق ۋاقتى", "TMT": "تۈركمەنىستان ئۆلچەملىك ۋاقتى", "AST": "ئاتلانتىك ئوكيان ئۆلچەملىك ۋاقتى"},
  71. }
  72. }
  73. // Locale returns the current translators string locale
  74. func (ug *ug_CN) Locale() string {
  75. return ug.locale
  76. }
  77. // PluralsCardinal returns the list of cardinal plural rules associated with 'ug_CN'
  78. func (ug *ug_CN) PluralsCardinal() []locales.PluralRule {
  79. return ug.pluralsCardinal
  80. }
  81. // PluralsOrdinal returns the list of ordinal plural rules associated with 'ug_CN'
  82. func (ug *ug_CN) PluralsOrdinal() []locales.PluralRule {
  83. return ug.pluralsOrdinal
  84. }
  85. // PluralsRange returns the list of range plural rules associated with 'ug_CN'
  86. func (ug *ug_CN) PluralsRange() []locales.PluralRule {
  87. return ug.pluralsRange
  88. }
  89. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'ug_CN'
  90. func (ug *ug_CN) 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 'ug_CN'
  98. func (ug *ug_CN) 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 'ug_CN'
  102. func (ug *ug_CN) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  103. start := ug.CardinalPluralRule(num1, v1)
  104. end := ug.CardinalPluralRule(num2, v2)
  105. if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
  106. return locales.PluralRuleOther
  107. } else if start == locales.PluralRuleOther && end == locales.PluralRuleOne {
  108. return locales.PluralRuleOne
  109. }
  110. return locales.PluralRuleOther
  111. }
  112. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  113. func (ug *ug_CN) MonthAbbreviated(month time.Month) string {
  114. return ug.monthsAbbreviated[month]
  115. }
  116. // MonthsAbbreviated returns the locales abbreviated months
  117. func (ug *ug_CN) MonthsAbbreviated() []string {
  118. return ug.monthsAbbreviated[1:]
  119. }
  120. // MonthNarrow returns the locales narrow month given the 'month' provided
  121. func (ug *ug_CN) MonthNarrow(month time.Month) string {
  122. return ug.monthsNarrow[month]
  123. }
  124. // MonthsNarrow returns the locales narrow months
  125. func (ug *ug_CN) MonthsNarrow() []string {
  126. return ug.monthsNarrow[1:]
  127. }
  128. // MonthWide returns the locales wide month given the 'month' provided
  129. func (ug *ug_CN) MonthWide(month time.Month) string {
  130. return ug.monthsWide[month]
  131. }
  132. // MonthsWide returns the locales wide months
  133. func (ug *ug_CN) MonthsWide() []string {
  134. return ug.monthsWide[1:]
  135. }
  136. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  137. func (ug *ug_CN) WeekdayAbbreviated(weekday time.Weekday) string {
  138. return ug.daysAbbreviated[weekday]
  139. }
  140. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  141. func (ug *ug_CN) WeekdaysAbbreviated() []string {
  142. return ug.daysAbbreviated
  143. }
  144. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  145. func (ug *ug_CN) WeekdayNarrow(weekday time.Weekday) string {
  146. return ug.daysNarrow[weekday]
  147. }
  148. // WeekdaysNarrow returns the locales narrow weekdays
  149. func (ug *ug_CN) WeekdaysNarrow() []string {
  150. return ug.daysNarrow
  151. }
  152. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  153. func (ug *ug_CN) WeekdayShort(weekday time.Weekday) string {
  154. return ug.daysShort[weekday]
  155. }
  156. // WeekdaysShort returns the locales short weekdays
  157. func (ug *ug_CN) WeekdaysShort() []string {
  158. return ug.daysShort
  159. }
  160. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  161. func (ug *ug_CN) WeekdayWide(weekday time.Weekday) string {
  162. return ug.daysWide[weekday]
  163. }
  164. // WeekdaysWide returns the locales wide weekdays
  165. func (ug *ug_CN) WeekdaysWide() []string {
  166. return ug.daysWide
  167. }
  168. // Decimal returns the decimal point of number
  169. func (ug *ug_CN) Decimal() string {
  170. return ug.decimal
  171. }
  172. // Group returns the group of number
  173. func (ug *ug_CN) Group() string {
  174. return ug.group
  175. }
  176. // Group returns the minus sign of number
  177. func (ug *ug_CN) Minus() string {
  178. return ug.minus
  179. }
  180. // FmtNumber returns 'num' with digits/precision of 'v' for 'ug_CN' and handles both Whole and Real numbers based on 'v'
  181. func (ug *ug_CN) FmtNumber(num float64, v uint64) string {
  182. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  183. l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  184. count := 0
  185. inWhole := v == 0
  186. b := make([]byte, 0, l)
  187. for i := len(s) - 1; i >= 0; i-- {
  188. if s[i] == '.' {
  189. b = append(b, ug.decimal[0])
  190. inWhole = true
  191. continue
  192. }
  193. if inWhole {
  194. if count == 3 {
  195. b = append(b, ug.group[0])
  196. count = 1
  197. } else {
  198. count++
  199. }
  200. }
  201. b = append(b, s[i])
  202. }
  203. if num < 0 {
  204. b = append(b, ug.minus[0])
  205. }
  206. // reverse
  207. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  208. b[i], b[j] = b[j], b[i]
  209. }
  210. return string(b)
  211. }
  212. // FmtPercent returns 'num' with digits/precision of 'v' for 'ug_CN' and handles both Whole and Real numbers based on 'v'
  213. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  214. func (ug *ug_CN) FmtPercent(num float64, v uint64) string {
  215. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  216. l := len(s) + 3
  217. b := make([]byte, 0, l)
  218. for i := len(s) - 1; i >= 0; i-- {
  219. if s[i] == '.' {
  220. b = append(b, ug.decimal[0])
  221. continue
  222. }
  223. b = append(b, s[i])
  224. }
  225. if num < 0 {
  226. b = append(b, ug.minus[0])
  227. }
  228. // reverse
  229. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  230. b[i], b[j] = b[j], b[i]
  231. }
  232. b = append(b, ug.percent...)
  233. return string(b)
  234. }
  235. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'ug_CN'
  236. func (ug *ug_CN) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  237. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  238. symbol := ug.currencies[currency]
  239. l := len(s) + len(symbol) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  240. count := 0
  241. inWhole := v == 0
  242. b := make([]byte, 0, l)
  243. for i := len(s) - 1; i >= 0; i-- {
  244. if s[i] == '.' {
  245. b = append(b, ug.decimal[0])
  246. inWhole = true
  247. continue
  248. }
  249. if inWhole {
  250. if count == 3 {
  251. b = append(b, ug.group[0])
  252. count = 1
  253. } else {
  254. count++
  255. }
  256. }
  257. b = append(b, s[i])
  258. }
  259. for j := len(symbol) - 1; j >= 0; j-- {
  260. b = append(b, symbol[j])
  261. }
  262. if num < 0 {
  263. b = append(b, ug.minus[0])
  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, ug.decimal...)
  272. }
  273. for i := 0; i < 2-int(v); i++ {
  274. b = append(b, '0')
  275. }
  276. }
  277. return string(b)
  278. }
  279. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'ug_CN'
  280. // in accounting notation.
  281. func (ug *ug_CN) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  282. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  283. symbol := ug.currencies[currency]
  284. l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
  285. count := 0
  286. inWhole := v == 0
  287. b := make([]byte, 0, l)
  288. for i := len(s) - 1; i >= 0; i-- {
  289. if s[i] == '.' {
  290. b = append(b, ug.decimal[0])
  291. inWhole = true
  292. continue
  293. }
  294. if inWhole {
  295. if count == 3 {
  296. b = append(b, ug.group[0])
  297. count = 1
  298. } else {
  299. count++
  300. }
  301. }
  302. b = append(b, s[i])
  303. }
  304. if num < 0 {
  305. for j := len(symbol) - 1; j >= 0; j-- {
  306. b = append(b, symbol[j])
  307. }
  308. b = append(b, ug.currencyNegativePrefix[0])
  309. } else {
  310. for j := len(symbol) - 1; j >= 0; j-- {
  311. b = append(b, symbol[j])
  312. }
  313. }
  314. // reverse
  315. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  316. b[i], b[j] = b[j], b[i]
  317. }
  318. if int(v) < 2 {
  319. if v == 0 {
  320. b = append(b, ug.decimal...)
  321. }
  322. for i := 0; i < 2-int(v); i++ {
  323. b = append(b, '0')
  324. }
  325. }
  326. if num < 0 {
  327. b = append(b, ug.currencyNegativeSuffix...)
  328. }
  329. return string(b)
  330. }
  331. // FmtDateShort returns the short date representation of 't' for 'ug_CN'
  332. func (ug *ug_CN) FmtDateShort(t time.Time) string {
  333. b := make([]byte, 0, 32)
  334. if t.Year() > 0 {
  335. b = strconv.AppendInt(b, int64(t.Year()), 10)
  336. } else {
  337. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  338. }
  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.Day() < 10 {
  346. b = append(b, '0')
  347. }
  348. b = strconv.AppendInt(b, int64(t.Day()), 10)
  349. return string(b)
  350. }
  351. // FmtDateMedium returns the medium date representation of 't' for 'ug_CN'
  352. func (ug *ug_CN) FmtDateMedium(t time.Time) string {
  353. b := make([]byte, 0, 32)
  354. b = strconv.AppendInt(b, int64(t.Day()), 10)
  355. b = append(b, []byte{0x2d}...)
  356. b = append(b, ug.monthsAbbreviated[t.Month()]...)
  357. b = append(b, []byte{0xd8, 0x8c, 0x20}...)
  358. if t.Year() > 0 {
  359. b = strconv.AppendInt(b, int64(t.Year()), 10)
  360. } else {
  361. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  362. }
  363. return string(b)
  364. }
  365. // FmtDateLong returns the long date representation of 't' for 'ug_CN'
  366. func (ug *ug_CN) FmtDateLong(t time.Time) string {
  367. b := make([]byte, 0, 32)
  368. b = strconv.AppendInt(b, int64(t.Day()), 10)
  369. b = append(b, []byte{0x2d}...)
  370. b = append(b, ug.monthsWide[t.Month()]...)
  371. b = append(b, []byte{0xd8, 0x8c, 0x20}...)
  372. if t.Year() > 0 {
  373. b = strconv.AppendInt(b, int64(t.Year()), 10)
  374. } else {
  375. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  376. }
  377. return string(b)
  378. }
  379. // FmtDateFull returns the full date representation of 't' for 'ug_CN'
  380. func (ug *ug_CN) FmtDateFull(t time.Time) string {
  381. b := make([]byte, 0, 32)
  382. if t.Year() > 0 {
  383. b = strconv.AppendInt(b, int64(t.Year()), 10)
  384. } else {
  385. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  386. }
  387. b = append(b, []byte{0x20}...)
  388. b = strconv.AppendInt(b, int64(t.Day()), 10)
  389. b = append(b, []byte{0x2d}...)
  390. b = append(b, ug.monthsWide[t.Month()]...)
  391. b = append(b, []byte{0xd8, 0x8c, 0x20}...)
  392. b = append(b, ug.daysWide[t.Weekday()]...)
  393. return string(b)
  394. }
  395. // FmtTimeShort returns the short time representation of 't' for 'ug_CN'
  396. func (ug *ug_CN) FmtTimeShort(t time.Time) string {
  397. b := make([]byte, 0, 32)
  398. h := t.Hour()
  399. if h > 12 {
  400. h -= 12
  401. }
  402. b = strconv.AppendInt(b, int64(h), 10)
  403. b = append(b, ug.timeSeparator...)
  404. if t.Minute() < 10 {
  405. b = append(b, '0')
  406. }
  407. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  408. b = append(b, []byte{0x20}...)
  409. if t.Hour() < 12 {
  410. b = append(b, ug.periodsAbbreviated[0]...)
  411. } else {
  412. b = append(b, ug.periodsAbbreviated[1]...)
  413. }
  414. return string(b)
  415. }
  416. // FmtTimeMedium returns the medium time representation of 't' for 'ug_CN'
  417. func (ug *ug_CN) FmtTimeMedium(t time.Time) string {
  418. b := make([]byte, 0, 32)
  419. h := t.Hour()
  420. if h > 12 {
  421. h -= 12
  422. }
  423. b = strconv.AppendInt(b, int64(h), 10)
  424. b = append(b, ug.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, ug.timeSeparator...)
  430. if t.Second() < 10 {
  431. b = append(b, '0')
  432. }
  433. b = strconv.AppendInt(b, int64(t.Second()), 10)
  434. b = append(b, []byte{0x20}...)
  435. if t.Hour() < 12 {
  436. b = append(b, ug.periodsAbbreviated[0]...)
  437. } else {
  438. b = append(b, ug.periodsAbbreviated[1]...)
  439. }
  440. return string(b)
  441. }
  442. // FmtTimeLong returns the long time representation of 't' for 'ug_CN'
  443. func (ug *ug_CN) FmtTimeLong(t time.Time) string {
  444. b := make([]byte, 0, 32)
  445. h := t.Hour()
  446. if h > 12 {
  447. h -= 12
  448. }
  449. b = strconv.AppendInt(b, int64(h), 10)
  450. b = append(b, ug.timeSeparator...)
  451. if t.Minute() < 10 {
  452. b = append(b, '0')
  453. }
  454. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  455. b = append(b, ug.timeSeparator...)
  456. if t.Second() < 10 {
  457. b = append(b, '0')
  458. }
  459. b = strconv.AppendInt(b, int64(t.Second()), 10)
  460. b = append(b, []byte{0x20}...)
  461. if t.Hour() < 12 {
  462. b = append(b, ug.periodsAbbreviated[0]...)
  463. } else {
  464. b = append(b, ug.periodsAbbreviated[1]...)
  465. }
  466. b = append(b, []byte{0x20}...)
  467. tz, _ := t.Zone()
  468. b = append(b, tz...)
  469. return string(b)
  470. }
  471. // FmtTimeFull returns the full time representation of 't' for 'ug_CN'
  472. func (ug *ug_CN) FmtTimeFull(t time.Time) string {
  473. b := make([]byte, 0, 32)
  474. h := t.Hour()
  475. if h > 12 {
  476. h -= 12
  477. }
  478. b = strconv.AppendInt(b, int64(h), 10)
  479. b = append(b, ug.timeSeparator...)
  480. if t.Minute() < 10 {
  481. b = append(b, '0')
  482. }
  483. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  484. b = append(b, ug.timeSeparator...)
  485. if t.Second() < 10 {
  486. b = append(b, '0')
  487. }
  488. b = strconv.AppendInt(b, int64(t.Second()), 10)
  489. b = append(b, []byte{0x20}...)
  490. if t.Hour() < 12 {
  491. b = append(b, ug.periodsAbbreviated[0]...)
  492. } else {
  493. b = append(b, ug.periodsAbbreviated[1]...)
  494. }
  495. b = append(b, []byte{0x20}...)
  496. tz, _ := t.Zone()
  497. if btz, ok := ug.timezones[tz]; ok {
  498. b = append(b, btz...)
  499. } else {
  500. b = append(b, tz...)
  501. }
  502. return string(b)
  503. }