8 "github.com/go-playground/locales"
9 "github.com/go-playground/locales/currency"
14 pluralsCardinal []locales.PluralRule
15 pluralsOrdinal []locales.PluralRule
16 pluralsRange []locales.PluralRule
24 currencies []string // idx = enum of currency code
25 currencyPositivePrefix string
26 currencyNegativePrefix string
27 monthsAbbreviated []string
30 daysAbbreviated []string
34 periodsAbbreviated []string
35 periodsNarrow []string
38 erasAbbreviated []string
41 timezones map[string]string
44 // New returns a new instance of translator for the 'fa' locale
45 func New() locales.Translator {
48 pluralsCardinal: []locales.PluralRule{2, 6},
49 pluralsOrdinal: []locales.PluralRule{6},
50 pluralsRange: []locales.PluralRule{6},
58 currencies: []string{"ADP", "AED", "AFA", "؋", "ALK", "ALL", "AMD", "ANG", "AOA", "AOK", "AON", "AOR", "ARA", "ARL", "ARM", "ARP", "ARS", "ATS", "A$", "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", "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", "ریال", "ISJ", "ISK", "ITL", "JMD", "JOD", "¥", "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", "$NZ", "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", "฿", "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", "CFPF", "XPT", "XRE", "XSU", "XTS", "XUA", "XXX", "YDD", "YER", "YUD", "YUM", "YUN", "YUR", "ZAL", "ZAR", "ZMK", "ZMW", "ZRN", "ZRZ", "ZWD", "ZWL", "ZWR"},
59 currencyPositivePrefix: "",
60 currencyNegativePrefix: "",
61 monthsAbbreviated: []string{"", "ژانویهٔ", "فوریهٔ", "مارس", "آوریل", "مهٔ", "ژوئن", "ژوئیهٔ", "اوت", "سپتامبر", "اکتبر", "نوامبر", "دسامبر"},
62 monthsNarrow: []string{"", "ژ", "ف", "م", "آ", "م", "ژ", "ژ", "ا", "س", "ا", "ن", "د"},
63 monthsWide: []string{"", "ژانویهٔ", "فوریهٔ", "مارس", "آوریل", "مهٔ", "ژوئن", "ژوئیهٔ", "اوت", "سپتامبر", "اکتبر", "نوامبر", "دسامبر"},
64 daysAbbreviated: []string{"یکشنبه", "دوشنبه", "سه\u200cشنبه", "چهارشنبه", "پنجشنبه", "جمعه", "شنبه"},
65 daysNarrow: []string{"ی", "د", "س", "چ", "پ", "ج", "ش"},
66 daysShort: []string{"۱ش", "۲ش", "۳ش", "۴ش", "۵ش", "ج", "ش"},
67 daysWide: []string{"یکشنبه", "دوشنبه", "سه\u200cشنبه", "چهارشنبه", "پنجشنبه", "جمعه", "شنبه"},
68 periodsAbbreviated: []string{"ق.ظ.", "ب.ظ."},
69 periodsNarrow: []string{"ق", "ب"},
70 periodsWide: []string{"قبل\u200cازظهر", "بعدازظهر"},
71 erasAbbreviated: []string{"ق.م.", "م."},
72 erasNarrow: []string{"ق", "م"},
73 erasWide: []string{"قبل از میلاد", "میلادی"},
74 timezones: map[string]string{"JST": "وقت عادی ژاپن", "AEST": "وقت عادی شرق استرالیا", "HNPMX": "وقت عادی شرق مکزیک", "MYT": "وقت مالزی", "VET": "وقت ونزوئلا", "JDT": "وقت تابستانی ژاپن", "ART": "وقت عادی آرژانتین", "WAT": "وقت عادی غرب افریقا", "HKST": "وقت تابستانی هنگ\u200cکنگ", "UYT": "وقت عادی اروگوئه", "NZDT": "وقت تابستانی زلاند نو", "OEZ": "وقت عادی شرق اروپا", "GFT": "وقت گویان فرانسه", "AKST": "وقت عادی آلاسکا", "SGT": "وقت سنگاپور", "ChST": "وقت عادی چامورو", "HNCU": "وقت عادی کوبا", "NZST": "وقت عادی زلاند نو", "CLST": "وقت تابستانی شیلی", "EDT": "وقت تابستانی شرق امریکا", "BOT": "وقت بولیوی", "AWDT": "وقت تابستانی غرب استرالیا", "LHST": "وقت عادی لردهو", "WARST": "وقت تابستانی غرب آرژانتین", "EST": "وقت عادی شرق امریکا", "GYT": "وقت گویان", "HEPM": "وقت تابستانی سنت\u200cپیر و میکلون", "SRT": "وقت سورینام", "WIT": "وقت شرق اندونزی", "WITA": "وقت مرکز اندونزی", "CST": "وقت عادی مرکز امریکا", "ACWDT": "وقت تابستانی مرکز-غرب استرالیا", "CHAST": "وقت عادی چت\u200cهام", "MEZ": "وقت عادی مرکز اروپا", "HAST": "وقت عادی هاوایی‐الوشن", "OESZ": "وقت تابستانی شرق اروپا", "CLT": "وقت عادی شیلی", "COT": "وقت عادی کلمبیا", "COST": "وقت تابستانی کلمبیا", "WESZ": "وقت تابستانی غرب اروپا", "ARST": "وقت تابستانی آرژانتین", "HNEG": "وقت عادی شرق گرینلند", "HKT": "وقت عادی هنگ\u200cکنگ", "HENOMX": "وقت تابستانی شمال غرب مکزیک", "HEOG": "وقت تابستانی غرب گرینلند", "WAST": "وقت تابستانی غرب افریقا", "AKDT": "وقت تابستانی آلاسکا", "ACDT": "وقت تابستانی مرکز استرالیا", "GMT": "وقت گرینویچ", "PST": "وقت عادی غرب امریکا", "MST": "وقت عادی کوهستانی امریکا", "AEDT": "وقت تابستانی شرق استرالیا", "WEZ": "وقت عادی غرب اروپا", "HEPMX": "وقت تابستانی شرق مکزیک", "CHADT": "وقت تابستانی چت\u200cهام", "HNOG": "وقت عادی غرب گرینلند", "SAST": "وقت عادی جنوب افریقا", "LHDT": "وقت تابستانی لردهو", "HNNOMX": "وقت عادی شمال غرب مکزیک", "CAT": "وقت مرکز افریقا", "CDT": "وقت تابستانی مرکز امریکا", "MESZ": "وقت تابستانی مرکز اروپا", "HNT": "وقت عادی نیوفاندلند", "HAT": "وقت تابستانی نیوفاندلند", "ACST": "وقت عادی مرکز استرالیا", "HNPM": "وقت عادی سنت\u200cپیر و میکلون", "ACWST": "وقت عادی مرکز-غرب استرالیا", "UYST": "وقت تابستانی اروگوئه", "TMT": "وقت عادی ترکمنستان", "TMST": "وقت تابستانی ترکمنستان", "WART": "وقت عادی غرب آرژانتین", "AST": "وقت عادی آتلانتیک", "HEEG": "وقت تابستانی شرق گرینلند", "PDT": "وقت تابستانی غرب امریکا", "MDT": "وقت تابستانی کوهستانی امریکا", "∅∅∅": "وقت تابستانی آزور", "ADT": "وقت تابستانی آتلانتیک", "ECT": "وقت اکوادور", "WIB": "وقت غرب اندونزی", "HECU": "وقت تابستانی کوبا", "BT": "وقت بوتان", "HADT": "وقت تابستانی هاوایی‐الوشن", "IST": "وقت هند", "EAT": "وقت شرق افریقا", "AWST": "وقت عادی غرب استرالیا"},
78 // Locale returns the current translators string locale
79 func (fa *fa) Locale() string {
83 // PluralsCardinal returns the list of cardinal plural rules associated with 'fa'
84 func (fa *fa) PluralsCardinal() []locales.PluralRule {
85 return fa.pluralsCardinal
88 // PluralsOrdinal returns the list of ordinal plural rules associated with 'fa'
89 func (fa *fa) PluralsOrdinal() []locales.PluralRule {
90 return fa.pluralsOrdinal
93 // PluralsRange returns the list of range plural rules associated with 'fa'
94 func (fa *fa) PluralsRange() []locales.PluralRule {
95 return fa.pluralsRange
98 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'fa'
99 func (fa *fa) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
104 if (i == 0) || (n == 1) {
105 return locales.PluralRuleOne
108 return locales.PluralRuleOther
111 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'fa'
112 func (fa *fa) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
113 return locales.PluralRuleOther
116 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'fa'
117 func (fa *fa) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
118 return locales.PluralRuleOther
121 // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
122 func (fa *fa) MonthAbbreviated(month time.Month) string {
123 return fa.monthsAbbreviated[month]
126 // MonthsAbbreviated returns the locales abbreviated months
127 func (fa *fa) MonthsAbbreviated() []string {
128 return fa.monthsAbbreviated[1:]
131 // MonthNarrow returns the locales narrow month given the 'month' provided
132 func (fa *fa) MonthNarrow(month time.Month) string {
133 return fa.monthsNarrow[month]
136 // MonthsNarrow returns the locales narrow months
137 func (fa *fa) MonthsNarrow() []string {
138 return fa.monthsNarrow[1:]
141 // MonthWide returns the locales wide month given the 'month' provided
142 func (fa *fa) MonthWide(month time.Month) string {
143 return fa.monthsWide[month]
146 // MonthsWide returns the locales wide months
147 func (fa *fa) MonthsWide() []string {
148 return fa.monthsWide[1:]
151 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
152 func (fa *fa) WeekdayAbbreviated(weekday time.Weekday) string {
153 return fa.daysAbbreviated[weekday]
156 // WeekdaysAbbreviated returns the locales abbreviated weekdays
157 func (fa *fa) WeekdaysAbbreviated() []string {
158 return fa.daysAbbreviated
161 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
162 func (fa *fa) WeekdayNarrow(weekday time.Weekday) string {
163 return fa.daysNarrow[weekday]
166 // WeekdaysNarrow returns the locales narrow weekdays
167 func (fa *fa) WeekdaysNarrow() []string {
171 // WeekdayShort returns the locales short weekday given the 'weekday' provided
172 func (fa *fa) WeekdayShort(weekday time.Weekday) string {
173 return fa.daysShort[weekday]
176 // WeekdaysShort returns the locales short weekdays
177 func (fa *fa) WeekdaysShort() []string {
181 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
182 func (fa *fa) WeekdayWide(weekday time.Weekday) string {
183 return fa.daysWide[weekday]
186 // WeekdaysWide returns the locales wide weekdays
187 func (fa *fa) WeekdaysWide() []string {
191 // Decimal returns the decimal point of number
192 func (fa *fa) Decimal() string {
196 // Group returns the group of number
197 func (fa *fa) Group() string {
201 // Group returns the minus sign of number
202 func (fa *fa) Minus() string {
206 // FmtNumber returns 'num' with digits/precision of 'v' for 'fa' and handles both Whole and Real numbers based on 'v'
207 func (fa *fa) FmtNumber(num float64, v uint64) string {
209 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
210 l := len(s) + 8 + 2*len(s[:len(s)-int(v)-1])/3
213 b := make([]byte, 0, l)
215 for i := len(s) - 1; i >= 0; i-- {
218 for j := len(fa.decimal) - 1; j >= 0; j-- {
219 b = append(b, fa.decimal[j])
227 for j := len(fa.group) - 1; j >= 0; j-- {
228 b = append(b, fa.group[j])
240 for j := len(fa.minus) - 1; j >= 0; j-- {
241 b = append(b, fa.minus[j])
246 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
247 b[i], b[j] = b[j], b[i]
253 // FmtPercent returns 'num' with digits/precision of 'v' for 'fa' and handles both Whole and Real numbers based on 'v'
254 // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
255 func (fa *fa) FmtPercent(num float64, v uint64) string {
256 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
258 b := make([]byte, 0, l)
260 for i := len(s) - 1; i >= 0; i-- {
263 for j := len(fa.decimal) - 1; j >= 0; j-- {
264 b = append(b, fa.decimal[j])
273 for j := len(fa.minus) - 1; j >= 0; j-- {
274 b = append(b, fa.minus[j])
279 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
280 b[i], b[j] = b[j], b[i]
283 b = append(b, fa.percent...)
288 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'fa'
289 func (fa *fa) FmtCurrency(num float64, v uint64, currency currency.Type) string {
291 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
292 symbol := fa.currencies[currency]
293 l := len(s) + len(symbol) + 11 + 2*len(s[:len(s)-int(v)-1])/3
296 b := make([]byte, 0, l)
298 for i := len(s) - 1; i >= 0; i-- {
301 for j := len(fa.decimal) - 1; j >= 0; j-- {
302 b = append(b, fa.decimal[j])
310 for j := len(fa.group) - 1; j >= 0; j-- {
311 b = append(b, fa.group[j])
322 for j := len(symbol) - 1; j >= 0; j-- {
323 b = append(b, symbol[j])
326 for j := len(fa.currencyPositivePrefix) - 1; j >= 0; j-- {
327 b = append(b, fa.currencyPositivePrefix[j])
331 for j := len(fa.minus) - 1; j >= 0; j-- {
332 b = append(b, fa.minus[j])
337 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
338 b[i], b[j] = b[j], b[i]
344 b = append(b, fa.decimal...)
347 for i := 0; i < 2-int(v); i++ {
355 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'fa'
356 // in accounting notation.
357 func (fa *fa) FmtAccounting(num float64, v uint64, currency currency.Type) string {
359 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
360 symbol := fa.currencies[currency]
361 l := len(s) + len(symbol) + 11 + 2*len(s[:len(s)-int(v)-1])/3
364 b := make([]byte, 0, l)
366 for i := len(s) - 1; i >= 0; i-- {
369 for j := len(fa.decimal) - 1; j >= 0; j-- {
370 b = append(b, fa.decimal[j])
378 for j := len(fa.group) - 1; j >= 0; j-- {
379 b = append(b, fa.group[j])
392 for j := len(symbol) - 1; j >= 0; j-- {
393 b = append(b, symbol[j])
396 for j := len(fa.currencyNegativePrefix) - 1; j >= 0; j-- {
397 b = append(b, fa.currencyNegativePrefix[j])
400 for j := len(fa.minus) - 1; j >= 0; j-- {
401 b = append(b, fa.minus[j])
406 for j := len(symbol) - 1; j >= 0; j-- {
407 b = append(b, symbol[j])
410 for j := len(fa.currencyPositivePrefix) - 1; j >= 0; j-- {
411 b = append(b, fa.currencyPositivePrefix[j])
417 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
418 b[i], b[j] = b[j], b[i]
424 b = append(b, fa.decimal...)
427 for i := 0; i < 2-int(v); i++ {
435 // FmtDateShort returns the short date representation of 't' for 'fa'
436 func (fa *fa) FmtDateShort(t time.Time) string {
438 b := make([]byte, 0, 32)
441 b = strconv.AppendInt(b, int64(t.Year()), 10)
443 b = strconv.AppendInt(b, int64(-t.Year()), 10)
446 b = append(b, []byte{0x2f}...)
447 b = strconv.AppendInt(b, int64(t.Month()), 10)
448 b = append(b, []byte{0x2f}...)
449 b = strconv.AppendInt(b, int64(t.Day()), 10)
454 // FmtDateMedium returns the medium date representation of 't' for 'fa'
455 func (fa *fa) FmtDateMedium(t time.Time) string {
457 b := make([]byte, 0, 32)
459 b = strconv.AppendInt(b, int64(t.Day()), 10)
460 b = append(b, []byte{0x20}...)
461 b = append(b, fa.monthsAbbreviated[t.Month()]...)
462 b = append(b, []byte{0x20}...)
465 b = strconv.AppendInt(b, int64(t.Year()), 10)
467 b = strconv.AppendInt(b, int64(-t.Year()), 10)
473 // FmtDateLong returns the long date representation of 't' for 'fa'
474 func (fa *fa) FmtDateLong(t time.Time) string {
476 b := make([]byte, 0, 32)
478 b = strconv.AppendInt(b, int64(t.Day()), 10)
479 b = append(b, []byte{0x20}...)
480 b = append(b, fa.monthsWide[t.Month()]...)
481 b = append(b, []byte{0x20}...)
484 b = strconv.AppendInt(b, int64(t.Year()), 10)
486 b = strconv.AppendInt(b, int64(-t.Year()), 10)
492 // FmtDateFull returns the full date representation of 't' for 'fa'
493 func (fa *fa) FmtDateFull(t time.Time) string {
495 b := make([]byte, 0, 32)
497 b = append(b, fa.daysWide[t.Weekday()]...)
498 b = append(b, []byte{0x20}...)
499 b = strconv.AppendInt(b, int64(t.Day()), 10)
500 b = append(b, []byte{0x20}...)
501 b = append(b, fa.monthsWide[t.Month()]...)
502 b = append(b, []byte{0x20}...)
505 b = strconv.AppendInt(b, int64(t.Year()), 10)
507 b = strconv.AppendInt(b, int64(-t.Year()), 10)
513 // FmtTimeShort returns the short time representation of 't' for 'fa'
514 func (fa *fa) FmtTimeShort(t time.Time) string {
516 b := make([]byte, 0, 32)
518 b = strconv.AppendInt(b, int64(t.Hour()), 10)
519 b = append(b, fa.timeSeparator...)
525 b = strconv.AppendInt(b, int64(t.Minute()), 10)
530 // FmtTimeMedium returns the medium time representation of 't' for 'fa'
531 func (fa *fa) FmtTimeMedium(t time.Time) string {
533 b := make([]byte, 0, 32)
535 b = strconv.AppendInt(b, int64(t.Hour()), 10)
536 b = append(b, fa.timeSeparator...)
542 b = strconv.AppendInt(b, int64(t.Minute()), 10)
543 b = append(b, fa.timeSeparator...)
549 b = strconv.AppendInt(b, int64(t.Second()), 10)
554 // FmtTimeLong returns the long time representation of 't' for 'fa'
555 func (fa *fa) FmtTimeLong(t time.Time) string {
557 b := make([]byte, 0, 32)
559 b = strconv.AppendInt(b, int64(t.Hour()), 10)
560 b = append(b, fa.timeSeparator...)
566 b = strconv.AppendInt(b, int64(t.Minute()), 10)
567 b = append(b, fa.timeSeparator...)
573 b = strconv.AppendInt(b, int64(t.Second()), 10)
574 b = append(b, []byte{0x20, 0x28}...)
579 b = append(b, []byte{0x29}...)
584 // FmtTimeFull returns the full time representation of 't' for 'fa'
585 func (fa *fa) FmtTimeFull(t time.Time) string {
587 b := make([]byte, 0, 32)
589 b = strconv.AppendInt(b, int64(t.Hour()), 10)
590 b = append(b, fa.timeSeparator...)
596 b = strconv.AppendInt(b, int64(t.Minute()), 10)
597 b = append(b, fa.timeSeparator...)
603 b = strconv.AppendInt(b, int64(t.Second()), 10)
604 b = append(b, []byte{0x20, 0x28}...)
608 if btz, ok := fa.timezones[tz]; ok {
609 b = append(b, btz...)
614 b = append(b, []byte{0x29}...)