br_FR.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. package br_FR
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type br_FR 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. percentSuffix string
  19. perMille string
  20. timeSeparator string
  21. inifinity string
  22. currencies []string // idx = enum of currency code
  23. currencyPositiveSuffix string
  24. currencyNegativeSuffix string
  25. monthsAbbreviated []string
  26. monthsNarrow []string
  27. monthsWide []string
  28. daysAbbreviated []string
  29. daysNarrow []string
  30. daysShort []string
  31. daysWide []string
  32. periodsAbbreviated []string
  33. periodsNarrow []string
  34. periodsShort []string
  35. periodsWide []string
  36. erasAbbreviated []string
  37. erasNarrow []string
  38. erasWide []string
  39. timezones map[string]string
  40. }
  41. // New returns a new instance of translator for the 'br_FR' locale
  42. func New() locales.Translator {
  43. return &br_FR{
  44. locale: "br_FR",
  45. pluralsCardinal: []locales.PluralRule{2, 3, 4, 5, 6},
  46. pluralsOrdinal: nil,
  47. pluralsRange: nil,
  48. decimal: ",",
  49. group: " ",
  50. minus: "-",
  51. percent: "%",
  52. perMille: "‰",
  53. timeSeparator: ":",
  54. inifinity: "∞",
  55. 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"},
  56. percentSuffix: " ",
  57. currencyPositiveSuffix: " ",
  58. currencyNegativeSuffix: " ",
  59. monthsAbbreviated: []string{"", "Gen.", "Cʼhwe.", "Meur.", "Ebr.", "Mae", "Mezh.", "Goue.", "Eost", "Gwen.", "Here", "Du", "Kzu."},
  60. monthsNarrow: []string{"", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"},
  61. monthsWide: []string{"", "Genver", "Cʼhwevrer", "Meurzh", "Ebrel", "Mae", "Mezheven", "Gouere", "Eost", "Gwengolo", "Here", "Du", "Kerzu"},
  62. daysAbbreviated: []string{"Sul", "Lun", "Meu.", "Mer.", "Yaou", "Gwe.", "Sad."},
  63. daysNarrow: []string{"Su", "L", "Mz", "Mc", "Y", "G", "Sa"},
  64. daysWide: []string{"Sul", "Lun", "Meurzh", "Mercʼher", "Yaou", "Gwener", "Sadorn"},
  65. periodsAbbreviated: []string{"A.M.", "G.M."},
  66. periodsNarrow: []string{"am", "gm"},
  67. periodsWide: []string{"A.M.", "G.M."},
  68. erasAbbreviated: []string{"a-raok J.K.", "goude J.K."},
  69. erasNarrow: []string{"a-raok J.K.", "goude J.K."},
  70. erasWide: []string{"a-raok Jezuz-Krist", "goude Jezuz-Krist"},
  71. timezones: map[string]string{"LHST": "LHST", "AST": "AST", "ChST": "ChST", "AWDT": "eur hañv Aostralia ar Cʼhornôg", "IST": "eur cʼhoañv India", "BT": "eur Bhoutan", "ACWDT": "eur hañv Kreizaostralia ar Cʼhornôg", "GYT": "eur Guyana", "JST": "eur cʼhoañv Japan", "OEZ": "eur cʼhoañv Europa ar Reter", "MESZ": "eur hañv Kreizeuropa", "EDT": "eur hañv ar Reter", "UYT": "eur cʼhoañv Uruguay", "NZDT": "eur hañv Zeland-Nevez", "JDT": "eur hañv Japan", "WEZ": "eur cʼhoañv Europa ar Cʼhornôg", "ARST": "eur hañv Arcʼhantina", "PDT": "PDT", "WAST": "eur hañv Afrika ar Cʼhornôg", "MST": "eur cʼhoañv ar Menezioù", "HAT": "eur hañv Newfoundland", "GFT": "eur Gwiana cʼhall", "OESZ": "eur hañv Europa ar Reter", "ECT": "eur Ecuador", "HAST": "HAST", "EST": "eur cʼhoañv ar Reter", "EAT": "eur Afrika ar Reter", "HADT": "HADT", "AEST": "eur cʼhoañv Aostralia ar Reter", "UYST": "eur hañv Uruguay", "WIB": "eur Indonezia ar Cʼhornôg", "AEDT": "eur hañv Aostralia ar Reter", "AKDT": "eur hañv Alaska", "BOT": "eur Bolivia", "HKT": "eur cʼhoañv Hong Kong", "COT": "eur cʼhoañv Kolombia", "VET": "eur Venezuela", "MEZ": "eur cʼhoañv Kreizeuropa", "TMST": "eur hañv Turkmenistan", "CLT": "eur cʼhoañv Chile", "CST": "CST", "CLST": "eur hañv Chile", "CAT": "eur Kreizafrika", "WESZ": "eur hañv Europa ar Cʼhornôg", "ART": "eur cʼhoañv Arcʼhantina", "ADT": "ADT", "TMT": "eur cʼhoañv Turkmenistan", "MDT": "eur hañv ar Menezioù", "WIT": "eur Indonezia ar Reter", "HNT": "eur cʼhoañv Newfoundland", "GMT": "Amzer keitat Greenwich (AKG)", "LHDT": "LHDT", "AKST": "eur cʼhoañv Alaska", "SAST": "eur cʼhoañv Suafrika", "ACWST": "eur cʼhoañv Kreizaostralia ar Cʼhornôg", "WAT": "eur cʼhoañv Afrika ar Cʼhornôg", "∅∅∅": "eur hañv an Azorez", "MYT": "eur Malaysia", "HKST": "eur hañv Hong Kong", "CDT": "CDT", "CHAST": "eur cʼhoañv Chatham", "ACDT": "eur hañv Kreizaostralia", "WART": "eur cʼhoañv Arcʼhantina ar Cʼhornôg", "PST": "PST", "WITA": "WITA", "WARST": "eur hañv Arcʼhantina ar Cʼhornôg", "ACST": "eur cʼhoañv Kreizaostralia", "COST": "eur hañv Kolombia", "SRT": "eur Surinam", "CHADT": "eur hañv Chatham", "SGT": "eur cʼhoañv Singapour", "NZST": "eur cʼhoañv Zeland-Nevez", "AWST": "eur cʼhoañv Aostralia ar Cʼhornôg"},
  72. }
  73. }
  74. // Locale returns the current translators string locale
  75. func (br *br_FR) Locale() string {
  76. return br.locale
  77. }
  78. // PluralsCardinal returns the list of cardinal plural rules associated with 'br_FR'
  79. func (br *br_FR) PluralsCardinal() []locales.PluralRule {
  80. return br.pluralsCardinal
  81. }
  82. // PluralsOrdinal returns the list of ordinal plural rules associated with 'br_FR'
  83. func (br *br_FR) PluralsOrdinal() []locales.PluralRule {
  84. return br.pluralsOrdinal
  85. }
  86. // PluralsRange returns the list of range plural rules associated with 'br_FR'
  87. func (br *br_FR) PluralsRange() []locales.PluralRule {
  88. return br.pluralsRange
  89. }
  90. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'br_FR'
  91. func (br *br_FR) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  92. n := math.Abs(num)
  93. nMod10 := math.Mod(n, 10)
  94. nMod100 := math.Mod(n, 100)
  95. nMod1000000 := math.Mod(n, 1000000)
  96. if nMod10 == 1 && (nMod100 != 11 && nMod100 != 71 && nMod100 != 91) {
  97. return locales.PluralRuleOne
  98. } else if nMod10 == 2 && (nMod100 != 12 && nMod100 != 72 && nMod100 != 92) {
  99. return locales.PluralRuleTwo
  100. } else if nMod10 >= 3 && nMod10 <= 4 && (nMod10 == 9) && (nMod100 < 10 || nMod100 > 19) || (nMod100 < 70 || nMod100 > 79) || (nMod100 < 90 || nMod100 > 99) {
  101. return locales.PluralRuleFew
  102. } else if n != 0 && nMod1000000 == 0 {
  103. return locales.PluralRuleMany
  104. }
  105. return locales.PluralRuleOther
  106. }
  107. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'br_FR'
  108. func (br *br_FR) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  109. return locales.PluralRuleUnknown
  110. }
  111. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'br_FR'
  112. func (br *br_FR) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  113. return locales.PluralRuleUnknown
  114. }
  115. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  116. func (br *br_FR) MonthAbbreviated(month time.Month) string {
  117. return br.monthsAbbreviated[month]
  118. }
  119. // MonthsAbbreviated returns the locales abbreviated months
  120. func (br *br_FR) MonthsAbbreviated() []string {
  121. return br.monthsAbbreviated[1:]
  122. }
  123. // MonthNarrow returns the locales narrow month given the 'month' provided
  124. func (br *br_FR) MonthNarrow(month time.Month) string {
  125. return br.monthsNarrow[month]
  126. }
  127. // MonthsNarrow returns the locales narrow months
  128. func (br *br_FR) MonthsNarrow() []string {
  129. return br.monthsNarrow[1:]
  130. }
  131. // MonthWide returns the locales wide month given the 'month' provided
  132. func (br *br_FR) MonthWide(month time.Month) string {
  133. return br.monthsWide[month]
  134. }
  135. // MonthsWide returns the locales wide months
  136. func (br *br_FR) MonthsWide() []string {
  137. return br.monthsWide[1:]
  138. }
  139. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  140. func (br *br_FR) WeekdayAbbreviated(weekday time.Weekday) string {
  141. return br.daysAbbreviated[weekday]
  142. }
  143. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  144. func (br *br_FR) WeekdaysAbbreviated() []string {
  145. return br.daysAbbreviated
  146. }
  147. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  148. func (br *br_FR) WeekdayNarrow(weekday time.Weekday) string {
  149. return br.daysNarrow[weekday]
  150. }
  151. // WeekdaysNarrow returns the locales narrow weekdays
  152. func (br *br_FR) WeekdaysNarrow() []string {
  153. return br.daysNarrow
  154. }
  155. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  156. func (br *br_FR) WeekdayShort(weekday time.Weekday) string {
  157. return br.daysShort[weekday]
  158. }
  159. // WeekdaysShort returns the locales short weekdays
  160. func (br *br_FR) WeekdaysShort() []string {
  161. return br.daysShort
  162. }
  163. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  164. func (br *br_FR) WeekdayWide(weekday time.Weekday) string {
  165. return br.daysWide[weekday]
  166. }
  167. // WeekdaysWide returns the locales wide weekdays
  168. func (br *br_FR) WeekdaysWide() []string {
  169. return br.daysWide
  170. }
  171. // FmtNumber returns 'num' with digits/precision of 'v' for 'br_FR' and handles both Whole and Real numbers based on 'v'
  172. func (br *br_FR) FmtNumber(num float64, v uint64) string {
  173. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  174. l := len(s) + 2 + 2*len(s[:len(s)-int(v)-1])/3
  175. count := 0
  176. inWhole := v == 0
  177. b := make([]byte, 0, l)
  178. for i := len(s) - 1; i >= 0; i-- {
  179. if s[i] == '.' {
  180. b = append(b, br.decimal[0])
  181. inWhole = true
  182. continue
  183. }
  184. if inWhole {
  185. if count == 3 {
  186. for j := len(br.group) - 1; j >= 0; j-- {
  187. b = append(b, br.group[j])
  188. }
  189. count = 1
  190. } else {
  191. count++
  192. }
  193. }
  194. b = append(b, s[i])
  195. }
  196. if num < 0 {
  197. b = append(b, br.minus[0])
  198. }
  199. // reverse
  200. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  201. b[i], b[j] = b[j], b[i]
  202. }
  203. return string(b)
  204. }
  205. // FmtPercent returns 'num' with digits/precision of 'v' for 'br_FR' and handles both Whole and Real numbers based on 'v'
  206. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  207. func (br *br_FR) FmtPercent(num float64, v uint64) string {
  208. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  209. l := len(s) + 5
  210. b := make([]byte, 0, l)
  211. for i := len(s) - 1; i >= 0; i-- {
  212. if s[i] == '.' {
  213. b = append(b, br.decimal[0])
  214. continue
  215. }
  216. b = append(b, s[i])
  217. }
  218. if num < 0 {
  219. b = append(b, br.minus[0])
  220. }
  221. // reverse
  222. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  223. b[i], b[j] = b[j], b[i]
  224. }
  225. b = append(b, br.percentSuffix...)
  226. b = append(b, br.percent...)
  227. return string(b)
  228. }
  229. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'br_FR'
  230. func (br *br_FR) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  231. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  232. symbol := br.currencies[currency]
  233. l := len(s) + len(symbol) + 4 + 2*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, br.decimal[0])
  240. inWhole = true
  241. continue
  242. }
  243. if inWhole {
  244. if count == 3 {
  245. for j := len(br.group) - 1; j >= 0; j-- {
  246. b = append(b, br.group[j])
  247. }
  248. count = 1
  249. } else {
  250. count++
  251. }
  252. }
  253. b = append(b, s[i])
  254. }
  255. if num < 0 {
  256. b = append(b, br.minus[0])
  257. }
  258. // reverse
  259. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  260. b[i], b[j] = b[j], b[i]
  261. }
  262. if int(v) < 2 {
  263. if v == 0 {
  264. b = append(b, br.decimal...)
  265. }
  266. for i := 0; i < 2-int(v); i++ {
  267. b = append(b, '0')
  268. }
  269. }
  270. b = append(b, br.currencyPositiveSuffix...)
  271. b = append(b, symbol...)
  272. return string(b)
  273. }
  274. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'br_FR'
  275. // in accounting notation.
  276. func (br *br_FR) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  277. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  278. symbol := br.currencies[currency]
  279. l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
  280. count := 0
  281. inWhole := v == 0
  282. b := make([]byte, 0, l)
  283. for i := len(s) - 1; i >= 0; i-- {
  284. if s[i] == '.' {
  285. b = append(b, br.decimal[0])
  286. inWhole = true
  287. continue
  288. }
  289. if inWhole {
  290. if count == 3 {
  291. for j := len(br.group) - 1; j >= 0; j-- {
  292. b = append(b, br.group[j])
  293. }
  294. count = 1
  295. } else {
  296. count++
  297. }
  298. }
  299. b = append(b, s[i])
  300. }
  301. if num < 0 {
  302. b = append(b, br.minus[0])
  303. }
  304. // reverse
  305. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  306. b[i], b[j] = b[j], b[i]
  307. }
  308. if int(v) < 2 {
  309. if v == 0 {
  310. b = append(b, br.decimal...)
  311. }
  312. for i := 0; i < 2-int(v); i++ {
  313. b = append(b, '0')
  314. }
  315. }
  316. if num < 0 {
  317. b = append(b, br.currencyNegativeSuffix...)
  318. b = append(b, symbol...)
  319. } else {
  320. b = append(b, br.currencyPositiveSuffix...)
  321. b = append(b, symbol...)
  322. }
  323. return string(b)
  324. }
  325. // FmtDateShort returns the short date representation of 't' for 'br_FR'
  326. func (br *br_FR) FmtDateShort(t time.Time) string {
  327. b := make([]byte, 0, 32)
  328. return string(b)
  329. }
  330. // FmtDateMedium returns the medium date representation of 't' for 'br_FR'
  331. func (br *br_FR) FmtDateMedium(t time.Time) string {
  332. b := make([]byte, 0, 32)
  333. return string(b)
  334. }
  335. // FmtDateLong returns the long date representation of 't' for 'br_FR'
  336. func (br *br_FR) FmtDateLong(t time.Time) string {
  337. b := make([]byte, 0, 32)
  338. return string(b)
  339. }
  340. // FmtDateFull returns the full date representation of 't' for 'br_FR'
  341. func (br *br_FR) FmtDateFull(t time.Time) string {
  342. b := make([]byte, 0, 32)
  343. return string(b)
  344. }
  345. // FmtTimeShort returns the short time representation of 't' for 'br_FR'
  346. func (br *br_FR) FmtTimeShort(t time.Time) string {
  347. b := make([]byte, 0, 32)
  348. return string(b)
  349. }
  350. // FmtTimeMedium returns the medium time representation of 't' for 'br_FR'
  351. func (br *br_FR) FmtTimeMedium(t time.Time) string {
  352. b := make([]byte, 0, 32)
  353. return string(b)
  354. }
  355. // FmtTimeLong returns the long time representation of 't' for 'br_FR'
  356. func (br *br_FR) FmtTimeLong(t time.Time) string {
  357. b := make([]byte, 0, 32)
  358. return string(b)
  359. }
  360. // FmtTimeFull returns the full time representation of 't' for 'br_FR'
  361. func (br *br_FR) FmtTimeFull(t time.Time) string {
  362. b := make([]byte, 0, 32)
  363. return string(b)
  364. }