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 currencyNegativePrefix string
26 currencyNegativeSuffix 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 'af' 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", "AFN", "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", "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", "MXN", "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", "US$", "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", "R", "ZMK", "ZMW", "ZRN", "ZRZ", "ZWD", "ZWL", "ZWR"},
59 currencyNegativePrefix: "(",
60 currencyNegativeSuffix: ")",
61 monthsAbbreviated: []string{"", "Jan.", "Feb.", "Mrt.", "Apr.", "Mei", "Jun.", "Jul.", "Aug.", "Sep.", "Okt.", "Nov.", "Des."},
62 monthsNarrow: []string{"", "J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"},
63 monthsWide: []string{"", "Januarie", "Februarie", "Maart", "April", "Mei", "Junie", "Julie", "Augustus", "September", "Oktober", "November", "Desember"},
64 daysAbbreviated: []string{"So.", "Ma.", "Di.", "Wo.", "Do.", "Vr.", "Sa."},
65 daysNarrow: []string{"S", "M", "D", "W", "D", "V", "S"},
66 daysShort: []string{"So.", "Ma.", "Di.", "Wo.", "Do.", "Vr.", "Sa."},
67 daysWide: []string{"Sondag", "Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrydag", "Saterdag"},
68 periodsAbbreviated: []string{"vm.", "nm."},
69 periodsNarrow: []string{"v", "n"},
70 periodsWide: []string{"vm.", "nm."},
71 erasAbbreviated: []string{"v.C.", "n.C."},
72 erasNarrow: []string{"v.C.", "n.C."},
73 erasWide: []string{"voor Christus", "na Christus"},
74 timezones: map[string]string{"CST": "Sentrale standaardtyd", "MST": "MST", "MYT": "Maleisië-tyd", "CAT": "Sentraal-Afrika-tyd", "HNPMX": "Meksikaanse Pasifiese standaardtyd", "BOT": "Bolivia-tyd", "MEZ": "Sentraal-Europese standaardtyd", "HADT": "Hawaii-Aleusiër-dagligtyd", "LHDT": "Lord Howe-dagligtyd", "VET": "Venezuela-tyd", "SAST": "Suid-Afrika-standaardtyd", "HEEG": "Oos-Groenland-somertyd", "CLST": "Chili-somertyd", "EDT": "Oostelike dagligtyd", "GYT": "Guyana-tyd", "AKST": "Alaska-standaardtyd", "ACST": "Australiese sentraal-standaardtyd", "PST": "Pasifiese standaardtyd", "HECU": "Kuba-dagligtyd", "WART": "Wes-Argentinië-standaardtyd", "ARST": "Argentinië-somertyd", "HNT": "Newfoundland-standaardtyd", "HAST": "Hawaii-Aleusiër-standaardtyd", "AST": "Atlantiese standaardtyd", "HNOG": "Wes-Groenland-standaardtyd", "WAST": "Wes-Afrika-somertyd", "UYST": "Uruguay-somertyd", "TMST": "Turkmenistan-somertyd", "WITA": "Sentraal Indonesië-tyd", "HKT": "Hongkong-standaardtyd", "AWST": "Australiese Westelike standaardtyd", "WARST": "Wes-Argentinië-somertyd", "HENOMX": "Noordwes-Meksiko-dagligtyd", "WAT": "Wes-Afrika-standaardtyd", "AKDT": "Alaska-dagligtyd", "SRT": "Suriname-tyd", "OEZ": "Oos-Europese standaardtyd", "HEOG": "Wes-Groenland-somertyd", "HNEG": "Oos-Groenland-standaardtyd", "COT": "Colombië-standaardtyd", "GFT": "Frans-Guiana-tyd", "WEZ": "Wes-Europese standaardtyd", "WIB": "Wes-Indonesië-tyd", "MDT": "MDT", "ACWST": "Australiese sentraal-Westelike standaard-tyd", "UYT": "Uruguay-standaardtyd", "JST": "Japan-standaardtyd", "ADT": "Atlantiese dagligtyd", "HAT": "Newfoundland-dagligtyd", "EST": "Oostelike standaardtyd", "BT": "Bhoetan-tyd", "CDT": "Sentrale dagligtyd", "TMT": "Turkmenistan-standaardtyd", "LHST": "Lord Howe-standaardtyd", "COST": "Colombië-somertyd", "ChST": "Chamorro-standaardtyd", "OESZ": "Oos-Europese somertyd", "HKST": "Hongkong-somertyd", "HNNOMX": "Noordwes-Meksiko-standaardtyd", "HEPMX": "Meksikaanse Pasifiese dagligtyd", "ACWDT": "Australiese sentraal-Westelike dagligtyd", "IST": "Indië-standaardtyd", "∅∅∅": "Peru-somertyd", "CHAST": "Chatham-standaardtyd", "MESZ": "Sentraal-Europese somertyd", "NZDT": "Nieu-Seeland-dagligtyd", "JDT": "Japan-dagligtyd", "GMT": "Greenwich-mediaantyd", "PDT": "Pasifiese dagligtyd", "HNCU": "Kuba-standaardtyd", "NZST": "Nieu-Seeland-standaardtyd", "AEST": "Australiese Oostelike standaardtyd", "AEDT": "Australiese Oostelike dagligtyd", "ACDT": "Australiese sentrale dagligtyd", "WESZ": "Wes-Europese somertyd", "CHADT": "Chatham-dagligtyd", "HEPM": "Sint-Pierre en Miquelon-dagligtyd", "ART": "Argentinië-standaardtyd", "EAT": "Oos-Afrika-tyd", "ECT": "Ecuador-tyd", "SGT": "Singapoer-standaardtyd", "HNPM": "Sint-Pierre en Miquelon-standaardtyd", "AWDT": "Australiese Westelike dagligtyd", "WIT": "Oos-Indonesië-tyd", "CLT": "Chili-standaardtyd"},
78 // Locale returns the current translators string locale
79 func (af *af) Locale() string {
83 // PluralsCardinal returns the list of cardinal plural rules associated with 'af'
84 func (af *af) PluralsCardinal() []locales.PluralRule {
85 return af.pluralsCardinal
88 // PluralsOrdinal returns the list of ordinal plural rules associated with 'af'
89 func (af *af) PluralsOrdinal() []locales.PluralRule {
90 return af.pluralsOrdinal
93 // PluralsRange returns the list of range plural rules associated with 'af'
94 func (af *af) PluralsRange() []locales.PluralRule {
95 return af.pluralsRange
98 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'af'
99 func (af *af) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
104 return locales.PluralRuleOne
107 return locales.PluralRuleOther
110 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'af'
111 func (af *af) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
112 return locales.PluralRuleOther
115 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'af'
116 func (af *af) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
117 return locales.PluralRuleOther
120 // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
121 func (af *af) MonthAbbreviated(month time.Month) string {
122 return af.monthsAbbreviated[month]
125 // MonthsAbbreviated returns the locales abbreviated months
126 func (af *af) MonthsAbbreviated() []string {
127 return af.monthsAbbreviated[1:]
130 // MonthNarrow returns the locales narrow month given the 'month' provided
131 func (af *af) MonthNarrow(month time.Month) string {
132 return af.monthsNarrow[month]
135 // MonthsNarrow returns the locales narrow months
136 func (af *af) MonthsNarrow() []string {
137 return af.monthsNarrow[1:]
140 // MonthWide returns the locales wide month given the 'month' provided
141 func (af *af) MonthWide(month time.Month) string {
142 return af.monthsWide[month]
145 // MonthsWide returns the locales wide months
146 func (af *af) MonthsWide() []string {
147 return af.monthsWide[1:]
150 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
151 func (af *af) WeekdayAbbreviated(weekday time.Weekday) string {
152 return af.daysAbbreviated[weekday]
155 // WeekdaysAbbreviated returns the locales abbreviated weekdays
156 func (af *af) WeekdaysAbbreviated() []string {
157 return af.daysAbbreviated
160 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
161 func (af *af) WeekdayNarrow(weekday time.Weekday) string {
162 return af.daysNarrow[weekday]
165 // WeekdaysNarrow returns the locales narrow weekdays
166 func (af *af) WeekdaysNarrow() []string {
170 // WeekdayShort returns the locales short weekday given the 'weekday' provided
171 func (af *af) WeekdayShort(weekday time.Weekday) string {
172 return af.daysShort[weekday]
175 // WeekdaysShort returns the locales short weekdays
176 func (af *af) WeekdaysShort() []string {
180 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
181 func (af *af) WeekdayWide(weekday time.Weekday) string {
182 return af.daysWide[weekday]
185 // WeekdaysWide returns the locales wide weekdays
186 func (af *af) WeekdaysWide() []string {
190 // Decimal returns the decimal point of number
191 func (af *af) Decimal() string {
195 // Group returns the group of number
196 func (af *af) Group() string {
200 // Group returns the minus sign of number
201 func (af *af) Minus() string {
205 // FmtNumber returns 'num' with digits/precision of 'v' for 'af' and handles both Whole and Real numbers based on 'v'
206 func (af *af) FmtNumber(num float64, v uint64) string {
208 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
209 l := len(s) + 2 + 2*len(s[:len(s)-int(v)-1])/3
212 b := make([]byte, 0, l)
214 for i := len(s) - 1; i >= 0; i-- {
217 b = append(b, af.decimal[0])
224 for j := len(af.group) - 1; j >= 0; j-- {
225 b = append(b, af.group[j])
237 b = append(b, af.minus[0])
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]
248 // FmtPercent returns 'num' with digits/precision of 'v' for 'af' and handles both Whole and Real numbers based on 'v'
249 // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
250 func (af *af) FmtPercent(num float64, v uint64) string {
251 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
253 b := make([]byte, 0, l)
255 for i := len(s) - 1; i >= 0; i-- {
258 b = append(b, af.decimal[0])
266 b = append(b, af.minus[0])
270 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
271 b[i], b[j] = b[j], b[i]
274 b = append(b, af.percent...)
279 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'af'
280 func (af *af) FmtCurrency(num float64, v uint64, currency currency.Type) string {
282 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
283 symbol := af.currencies[currency]
284 l := len(s) + len(symbol) + 2 + 2*len(s[:len(s)-int(v)-1])/3
287 b := make([]byte, 0, l)
289 for i := len(s) - 1; i >= 0; i-- {
292 b = append(b, af.decimal[0])
299 for j := len(af.group) - 1; j >= 0; j-- {
300 b = append(b, af.group[j])
311 for j := len(symbol) - 1; j >= 0; j-- {
312 b = append(b, symbol[j])
316 b = append(b, af.minus[0])
320 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
321 b[i], b[j] = b[j], b[i]
327 b = append(b, af.decimal...)
330 for i := 0; i < 2-int(v); i++ {
338 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'af'
339 // in accounting notation.
340 func (af *af) FmtAccounting(num float64, v uint64, currency currency.Type) string {
342 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
343 symbol := af.currencies[currency]
344 l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
347 b := make([]byte, 0, l)
349 for i := len(s) - 1; i >= 0; i-- {
352 b = append(b, af.decimal[0])
359 for j := len(af.group) - 1; j >= 0; j-- {
360 b = append(b, af.group[j])
373 for j := len(symbol) - 1; j >= 0; j-- {
374 b = append(b, symbol[j])
377 b = append(b, af.currencyNegativePrefix[0])
381 for j := len(symbol) - 1; j >= 0; j-- {
382 b = append(b, symbol[j])
388 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
389 b[i], b[j] = b[j], b[i]
395 b = append(b, af.decimal...)
398 for i := 0; i < 2-int(v); i++ {
404 b = append(b, af.currencyNegativeSuffix...)
410 // FmtDateShort returns the short date representation of 't' for 'af'
411 func (af *af) FmtDateShort(t time.Time) string {
413 b := make([]byte, 0, 32)
416 b = strconv.AppendInt(b, int64(t.Year()), 10)
418 b = strconv.AppendInt(b, int64(-t.Year()), 10)
421 b = append(b, []byte{0x2d}...)
427 b = strconv.AppendInt(b, int64(t.Month()), 10)
429 b = append(b, []byte{0x2d}...)
435 b = strconv.AppendInt(b, int64(t.Day()), 10)
440 // FmtDateMedium returns the medium date representation of 't' for 'af'
441 func (af *af) FmtDateMedium(t time.Time) string {
443 b := make([]byte, 0, 32)
449 b = strconv.AppendInt(b, int64(t.Day()), 10)
450 b = append(b, []byte{0x20}...)
451 b = append(b, af.monthsAbbreviated[t.Month()]...)
452 b = append(b, []byte{0x20}...)
455 b = strconv.AppendInt(b, int64(t.Year()), 10)
457 b = strconv.AppendInt(b, int64(-t.Year()), 10)
463 // FmtDateLong returns the long date representation of 't' for 'af'
464 func (af *af) FmtDateLong(t time.Time) string {
466 b := make([]byte, 0, 32)
472 b = strconv.AppendInt(b, int64(t.Day()), 10)
473 b = append(b, []byte{0x20}...)
474 b = append(b, af.monthsWide[t.Month()]...)
475 b = append(b, []byte{0x20}...)
478 b = strconv.AppendInt(b, int64(t.Year()), 10)
480 b = strconv.AppendInt(b, int64(-t.Year()), 10)
486 // FmtDateFull returns the full date representation of 't' for 'af'
487 func (af *af) FmtDateFull(t time.Time) string {
489 b := make([]byte, 0, 32)
491 b = append(b, af.daysWide[t.Weekday()]...)
492 b = append(b, []byte{0x2c, 0x20}...)
498 b = strconv.AppendInt(b, int64(t.Day()), 10)
499 b = append(b, []byte{0x20}...)
500 b = append(b, af.monthsWide[t.Month()]...)
501 b = append(b, []byte{0x20}...)
504 b = strconv.AppendInt(b, int64(t.Year()), 10)
506 b = strconv.AppendInt(b, int64(-t.Year()), 10)
512 // FmtTimeShort returns the short time representation of 't' for 'af'
513 func (af *af) FmtTimeShort(t time.Time) string {
515 b := make([]byte, 0, 32)
521 b = strconv.AppendInt(b, int64(t.Hour()), 10)
522 b = append(b, af.timeSeparator...)
528 b = strconv.AppendInt(b, int64(t.Minute()), 10)
533 // FmtTimeMedium returns the medium time representation of 't' for 'af'
534 func (af *af) FmtTimeMedium(t time.Time) string {
536 b := make([]byte, 0, 32)
542 b = strconv.AppendInt(b, int64(t.Hour()), 10)
543 b = append(b, af.timeSeparator...)
549 b = strconv.AppendInt(b, int64(t.Minute()), 10)
550 b = append(b, af.timeSeparator...)
556 b = strconv.AppendInt(b, int64(t.Second()), 10)
561 // FmtTimeLong returns the long time representation of 't' for 'af'
562 func (af *af) FmtTimeLong(t time.Time) string {
564 b := make([]byte, 0, 32)
570 b = strconv.AppendInt(b, int64(t.Hour()), 10)
571 b = append(b, af.timeSeparator...)
577 b = strconv.AppendInt(b, int64(t.Minute()), 10)
578 b = append(b, af.timeSeparator...)
584 b = strconv.AppendInt(b, int64(t.Second()), 10)
585 b = append(b, []byte{0x20}...)
593 // FmtTimeFull returns the full time representation of 't' for 'af'
594 func (af *af) FmtTimeFull(t time.Time) string {
596 b := make([]byte, 0, 32)
602 b = strconv.AppendInt(b, int64(t.Hour()), 10)
603 b = append(b, af.timeSeparator...)
609 b = strconv.AppendInt(b, int64(t.Minute()), 10)
610 b = append(b, af.timeSeparator...)
616 b = strconv.AppendInt(b, int64(t.Second()), 10)
617 b = append(b, []byte{0x20}...)
621 if btz, ok := af.timezones[tz]; ok {
622 b = append(b, btz...)