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 currencyPositiveSuffix string
27 currencyNegativePrefix string
28 currencyNegativeSuffix string
29 monthsAbbreviated []string
32 daysAbbreviated []string
36 periodsAbbreviated []string
37 periodsNarrow []string
40 erasAbbreviated []string
43 timezones map[string]string
46 // New returns a new instance of translator for the 'eo' locale
47 func New() locales.Translator {
50 pluralsCardinal: []locales.PluralRule{2, 6},
60 currencies: []string{"ADP", "AED", "AFA", "AFN", "ALK", "ALL", "AMD", "ANG", "AOA", "AOK", "AON", "AOR", "ARA", "ARL", "ARM", "ARP", "ARS", "ATS", "AU$", "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", "ILS", "₹", "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", "MX$", "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", "฿", "TJR", "TJS", "TMM", "TMT", "TND", "TOP", "TPE", "TRL", "₺", "TTD", "NT$", "TZS", "UAH", "UAK", "UGS", "UGX", "US$", "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"},
61 currencyPositivePrefix: " ",
62 currencyPositiveSuffix: "K",
63 currencyNegativePrefix: " ",
64 currencyNegativeSuffix: "K",
65 monthsAbbreviated: []string{"", "jan", "feb", "mar", "apr", "maj", "jun", "jul", "aŭg", "sep", "okt", "nov", "dec"},
66 monthsNarrow: []string{"", "J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"},
67 monthsWide: []string{"", "januaro", "februaro", "marto", "aprilo", "majo", "junio", "julio", "aŭgusto", "septembro", "oktobro", "novembro", "decembro"},
68 daysAbbreviated: []string{"di", "lu", "ma", "me", "ĵa", "ve", "sa"},
69 daysNarrow: []string{"D", "L", "M", "M", "Ĵ", "V", "S"},
70 daysWide: []string{"dimanĉo", "lundo", "mardo", "merkredo", "ĵaŭdo", "vendredo", "sabato"},
71 periodsAbbreviated: []string{"atm", "ptm"},
72 periodsNarrow: []string{"a", "p"},
73 periodsWide: []string{"atm", "ptm"},
74 erasAbbreviated: []string{"aK", "pK"},
75 erasNarrow: []string{"aK", "pK"},
76 erasWide: []string{"aK", "pK"},
77 timezones: map[string]string{"HENOMX": "HENOMX", "WEZ": "okcidenta eŭropa norma tempo", "OEZ": "orienta eŭropa norma tempo", "CLT": "CLT", "EDT": "orienta nord-amerika somera tempo", "PDT": "pacifika nord-amerika somera tempo", "AWST": "okcidenta aŭstralia norma tempo", "HADT": "HADT", "AST": "atlantika nord-amerika norma tempo", "EAT": "orienta afrika tempo", "HNT": "HNT", "EST": "orienta nord-amerika norma tempo", "HEPMX": "HEPMX", "HNCU": "HNCU", "CST": "centra nord-amerika norma tempo", "CAT": "centra afrika tempo", "JST": "japana norma tempo", "AEDT": "orienta aŭstralia somera tempo", "HEEG": "HEEG", "ACST": "centra aŭstralia norma tempo", "AKST": "AKST", "PST": "pacifika nord-amerika norma tempo", "BT": "BT", "NZST": "NZST", "∅∅∅": "∅∅∅", "CHAST": "CHAST", "VET": "VET", "GFT": "GFT", "WESZ": "okcidenta eŭropa somera tempo", "CHADT": "CHADT", "LHDT": "LHDT", "TMST": "TMST", "HKST": "HKST", "SRT": "SRT", "HAST": "HAST", "HEPM": "HEPM", "AWDT": "okcidenta aŭstralia somera tempo", "ACWDT": "centrokcidenta aŭstralia somera tempo", "HNNOMX": "HNNOMX", "OESZ": "orienta eŭropa somera tempo", "IST": "barata tempo", "WIB": "okcidenta indonezia tempo", "HNPM": "HNPM", "HAT": "HAT", "ECT": "ECT", "HECU": "HECU", "WIT": "orienta indonezia tempo", "JDT": "japana somera tempo", "ARST": "ARST", "HNOG": "HNOG", "WAT": "okcidenta afrika norma tempo", "HNPMX": "HNPMX", "GMT": "universala tempo kunordigita", "AKDT": "AKDT", "ADT": "atlantika nord-amerika somera tempo", "COT": "COT", "NZDT": "NZDT", "WART": "WART", "ACWST": "centrokcidenta aŭstralia norma tempo", "SGT": "SGT", "MDT": "MDT", "MYT": "MYT", "SAST": "suda afrika tempo", "ACDT": "centra aŭstralia somera tempo", "LHST": "LHST", "WITA": "centra indonezia tempo", "UYST": "UYST", "MESZ": "centra eŭropa somera tempo", "AEST": "orienta aŭstralia norma tempo", "HEOG": "HEOG", "WAST": "okcidenta afrika somera tempo", "CLST": "CLST", "MST": "MST", "CDT": "centra nord-amerika somera tempo", "COST": "COST", "ChST": "ChST", "UYT": "UYT", "MEZ": "centra eŭropa norma tempo", "WARST": "WARST", "ART": "ART", "HNEG": "HNEG", "HKT": "HKT", "GYT": "GYT", "BOT": "BOT", "TMT": "TMT"},
81 // Locale returns the current translators string locale
82 func (eo *eo) Locale() string {
86 // PluralsCardinal returns the list of cardinal plural rules associated with 'eo'
87 func (eo *eo) PluralsCardinal() []locales.PluralRule {
88 return eo.pluralsCardinal
91 // PluralsOrdinal returns the list of ordinal plural rules associated with 'eo'
92 func (eo *eo) PluralsOrdinal() []locales.PluralRule {
93 return eo.pluralsOrdinal
96 // PluralsRange returns the list of range plural rules associated with 'eo'
97 func (eo *eo) PluralsRange() []locales.PluralRule {
98 return eo.pluralsRange
101 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'eo'
102 func (eo *eo) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
107 return locales.PluralRuleOne
110 return locales.PluralRuleOther
113 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'eo'
114 func (eo *eo) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
115 return locales.PluralRuleUnknown
118 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'eo'
119 func (eo *eo) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
120 return locales.PluralRuleUnknown
123 // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
124 func (eo *eo) MonthAbbreviated(month time.Month) string {
125 return eo.monthsAbbreviated[month]
128 // MonthsAbbreviated returns the locales abbreviated months
129 func (eo *eo) MonthsAbbreviated() []string {
130 return eo.monthsAbbreviated[1:]
133 // MonthNarrow returns the locales narrow month given the 'month' provided
134 func (eo *eo) MonthNarrow(month time.Month) string {
135 return eo.monthsNarrow[month]
138 // MonthsNarrow returns the locales narrow months
139 func (eo *eo) MonthsNarrow() []string {
140 return eo.monthsNarrow[1:]
143 // MonthWide returns the locales wide month given the 'month' provided
144 func (eo *eo) MonthWide(month time.Month) string {
145 return eo.monthsWide[month]
148 // MonthsWide returns the locales wide months
149 func (eo *eo) MonthsWide() []string {
150 return eo.monthsWide[1:]
153 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
154 func (eo *eo) WeekdayAbbreviated(weekday time.Weekday) string {
155 return eo.daysAbbreviated[weekday]
158 // WeekdaysAbbreviated returns the locales abbreviated weekdays
159 func (eo *eo) WeekdaysAbbreviated() []string {
160 return eo.daysAbbreviated
163 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
164 func (eo *eo) WeekdayNarrow(weekday time.Weekday) string {
165 return eo.daysNarrow[weekday]
168 // WeekdaysNarrow returns the locales narrow weekdays
169 func (eo *eo) WeekdaysNarrow() []string {
173 // WeekdayShort returns the locales short weekday given the 'weekday' provided
174 func (eo *eo) WeekdayShort(weekday time.Weekday) string {
175 return eo.daysShort[weekday]
178 // WeekdaysShort returns the locales short weekdays
179 func (eo *eo) WeekdaysShort() []string {
183 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
184 func (eo *eo) WeekdayWide(weekday time.Weekday) string {
185 return eo.daysWide[weekday]
188 // WeekdaysWide returns the locales wide weekdays
189 func (eo *eo) WeekdaysWide() []string {
193 // Decimal returns the decimal point of number
194 func (eo *eo) Decimal() string {
198 // Group returns the group of number
199 func (eo *eo) Group() string {
203 // Group returns the minus sign of number
204 func (eo *eo) Minus() string {
208 // FmtNumber returns 'num' with digits/precision of 'v' for 'eo' and handles both Whole and Real numbers based on 'v'
209 func (eo *eo) FmtNumber(num float64, v uint64) string {
211 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
212 l := len(s) + 4 + 2*len(s[:len(s)-int(v)-1])/3
215 b := make([]byte, 0, l)
217 for i := len(s) - 1; i >= 0; i-- {
220 b = append(b, eo.decimal[0])
227 for j := len(eo.group) - 1; j >= 0; j-- {
228 b = append(b, eo.group[j])
240 for j := len(eo.minus) - 1; j >= 0; j-- {
241 b = append(b, eo.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 'eo' 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 (eo *eo) 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 b = append(b, eo.decimal[0])
271 for j := len(eo.minus) - 1; j >= 0; j-- {
272 b = append(b, eo.minus[j])
277 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
278 b[i], b[j] = b[j], b[i]
281 b = append(b, eo.percent...)
286 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'eo'
287 func (eo *eo) FmtCurrency(num float64, v uint64, currency currency.Type) string {
289 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
290 symbol := eo.currencies[currency]
291 l := len(s) + len(symbol) + 7
293 b := make([]byte, 0, l)
295 for i := len(s) - 1; i >= 0; i-- {
298 b = append(b, eo.decimal[0])
305 for j := len(symbol) - 1; j >= 0; j-- {
306 b = append(b, symbol[j])
309 for j := len(eo.currencyPositivePrefix) - 1; j >= 0; j-- {
310 b = append(b, eo.currencyPositivePrefix[j])
314 for j := len(eo.minus) - 1; j >= 0; j-- {
315 b = append(b, eo.minus[j])
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]
324 b = append(b, eo.currencyPositiveSuffix...)
329 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'eo'
330 // in accounting notation.
331 func (eo *eo) FmtAccounting(num float64, v uint64, currency currency.Type) string {
333 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
334 symbol := eo.currencies[currency]
335 l := len(s) + len(symbol) + 7
337 b := make([]byte, 0, l)
339 for i := len(s) - 1; i >= 0; i-- {
342 b = append(b, eo.decimal[0])
351 for j := len(symbol) - 1; j >= 0; j-- {
352 b = append(b, symbol[j])
355 for j := len(eo.currencyNegativePrefix) - 1; j >= 0; j-- {
356 b = append(b, eo.currencyNegativePrefix[j])
359 for j := len(eo.minus) - 1; j >= 0; j-- {
360 b = append(b, eo.minus[j])
365 for j := len(symbol) - 1; j >= 0; j-- {
366 b = append(b, symbol[j])
369 for j := len(eo.currencyPositivePrefix) - 1; j >= 0; j-- {
370 b = append(b, eo.currencyPositivePrefix[j])
376 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
377 b[i], b[j] = b[j], b[i]
381 b = append(b, eo.currencyNegativeSuffix...)
384 b = append(b, eo.currencyPositiveSuffix...)
390 // FmtDateShort returns the short date representation of 't' for 'eo'
391 func (eo *eo) FmtDateShort(t time.Time) string {
393 b := make([]byte, 0, 32)
396 b = append(b, strconv.Itoa(t.Year())[2:]...)
398 b = append(b, strconv.Itoa(t.Year())[1:]...)
401 b = append(b, []byte{0x2d}...)
407 b = strconv.AppendInt(b, int64(t.Month()), 10)
409 b = append(b, []byte{0x2d}...)
415 b = strconv.AppendInt(b, int64(t.Day()), 10)
420 // FmtDateMedium returns the medium date representation of 't' for 'eo'
421 func (eo *eo) FmtDateMedium(t time.Time) string {
423 b := make([]byte, 0, 32)
426 b = strconv.AppendInt(b, int64(t.Year()), 10)
428 b = strconv.AppendInt(b, int64(-t.Year()), 10)
431 b = append(b, []byte{0x2d}...)
432 b = append(b, eo.monthsAbbreviated[t.Month()]...)
433 b = append(b, []byte{0x2d}...)
439 b = strconv.AppendInt(b, int64(t.Day()), 10)
444 // FmtDateLong returns the long date representation of 't' for 'eo'
445 func (eo *eo) FmtDateLong(t time.Time) string {
447 b := make([]byte, 0, 32)
450 b = strconv.AppendInt(b, int64(t.Year()), 10)
452 b = strconv.AppendInt(b, int64(-t.Year()), 10)
455 b = append(b, []byte{0x2d}...)
456 b = append(b, eo.monthsWide[t.Month()]...)
457 b = append(b, []byte{0x2d}...)
463 b = strconv.AppendInt(b, int64(t.Day()), 10)
468 // FmtDateFull returns the full date representation of 't' for 'eo'
469 func (eo *eo) FmtDateFull(t time.Time) string {
471 b := make([]byte, 0, 32)
473 b = append(b, eo.daysWide[t.Weekday()]...)
474 b = append(b, []byte{0x2c, 0x20}...)
475 b = strconv.AppendInt(b, int64(t.Day()), 10)
476 b = append(b, []byte{0x2d, 0x61}...)
477 b = append(b, []byte{0x20, 0x64, 0x65}...)
478 b = append(b, []byte{0x20}...)
479 b = append(b, eo.monthsWide[t.Month()]...)
480 b = append(b, []byte{0x20}...)
483 b = strconv.AppendInt(b, int64(t.Year()), 10)
485 b = strconv.AppendInt(b, int64(-t.Year()), 10)
491 // FmtTimeShort returns the short time representation of 't' for 'eo'
492 func (eo *eo) FmtTimeShort(t time.Time) string {
494 b := make([]byte, 0, 32)
500 b = strconv.AppendInt(b, int64(t.Hour()), 10)
501 b = append(b, eo.timeSeparator...)
507 b = strconv.AppendInt(b, int64(t.Minute()), 10)
512 // FmtTimeMedium returns the medium time representation of 't' for 'eo'
513 func (eo *eo) FmtTimeMedium(t time.Time) string {
515 b := make([]byte, 0, 32)
521 b = strconv.AppendInt(b, int64(t.Hour()), 10)
522 b = append(b, eo.timeSeparator...)
528 b = strconv.AppendInt(b, int64(t.Minute()), 10)
529 b = append(b, eo.timeSeparator...)
535 b = strconv.AppendInt(b, int64(t.Second()), 10)
540 // FmtTimeLong returns the long time representation of 't' for 'eo'
541 func (eo *eo) FmtTimeLong(t time.Time) string {
543 b := make([]byte, 0, 32)
549 b = strconv.AppendInt(b, int64(t.Hour()), 10)
550 b = append(b, eo.timeSeparator...)
556 b = strconv.AppendInt(b, int64(t.Minute()), 10)
557 b = append(b, eo.timeSeparator...)
563 b = strconv.AppendInt(b, int64(t.Second()), 10)
564 b = append(b, []byte{0x20}...)
572 // FmtTimeFull returns the full time representation of 't' for 'eo'
573 func (eo *eo) FmtTimeFull(t time.Time) string {
575 b := make([]byte, 0, 32)
577 b = strconv.AppendInt(b, int64(t.Hour()), 10)
578 b = append(b, []byte{0x2d, 0x61}...)
579 b = append(b, []byte{0x20, 0x68, 0x6f, 0x72, 0x6f}...)
580 b = append(b, []byte{0x20, 0x6b, 0x61, 0x6a}...)
581 b = append(b, []byte{0x20}...)
582 b = strconv.AppendInt(b, int64(t.Minute()), 10)
583 b = append(b, eo.timeSeparator...)
589 b = strconv.AppendInt(b, int64(t.Second()), 10)
590 b = append(b, []byte{0x20}...)
594 if btz, ok := eo.timezones[tz]; ok {
595 b = append(b, btz...)