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 currencyPositiveSuffix string
26 currencyNegativePrefix string
27 currencyNegativeSuffix string
28 monthsAbbreviated []string
31 daysAbbreviated []string
35 periodsAbbreviated []string
36 periodsNarrow []string
39 erasAbbreviated []string
42 timezones map[string]string
45 // New returns a new instance of translator for the 'yav' locale
46 func New() locales.Translator {
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", "BYN", "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 currencyPositiveSuffix: " ",
57 currencyNegativePrefix: "(",
58 currencyNegativeSuffix: " )",
59 monthsAbbreviated: []string{"", "o.1", "o.2", "o.3", "o.4", "o.5", "o.6", "o.7", "o.8", "o.9", "o.10", "o.11", "o.12"},
60 monthsWide: []string{"", "pikítíkítie, oólí ú kutúan", "siɛyɛ́, oóli ú kándíɛ", "ɔnsúmbɔl, oóli ú kátátúɛ", "mesiŋ, oóli ú kénie", "ensil, oóli ú kátánuɛ", "ɔsɔn", "efute", "pisuyú", "imɛŋ i puɔs", "imɛŋ i putúk,oóli ú kátíɛ", "makandikɛ", "pilɔndɔ́"},
61 daysAbbreviated: []string{"sd", "md", "mw", "et", "kl", "fl", "ss"},
62 daysNarrow: []string{"s", "m", "m", "e", "k", "f", "s"},
63 daysWide: []string{"sɔ́ndiɛ", "móndie", "muányáŋmóndie", "metúkpíápɛ", "kúpélimetúkpiapɛ", "feléte", "séselé"},
64 periodsAbbreviated: []string{"kiɛmɛ́ɛm", "kisɛ́ndɛ"},
65 periodsWide: []string{"kiɛmɛ́ɛm", "kisɛ́ndɛ"},
66 erasAbbreviated: []string{"k.Y.", "+J.C."},
67 erasNarrow: []string{"", ""},
68 erasWide: []string{"katikupíen Yésuse", "ékélémkúnupíén n"},
69 timezones: map[string]string{"AKDT": "AKDT", "ChST": "ChST", "HAT": "HAT", "ADT": "ADT", "SAST": "SAST", "HNT": "HNT", "GYT": "GYT", "WESZ": "WESZ", "MYT": "MYT", "HADT": "HADT", "WITA": "WITA", "AEDT": "AEDT", "EAT": "EAT", "WAT": "WAT", "BT": "BT", "UYT": "UYT", "HAST": "HAST", "∅∅∅": "∅∅∅", "LHST": "LHST", "AEST": "AEST", "AKST": "AKST", "GMT": "GMT", "HNPM": "HNPM", "CST": "CST", "OESZ": "OESZ", "HNNOMX": "HNNOMX", "COST": "COST", "UYST": "UYST", "WIT": "WIT", "NZDT": "NZDT", "WARST": "WARST", "MST": "MST", "JST": "JST", "HEOG": "HEOG", "HEPMX": "HEPMX", "PST": "PST", "CDT": "CDT", "TMST": "TMST", "OEZ": "OEZ", "ARST": "ARST", "ECT": "ECT", "WEZ": "WEZ", "CHAST": "CHAST", "HECU": "HECU", "TMT": "TMT", "WART": "WART", "JDT": "JDT", "HNEG": "HNEG", "CLST": "CLST", "WIB": "WIB", "AWST": "AWST", "AWDT": "AWDT", "HENOMX": "HENOMX", "PDT": "PDT", "HKST": "HKST", "COT": "COT", "HNCU": "HNCU", "NZST": "NZST", "HEEG": "HEEG", "ACST": "ACST", "ACDT": "ACDT", "CHADT": "CHADT", "MDT": "MDT", "CLT": "CLT", "WAST": "WAST", "EST": "EST", "SRT": "SRT", "ACWDT": "ACWDT", "MEZ": "MEZ", "MESZ": "MESZ", "AST": "AST", "CAT": "CAT", "HNPMX": "HNPMX", "BOT": "BOT", "LHDT": "LHDT", "ART": "ART", "GFT": "GFT", "EDT": "EDT", "SGT": "SGT", "ACWST": "ACWST", "IST": "IST", "HNOG": "HNOG", "HKT": "HKT", "HEPM": "HEPM", "VET": "VET"},
73 // Locale returns the current translators string locale
74 func (yav *yav) Locale() string {
78 // PluralsCardinal returns the list of cardinal plural rules associated with 'yav'
79 func (yav *yav) PluralsCardinal() []locales.PluralRule {
80 return yav.pluralsCardinal
83 // PluralsOrdinal returns the list of ordinal plural rules associated with 'yav'
84 func (yav *yav) PluralsOrdinal() []locales.PluralRule {
85 return yav.pluralsOrdinal
88 // PluralsRange returns the list of range plural rules associated with 'yav'
89 func (yav *yav) PluralsRange() []locales.PluralRule {
90 return yav.pluralsRange
93 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'yav'
94 func (yav *yav) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
95 return locales.PluralRuleUnknown
98 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'yav'
99 func (yav *yav) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
100 return locales.PluralRuleUnknown
103 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'yav'
104 func (yav *yav) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
105 return locales.PluralRuleUnknown
108 // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
109 func (yav *yav) MonthAbbreviated(month time.Month) string {
110 return yav.monthsAbbreviated[month]
113 // MonthsAbbreviated returns the locales abbreviated months
114 func (yav *yav) MonthsAbbreviated() []string {
115 return yav.monthsAbbreviated[1:]
118 // MonthNarrow returns the locales narrow month given the 'month' provided
119 func (yav *yav) MonthNarrow(month time.Month) string {
120 return yav.monthsNarrow[month]
123 // MonthsNarrow returns the locales narrow months
124 func (yav *yav) MonthsNarrow() []string {
128 // MonthWide returns the locales wide month given the 'month' provided
129 func (yav *yav) MonthWide(month time.Month) string {
130 return yav.monthsWide[month]
133 // MonthsWide returns the locales wide months
134 func (yav *yav) MonthsWide() []string {
135 return yav.monthsWide[1:]
138 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
139 func (yav *yav) WeekdayAbbreviated(weekday time.Weekday) string {
140 return yav.daysAbbreviated[weekday]
143 // WeekdaysAbbreviated returns the locales abbreviated weekdays
144 func (yav *yav) WeekdaysAbbreviated() []string {
145 return yav.daysAbbreviated
148 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
149 func (yav *yav) WeekdayNarrow(weekday time.Weekday) string {
150 return yav.daysNarrow[weekday]
153 // WeekdaysNarrow returns the locales narrow weekdays
154 func (yav *yav) WeekdaysNarrow() []string {
155 return yav.daysNarrow
158 // WeekdayShort returns the locales short weekday given the 'weekday' provided
159 func (yav *yav) WeekdayShort(weekday time.Weekday) string {
160 return yav.daysShort[weekday]
163 // WeekdaysShort returns the locales short weekdays
164 func (yav *yav) WeekdaysShort() []string {
168 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
169 func (yav *yav) WeekdayWide(weekday time.Weekday) string {
170 return yav.daysWide[weekday]
173 // WeekdaysWide returns the locales wide weekdays
174 func (yav *yav) WeekdaysWide() []string {
178 // Decimal returns the decimal point of number
179 func (yav *yav) Decimal() string {
183 // Group returns the group of number
184 func (yav *yav) Group() string {
188 // Group returns the minus sign of number
189 func (yav *yav) Minus() string {
193 // FmtNumber returns 'num' with digits/precision of 'v' for 'yav' and handles both Whole and Real numbers based on 'v'
194 func (yav *yav) FmtNumber(num float64, v uint64) string {
196 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
197 l := len(s) + 1 + 2*len(s[:len(s)-int(v)-1])/3
200 b := make([]byte, 0, l)
202 for i := len(s) - 1; i >= 0; i-- {
205 b = append(b, yav.decimal[0])
212 for j := len(yav.group) - 1; j >= 0; j-- {
213 b = append(b, yav.group[j])
225 b = append(b, yav.minus[0])
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]
236 // FmtPercent returns 'num' with digits/precision of 'v' for 'yav' and handles both Whole and Real numbers based on 'v'
237 // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
238 func (yav *yav) FmtPercent(num float64, v uint64) string {
239 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
241 b := make([]byte, 0, l)
243 for i := len(s) - 1; i >= 0; i-- {
246 b = append(b, yav.decimal[0])
254 b = append(b, yav.minus[0])
258 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
259 b[i], b[j] = b[j], b[i]
262 b = append(b, yav.percent...)
267 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'yav'
268 func (yav *yav) FmtCurrency(num float64, v uint64, currency currency.Type) string {
270 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
271 symbol := yav.currencies[currency]
272 l := len(s) + len(symbol) + 3 + 2*len(s[:len(s)-int(v)-1])/3
275 b := make([]byte, 0, l)
277 for i := len(s) - 1; i >= 0; i-- {
280 b = append(b, yav.decimal[0])
287 for j := len(yav.group) - 1; j >= 0; j-- {
288 b = append(b, yav.group[j])
300 b = append(b, yav.minus[0])
304 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
305 b[i], b[j] = b[j], b[i]
311 b = append(b, yav.decimal...)
314 for i := 0; i < 2-int(v); i++ {
319 b = append(b, yav.currencyPositiveSuffix...)
321 b = append(b, symbol...)
326 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'yav'
327 // in accounting notation.
328 func (yav *yav) FmtAccounting(num float64, v uint64, currency currency.Type) string {
330 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
331 symbol := yav.currencies[currency]
332 l := len(s) + len(symbol) + 5 + 2*len(s[:len(s)-int(v)-1])/3
335 b := make([]byte, 0, l)
337 for i := len(s) - 1; i >= 0; i-- {
340 b = append(b, yav.decimal[0])
347 for j := len(yav.group) - 1; j >= 0; j-- {
348 b = append(b, yav.group[j])
361 b = append(b, yav.currencyNegativePrefix[0])
366 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
367 b[i], b[j] = b[j], b[i]
373 b = append(b, yav.decimal...)
376 for i := 0; i < 2-int(v); i++ {
382 b = append(b, yav.currencyNegativeSuffix...)
383 b = append(b, symbol...)
386 b = append(b, yav.currencyPositiveSuffix...)
387 b = append(b, symbol...)
393 // FmtDateShort returns the short date representation of 't' for 'yav'
394 func (yav *yav) FmtDateShort(t time.Time) string {
396 b := make([]byte, 0, 32)
398 b = strconv.AppendInt(b, int64(t.Day()), 10)
399 b = append(b, []byte{0x2f}...)
400 b = strconv.AppendInt(b, int64(t.Month()), 10)
401 b = append(b, []byte{0x2f}...)
404 b = strconv.AppendInt(b, int64(t.Year()), 10)
406 b = strconv.AppendInt(b, int64(-t.Year()), 10)
412 // FmtDateMedium returns the medium date representation of 't' for 'yav'
413 func (yav *yav) FmtDateMedium(t time.Time) string {
415 b := make([]byte, 0, 32)
417 b = strconv.AppendInt(b, int64(t.Day()), 10)
418 b = append(b, []byte{0x20}...)
419 b = append(b, yav.monthsAbbreviated[t.Month()]...)
420 b = append(b, []byte{0x20}...)
423 b = strconv.AppendInt(b, int64(t.Year()), 10)
425 b = strconv.AppendInt(b, int64(-t.Year()), 10)
431 // FmtDateLong returns the long date representation of 't' for 'yav'
432 func (yav *yav) FmtDateLong(t time.Time) string {
434 b := make([]byte, 0, 32)
436 b = strconv.AppendInt(b, int64(t.Day()), 10)
437 b = append(b, []byte{0x20}...)
438 b = append(b, yav.monthsWide[t.Month()]...)
439 b = append(b, []byte{0x20}...)
442 b = strconv.AppendInt(b, int64(t.Year()), 10)
444 b = strconv.AppendInt(b, int64(-t.Year()), 10)
450 // FmtDateFull returns the full date representation of 't' for 'yav'
451 func (yav *yav) FmtDateFull(t time.Time) string {
453 b := make([]byte, 0, 32)
455 b = append(b, yav.daysWide[t.Weekday()]...)
456 b = append(b, []byte{0x20}...)
457 b = strconv.AppendInt(b, int64(t.Day()), 10)
458 b = append(b, []byte{0x20}...)
459 b = append(b, yav.monthsWide[t.Month()]...)
460 b = append(b, []byte{0x20}...)
463 b = strconv.AppendInt(b, int64(t.Year()), 10)
465 b = strconv.AppendInt(b, int64(-t.Year()), 10)
471 // FmtTimeShort returns the short time representation of 't' for 'yav'
472 func (yav *yav) FmtTimeShort(t time.Time) string {
474 b := make([]byte, 0, 32)
480 b = strconv.AppendInt(b, int64(t.Hour()), 10)
481 b = append(b, yav.timeSeparator...)
487 b = strconv.AppendInt(b, int64(t.Minute()), 10)
492 // FmtTimeMedium returns the medium time representation of 't' for 'yav'
493 func (yav *yav) FmtTimeMedium(t time.Time) string {
495 b := make([]byte, 0, 32)
501 b = strconv.AppendInt(b, int64(t.Hour()), 10)
502 b = append(b, yav.timeSeparator...)
508 b = strconv.AppendInt(b, int64(t.Minute()), 10)
509 b = append(b, yav.timeSeparator...)
515 b = strconv.AppendInt(b, int64(t.Second()), 10)
520 // FmtTimeLong returns the long time representation of 't' for 'yav'
521 func (yav *yav) FmtTimeLong(t time.Time) string {
523 b := make([]byte, 0, 32)
529 b = strconv.AppendInt(b, int64(t.Hour()), 10)
530 b = append(b, yav.timeSeparator...)
536 b = strconv.AppendInt(b, int64(t.Minute()), 10)
537 b = append(b, yav.timeSeparator...)
543 b = strconv.AppendInt(b, int64(t.Second()), 10)
544 b = append(b, []byte{0x20}...)
552 // FmtTimeFull returns the full time representation of 't' for 'yav'
553 func (yav *yav) FmtTimeFull(t time.Time) string {
555 b := make([]byte, 0, 32)
561 b = strconv.AppendInt(b, int64(t.Hour()), 10)
562 b = append(b, yav.timeSeparator...)
568 b = strconv.AppendInt(b, int64(t.Minute()), 10)
569 b = append(b, yav.timeSeparator...)
575 b = strconv.AppendInt(b, int64(t.Second()), 10)
576 b = append(b, []byte{0x20}...)
580 if btz, ok := yav.timezones[tz]; ok {
581 b = append(b, btz...)