ps_AF.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. package ps_AF
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type ps_AF 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. currencyPositiveSuffix 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 'ps_AF' locale
  41. func New() locales.Translator {
  42. return &ps_AF{
  43. locale: "ps_AF",
  44. pluralsCardinal: []locales.PluralRule{2, 6},
  45. pluralsOrdinal: nil,
  46. pluralsRange: nil,
  47. decimal: "٫",
  48. group: "٬",
  49. percent: "٪",
  50. timeSeparator: ":",
  51. 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", "BYR", "BZD", "CAD", "CDF", "CHE", "CHF", "CHW", "CLE", "CLF", "CLP", "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", "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"},
  52. currencyPositiveSuffix: " ",
  53. currencyNegativeSuffix: " ",
  54. monthsWide: []string{"", "جنوري", "فبروري", "مارچ", "اپریل", "می", "جون", "جولای", "اګست", "سپتمبر", "اکتوبر", "نومبر", "دسمبر"},
  55. daysWide: []string{"یکشنبه", "دوشنبه", "سه\u200cشنبه", "چهارشنبه", "پنجشنبه", "جمعه", "شنبه"},
  56. periodsAbbreviated: []string{"غ.م.", "غ.و."},
  57. periodsWide: []string{"غ.م.", "غ.و."},
  58. erasAbbreviated: []string{"ق.م.", "م."},
  59. erasNarrow: []string{"", ""},
  60. erasWide: []string{"", ""},
  61. timezones: map[string]string{"EST": "EST", "HNT": "HNT", "BOT": "BOT", "AST": "AST", "WESZ": "∅∅∅", "AWST": "AWST", "SGT": "SGT", "ACWDT": "ACWDT", "CLT": "CLT", "CLST": "CLST", "ART": "ART", "ARST": "ARST", "WITA": "WITA", "SRT": "SRT", "JST": "JST", "MST": "MST", "CHADT": "CHADT", "AEST": "AEST", "CDT": "CDT", "TMT": "TMT", "TMST": "TMST", "HKT": "HKT", "UYT": "UYT", "OEZ": "OEZ", "COT": "COT", "HAT": "HAT", "∅∅∅": "∅∅∅", "JDT": "JDT", "BT": "BT", "MYT": "MYT", "IST": "IST", "AEDT": "AEDT", "LHST": "LHST", "HKST": "HKST", "WAT": "WAT", "MDT": "MDT", "WART": "WART", "AKDT": "AKDT", "ADT": "ADT", "WEZ": "∅∅∅", "COST": "COST", "HAST": "HAST", "HADT": "HADT", "EAT": "EAT", "ACST": "ACST", "ACDT": "ACDT", "NZST": "NZST", "GMT": "گرينويچ وخت", "ACWST": "ACWST", "GFT": "GFT", "AWDT": "AWDT", "PDT": "PDT", "CHAST": "CHAST", "UYST": "UYST", "MESZ": "MESZ", "PST": "PST", "WARST": "WARST", "SAST": "SAST", "LHDT": "LHDT", "GYT": "GYT", "NZDT": "NZDT", "VET": "VET", "ChST": "ChST", "OESZ": "OESZ", "AKST": "AKST", "WAST": "WAST", "WIB": "WIB", "EDT": "EDT", "WIT": "WIT", "CAT": "CAT", "CST": "CST", "ECT": "ECT", "MEZ": "MEZ"},
  62. }
  63. }
  64. // Locale returns the current translators string locale
  65. func (ps *ps_AF) Locale() string {
  66. return ps.locale
  67. }
  68. // PluralsCardinal returns the list of cardinal plural rules associated with 'ps_AF'
  69. func (ps *ps_AF) PluralsCardinal() []locales.PluralRule {
  70. return ps.pluralsCardinal
  71. }
  72. // PluralsOrdinal returns the list of ordinal plural rules associated with 'ps_AF'
  73. func (ps *ps_AF) PluralsOrdinal() []locales.PluralRule {
  74. return ps.pluralsOrdinal
  75. }
  76. // PluralsRange returns the list of range plural rules associated with 'ps_AF'
  77. func (ps *ps_AF) PluralsRange() []locales.PluralRule {
  78. return ps.pluralsRange
  79. }
  80. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'ps_AF'
  81. func (ps *ps_AF) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  82. n := math.Abs(num)
  83. if n == 1 {
  84. return locales.PluralRuleOne
  85. }
  86. return locales.PluralRuleOther
  87. }
  88. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'ps_AF'
  89. func (ps *ps_AF) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  90. return locales.PluralRuleUnknown
  91. }
  92. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'ps_AF'
  93. func (ps *ps_AF) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  94. return locales.PluralRuleUnknown
  95. }
  96. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  97. func (ps *ps_AF) MonthAbbreviated(month time.Month) string {
  98. return ps.monthsAbbreviated[month]
  99. }
  100. // MonthsAbbreviated returns the locales abbreviated months
  101. func (ps *ps_AF) MonthsAbbreviated() []string {
  102. return nil
  103. }
  104. // MonthNarrow returns the locales narrow month given the 'month' provided
  105. func (ps *ps_AF) MonthNarrow(month time.Month) string {
  106. return ps.monthsNarrow[month]
  107. }
  108. // MonthsNarrow returns the locales narrow months
  109. func (ps *ps_AF) MonthsNarrow() []string {
  110. return nil
  111. }
  112. // MonthWide returns the locales wide month given the 'month' provided
  113. func (ps *ps_AF) MonthWide(month time.Month) string {
  114. return ps.monthsWide[month]
  115. }
  116. // MonthsWide returns the locales wide months
  117. func (ps *ps_AF) MonthsWide() []string {
  118. return ps.monthsWide[1:]
  119. }
  120. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  121. func (ps *ps_AF) WeekdayAbbreviated(weekday time.Weekday) string {
  122. return ps.daysAbbreviated[weekday]
  123. }
  124. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  125. func (ps *ps_AF) WeekdaysAbbreviated() []string {
  126. return ps.daysAbbreviated
  127. }
  128. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  129. func (ps *ps_AF) WeekdayNarrow(weekday time.Weekday) string {
  130. return ps.daysNarrow[weekday]
  131. }
  132. // WeekdaysNarrow returns the locales narrow weekdays
  133. func (ps *ps_AF) WeekdaysNarrow() []string {
  134. return ps.daysNarrow
  135. }
  136. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  137. func (ps *ps_AF) WeekdayShort(weekday time.Weekday) string {
  138. return ps.daysShort[weekday]
  139. }
  140. // WeekdaysShort returns the locales short weekdays
  141. func (ps *ps_AF) WeekdaysShort() []string {
  142. return ps.daysShort
  143. }
  144. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  145. func (ps *ps_AF) WeekdayWide(weekday time.Weekday) string {
  146. return ps.daysWide[weekday]
  147. }
  148. // WeekdaysWide returns the locales wide weekdays
  149. func (ps *ps_AF) WeekdaysWide() []string {
  150. return ps.daysWide
  151. }
  152. // FmtNumber returns 'num' with digits/precision of 'v' for 'ps_AF' and handles both Whole and Real numbers based on 'v'
  153. func (ps *ps_AF) FmtNumber(num float64, v uint64) string {
  154. return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  155. }
  156. // FmtPercent returns 'num' with digits/precision of 'v' for 'ps_AF' and handles both Whole and Real numbers based on 'v'
  157. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  158. func (ps *ps_AF) FmtPercent(num float64, v uint64) string {
  159. return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  160. }
  161. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'ps_AF'
  162. func (ps *ps_AF) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  163. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  164. symbol := ps.currencies[currency]
  165. l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
  166. count := 0
  167. inWhole := v == 0
  168. b := make([]byte, 0, l)
  169. for i := len(s) - 1; i >= 0; i-- {
  170. if s[i] == '.' {
  171. for j := len(ps.decimal) - 1; j >= 0; j-- {
  172. b = append(b, ps.decimal[j])
  173. }
  174. inWhole = true
  175. continue
  176. }
  177. if inWhole {
  178. if count == 3 {
  179. for j := len(ps.group) - 1; j >= 0; j-- {
  180. b = append(b, ps.group[j])
  181. }
  182. count = 1
  183. } else {
  184. count++
  185. }
  186. }
  187. b = append(b, s[i])
  188. }
  189. if num < 0 {
  190. b = append(b, ps.minus[0])
  191. }
  192. // reverse
  193. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  194. b[i], b[j] = b[j], b[i]
  195. }
  196. if int(v) < 2 {
  197. if v == 0 {
  198. b = append(b, ps.decimal...)
  199. }
  200. for i := 0; i < 2-int(v); i++ {
  201. b = append(b, '0')
  202. }
  203. }
  204. b = append(b, ps.currencyPositiveSuffix...)
  205. b = append(b, symbol...)
  206. return string(b)
  207. }
  208. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'ps_AF'
  209. // in accounting notation.
  210. func (ps *ps_AF) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  211. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  212. symbol := ps.currencies[currency]
  213. l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
  214. count := 0
  215. inWhole := v == 0
  216. b := make([]byte, 0, l)
  217. for i := len(s) - 1; i >= 0; i-- {
  218. if s[i] == '.' {
  219. for j := len(ps.decimal) - 1; j >= 0; j-- {
  220. b = append(b, ps.decimal[j])
  221. }
  222. inWhole = true
  223. continue
  224. }
  225. if inWhole {
  226. if count == 3 {
  227. for j := len(ps.group) - 1; j >= 0; j-- {
  228. b = append(b, ps.group[j])
  229. }
  230. count = 1
  231. } else {
  232. count++
  233. }
  234. }
  235. b = append(b, s[i])
  236. }
  237. if num < 0 {
  238. b = append(b, ps.minus[0])
  239. }
  240. // reverse
  241. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  242. b[i], b[j] = b[j], b[i]
  243. }
  244. if int(v) < 2 {
  245. if v == 0 {
  246. b = append(b, ps.decimal...)
  247. }
  248. for i := 0; i < 2-int(v); i++ {
  249. b = append(b, '0')
  250. }
  251. }
  252. if num < 0 {
  253. b = append(b, ps.currencyNegativeSuffix...)
  254. b = append(b, symbol...)
  255. } else {
  256. b = append(b, ps.currencyPositiveSuffix...)
  257. b = append(b, symbol...)
  258. }
  259. return string(b)
  260. }
  261. // FmtDateShort returns the short date representation of 't' for 'ps_AF'
  262. func (ps *ps_AF) FmtDateShort(t time.Time) string {
  263. b := make([]byte, 0, 32)
  264. b = strconv.AppendInt(b, int64(t.Year()), 10)
  265. b = append(b, []byte{0x2f}...)
  266. b = strconv.AppendInt(b, int64(t.Month()), 10)
  267. b = append(b, []byte{0x2f}...)
  268. b = strconv.AppendInt(b, int64(t.Day()), 10)
  269. return string(b)
  270. }
  271. // FmtDateMedium returns the medium date representation of 't' for 'ps_AF'
  272. func (ps *ps_AF) FmtDateMedium(t time.Time) string {
  273. b := make([]byte, 0, 32)
  274. b = strconv.AppendInt(b, int64(t.Day()), 10)
  275. b = append(b, []byte{0x20}...)
  276. b = append(b, ps.monthsAbbreviated[t.Month()]...)
  277. b = append(b, []byte{0x20}...)
  278. b = strconv.AppendInt(b, int64(t.Year()), 10)
  279. return string(b)
  280. }
  281. // FmtDateLong returns the long date representation of 't' for 'ps_AF'
  282. func (ps *ps_AF) FmtDateLong(t time.Time) string {
  283. b := make([]byte, 0, 32)
  284. b = append(b, []byte{0xd8, 0xaf, 0x20}...)
  285. b = strconv.AppendInt(b, int64(t.Year()), 10)
  286. b = append(b, []byte{0x20, 0xd8, 0xaf, 0x20}...)
  287. b = append(b, ps.monthsWide[t.Month()]...)
  288. b = append(b, []byte{0x20}...)
  289. b = strconv.AppendInt(b, int64(t.Day()), 10)
  290. return string(b)
  291. }
  292. // FmtDateFull returns the full date representation of 't' for 'ps_AF'
  293. func (ps *ps_AF) FmtDateFull(t time.Time) string {
  294. b := make([]byte, 0, 32)
  295. b = append(b, ps.daysWide[t.Weekday()]...)
  296. b = append(b, []byte{0x20, 0xd8, 0xaf, 0x20}...)
  297. b = strconv.AppendInt(b, int64(t.Year()), 10)
  298. b = append(b, []byte{0x20, 0xd8, 0xaf, 0x20}...)
  299. b = append(b, ps.monthsWide[t.Month()]...)
  300. b = append(b, []byte{0x20}...)
  301. b = strconv.AppendInt(b, int64(t.Day()), 10)
  302. return string(b)
  303. }
  304. // FmtTimeShort returns the short time representation of 't' for 'ps_AF'
  305. func (ps *ps_AF) FmtTimeShort(t time.Time) string {
  306. b := make([]byte, 0, 32)
  307. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  308. b = append(b, ps.timeSeparator...)
  309. if t.Minute() < 10 {
  310. b = append(b, '0')
  311. }
  312. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  313. return string(b)
  314. }
  315. // FmtTimeMedium returns the medium time representation of 't' for 'ps_AF'
  316. func (ps *ps_AF) FmtTimeMedium(t time.Time) string {
  317. b := make([]byte, 0, 32)
  318. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  319. b = append(b, ps.timeSeparator...)
  320. if t.Minute() < 10 {
  321. b = append(b, '0')
  322. }
  323. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  324. b = append(b, ps.timeSeparator...)
  325. if t.Second() < 10 {
  326. b = append(b, '0')
  327. }
  328. b = strconv.AppendInt(b, int64(t.Second()), 10)
  329. return string(b)
  330. }
  331. // FmtTimeLong returns the long time representation of 't' for 'ps_AF'
  332. func (ps *ps_AF) FmtTimeLong(t time.Time) string {
  333. b := make([]byte, 0, 32)
  334. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  335. b = append(b, ps.timeSeparator...)
  336. if t.Minute() < 10 {
  337. b = append(b, '0')
  338. }
  339. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  340. b = append(b, ps.timeSeparator...)
  341. if t.Second() < 10 {
  342. b = append(b, '0')
  343. }
  344. b = strconv.AppendInt(b, int64(t.Second()), 10)
  345. b = append(b, []byte{0x20, 0x28}...)
  346. tz, _ := t.Zone()
  347. b = append(b, tz...)
  348. b = append(b, []byte{0x29}...)
  349. return string(b)
  350. }
  351. // FmtTimeFull returns the full time representation of 't' for 'ps_AF'
  352. func (ps *ps_AF) FmtTimeFull(t time.Time) string {
  353. b := make([]byte, 0, 32)
  354. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  355. b = append(b, ps.timeSeparator...)
  356. if t.Minute() < 10 {
  357. b = append(b, '0')
  358. }
  359. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  360. b = append(b, ps.timeSeparator...)
  361. if t.Second() < 10 {
  362. b = append(b, '0')
  363. }
  364. b = strconv.AppendInt(b, int64(t.Second()), 10)
  365. b = append(b, []byte{0x20, 0x28}...)
  366. tz, _ := t.Zone()
  367. if btz, ok := ps.timezones[tz]; ok {
  368. b = append(b, btz...)
  369. } else {
  370. b = append(b, tz...)
  371. }
  372. b = append(b, []byte{0x29}...)
  373. return string(b)
  374. }