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 'ee' locale
45 func New() locales.Translator {
48 pluralsCardinal: []locales.PluralRule{2, 6},
52 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", "GH₵", "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", "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", "US$", "USN", "USS", "UYI", "UYP", "UYU", "UZS", "VEB", "VEF", "₫", "VNN", "VUV", "WST", "XAF", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "EC$", "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"},
53 currencyNegativePrefix: "(",
54 currencyNegativeSuffix: ")",
55 monthsAbbreviated: []string{"", "dzv", "dzd", "ted", "afɔ", "dam", "mas", "sia", "dea", "any", "kel", "ade", "dzm"},
56 monthsNarrow: []string{"", "d", "d", "t", "a", "d", "m", "s", "d", "a", "k", "a", "d"},
57 monthsWide: []string{"", "dzove", "dzodze", "tedoxe", "afɔfĩe", "dama", "masa", "siamlɔm", "deasiamime", "anyɔnyɔ", "kele", "adeɛmekpɔxe", "dzome"},
58 daysAbbreviated: []string{"kɔs", "dzo", "bla", "kuɖ", "yaw", "fiɖ", "mem"},
59 daysNarrow: []string{"k", "d", "b", "k", "y", "f", "m"},
60 daysShort: []string{"kɔs", "dzo", "bla", "kuɖ", "yaw", "fiɖ", "mem"},
61 daysWide: []string{"kɔsiɖa", "dzoɖa", "blaɖa", "kuɖa", "yawoɖa", "fiɖa", "memleɖa"},
62 periodsAbbreviated: []string{"ŋdi", "ɣetrɔ"},
63 periodsNarrow: []string{"ŋ", "ɣ"},
64 periodsWide: []string{"ŋdi", "ɣetrɔ"},
65 erasAbbreviated: []string{"hY", "Yŋ"},
66 erasNarrow: []string{"hY", "Yŋ"},
67 erasWide: []string{"Hafi Yesu Va Do ŋgɔ", "Yesu Ŋɔli"},
68 timezones: map[string]string{"SAST": "Anyiehe Africa gaƒoƒome", "CLST": "Tsile dzomeŋɔli gaƒoƒome", "TMST": "Tɛkmenistan dzomeŋɔli gaƒoƒome", "HADT": "Hawaii-Aleutia ŋkekeme gaƒoƒome", "WITA": "WITA", "IST": "IST", "COT": "Kolombia gaƒoƒoɖoanyime", "HAT": "Niufaunɖlanɖ ŋkekeme gaƒoƒome", "ChST": "ChST", "ART": "Argentina gaƒoƒoɖoanyime", "EST": "Ɣedzeƒe America gaƒoƒoɖoanyime", "SGT": "SGT", "CHAST": "CHAST", "HAST": "Hawaii-Aleutia gaƒoƒoɖoanyime", "WART": "Ɣetoɖoƒe Argentina gaƒoƒoɖoanyime", "HNEG": "Ɣedzeƒe Grinlanɖ gaƒoƒoɖoanyime", "HECU": "Kuba ŋkekeme gaƒoƒome", "AWST": "Ɣetoɖoƒe Australia gaƒoƒoɖoanyime", "MESZ": "Titina Europe ŋkekeme gaƒoƒome", "OEZ": "Ɣedzeƒe Europe gaƒoƒoɖoanyime", "WAT": "Ɣetoɖoƒe Afrika gaƒoƒoɖoanyime", "AKDT": "Alaska ŋkekeme gaƒoƒome", "PST": "Pacific gaƒoƒoɖoanyime", "HENOMX": "HENOMX", "MST": "America Todzidukɔwo ƒe gaƒoƒoɖoanyime", "BOT": "Bolivia gaƒoƒome", "AEDT": "Ɣedzeƒe Australia ŋkekeme gaƒoƒome", "HKT": "Hɔng Kɔng gaƒoƒoɖoanyi me", "ARST": "Argentina dzomeŋɔli gaƒoƒome", "WEZ": "Ɣetoɖoƒe Europe gaƒoƒoɖoanyime", "HEPMX": "HEPMX", "WIT": "WIT", "HNNOMX": "HNNOMX", "∅∅∅": "Azores dzomeŋɔli gaƒoƒome", "HEOG": "Ɣetoɖoƒe Grinlanɖ dzomeŋɔli gaƒoƒome", "AEST": "Ɣedzeƒe Australia gaƒoƒoɖoanyime", "CAT": "Titina Afrika gaƒoƒome", "MEZ": "Titina Europe gaƒoƒoɖoanyime", "OESZ": "Ɣedzeƒe Europe ŋkekeme gaƒoƒome", "MDT": "America Todzidukɔwo ƒe ŋkekme gaƒoƒome", "WAST": "Ɣetoɖoƒe Africa ŋkekeme gaƒoƒome", "AKST": "Alaska gaƒoƒoɖoanyime", "WESZ": "Ɣetoɖoƒe Europe ŋkekeme gaƒoƒome", "HNPM": "Saint Pierre kple Mikuelon gaƒoƒoɖoanyime", "CLT": "Tsile gaƒoƒoɖoanyime", "ACST": "Titina Australia gaƒoƒoɖoanyime", "HNPMX": "HNPMX", "CHADT": "CHADT", "BT": "BT", "SRT": "Suriname gaƒoƒome", "UYST": "Uruguai dzomeŋɔli gaƒoƒome", "HKST": "Hɔng Kɔng dzomeŋɔli gaƒoƒome", "JST": "Japan gaƒoƒoɖanyime", "LHDT": "LHDT", "HNOG": "Ɣetoɖoƒe Grinlanɖ gaƒoƒoɖoanyime", "AST": "Atlantic gaƒoƒoɖoanyime", "ADT": "Atlantic ŋkekeme gaƒoƒome", "HEEG": "Ɣedzeƒe Grinlanɖ dzomeŋɔli gaƒoƒome", "HNT": "Niufaunɖlanɖ gaƒoƒoɖoanyime", "WIB": "WIB", "UYT": "Uruguai gaƒoƒoɖoanyime", "WARST": "Ɣetoɖoƒe Argentina dzomeŋɔli gaƒoƒome", "COST": "Kolombia dzomeŋɔli gaƒoƒome", "PDT": "Pacific ŋkekme gaƒoƒome", "HNCU": "Kuba gaƒoƒoɖoanyime", "CST": "Titina America gaƒoƒoɖoanyime", "NZST": "NZST", "ACWDT": "Australia ɣetoɖofe ŋkekeme gaƒoƒome", "LHST": "LHST", "GFT": "Frentsi Guiana gaƒoƒome", "EDT": "Ɣedzeƒe America ŋkekeme gaƒoƒome", "GYT": "Gayana gaƒoƒome", "ACDT": "Titina Australia ŋkekeme gaƒoƒome", "ECT": "Ikuedɔ dzomeŋɔli gaƒoƒome", "CDT": "Titina America ŋkekeme gaƒoƒome", "TMT": "Tɛkmenistan gaƒoƒoɖoanyime", "VET": "Venezuela gaƒoƒome", "EAT": "Ɣedzeƒe Africa gaƒoƒome", "AWDT": "Ɣetoɖoƒe Australia ŋkekeme gaƒoƒome", "NZDT": "NZDT", "JDT": "Japan ŋkekeme gaƒoƒome", "GMT": "Greenwich gaƒoƒome", "HEPM": "Saint Pierre kple Mikuelon ŋkekeme gaƒoƒome", "ACWST": "Australia ɣetoɖofe gaƒoƒoɖoanyime", "MYT": "MYT"},
72 // Locale returns the current translators string locale
73 func (ee *ee) Locale() string {
77 // PluralsCardinal returns the list of cardinal plural rules associated with 'ee'
78 func (ee *ee) PluralsCardinal() []locales.PluralRule {
79 return ee.pluralsCardinal
82 // PluralsOrdinal returns the list of ordinal plural rules associated with 'ee'
83 func (ee *ee) PluralsOrdinal() []locales.PluralRule {
84 return ee.pluralsOrdinal
87 // PluralsRange returns the list of range plural rules associated with 'ee'
88 func (ee *ee) PluralsRange() []locales.PluralRule {
89 return ee.pluralsRange
92 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'ee'
93 func (ee *ee) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
98 return locales.PluralRuleOne
101 return locales.PluralRuleOther
104 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'ee'
105 func (ee *ee) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
106 return locales.PluralRuleUnknown
109 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'ee'
110 func (ee *ee) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
111 return locales.PluralRuleUnknown
114 // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
115 func (ee *ee) MonthAbbreviated(month time.Month) string {
116 return ee.monthsAbbreviated[month]
119 // MonthsAbbreviated returns the locales abbreviated months
120 func (ee *ee) MonthsAbbreviated() []string {
121 return ee.monthsAbbreviated[1:]
124 // MonthNarrow returns the locales narrow month given the 'month' provided
125 func (ee *ee) MonthNarrow(month time.Month) string {
126 return ee.monthsNarrow[month]
129 // MonthsNarrow returns the locales narrow months
130 func (ee *ee) MonthsNarrow() []string {
131 return ee.monthsNarrow[1:]
134 // MonthWide returns the locales wide month given the 'month' provided
135 func (ee *ee) MonthWide(month time.Month) string {
136 return ee.monthsWide[month]
139 // MonthsWide returns the locales wide months
140 func (ee *ee) MonthsWide() []string {
141 return ee.monthsWide[1:]
144 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
145 func (ee *ee) WeekdayAbbreviated(weekday time.Weekday) string {
146 return ee.daysAbbreviated[weekday]
149 // WeekdaysAbbreviated returns the locales abbreviated weekdays
150 func (ee *ee) WeekdaysAbbreviated() []string {
151 return ee.daysAbbreviated
154 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
155 func (ee *ee) WeekdayNarrow(weekday time.Weekday) string {
156 return ee.daysNarrow[weekday]
159 // WeekdaysNarrow returns the locales narrow weekdays
160 func (ee *ee) WeekdaysNarrow() []string {
164 // WeekdayShort returns the locales short weekday given the 'weekday' provided
165 func (ee *ee) WeekdayShort(weekday time.Weekday) string {
166 return ee.daysShort[weekday]
169 // WeekdaysShort returns the locales short weekdays
170 func (ee *ee) WeekdaysShort() []string {
174 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
175 func (ee *ee) WeekdayWide(weekday time.Weekday) string {
176 return ee.daysWide[weekday]
179 // WeekdaysWide returns the locales wide weekdays
180 func (ee *ee) WeekdaysWide() []string {
184 // Decimal returns the decimal point of number
185 func (ee *ee) Decimal() string {
189 // Group returns the group of number
190 func (ee *ee) Group() string {
194 // Group returns the minus sign of number
195 func (ee *ee) Minus() string {
199 // FmtNumber returns 'num' with digits/precision of 'v' for 'ee' and handles both Whole and Real numbers based on 'v'
200 func (ee *ee) FmtNumber(num float64, v uint64) string {
202 return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
205 // FmtPercent returns 'num' with digits/precision of 'v' for 'ee' 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 (ee *ee) FmtPercent(num float64, v uint64) string {
208 return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
211 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'ee'
212 func (ee *ee) FmtCurrency(num float64, v uint64, currency currency.Type) string {
214 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
215 symbol := ee.currencies[currency]
216 l := len(s) + len(symbol) + 0
219 b := make([]byte, 0, l)
221 for i := len(s) - 1; i >= 0; i-- {
224 b = append(b, ee.decimal[0])
231 b = append(b, ee.group[0])
241 for j := len(symbol) - 1; j >= 0; j-- {
242 b = append(b, symbol[j])
246 b = append(b, ee.minus[0])
250 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
251 b[i], b[j] = b[j], b[i]
257 b = append(b, ee.decimal...)
260 for i := 0; i < 2-int(v); i++ {
268 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'ee'
269 // in accounting notation.
270 func (ee *ee) FmtAccounting(num float64, v uint64, currency currency.Type) string {
272 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
273 symbol := ee.currencies[currency]
274 l := len(s) + len(symbol) + 2
277 b := make([]byte, 0, l)
279 for i := len(s) - 1; i >= 0; i-- {
282 b = append(b, ee.decimal[0])
289 b = append(b, ee.group[0])
301 for j := len(symbol) - 1; j >= 0; j-- {
302 b = append(b, symbol[j])
305 b = append(b, ee.currencyNegativePrefix[0])
309 for j := len(symbol) - 1; j >= 0; j-- {
310 b = append(b, symbol[j])
316 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
317 b[i], b[j] = b[j], b[i]
323 b = append(b, ee.decimal...)
326 for i := 0; i < 2-int(v); i++ {
332 b = append(b, ee.currencyNegativeSuffix...)
338 // FmtDateShort returns the short date representation of 't' for 'ee'
339 func (ee *ee) FmtDateShort(t time.Time) string {
341 b := make([]byte, 0, 32)
343 b = strconv.AppendInt(b, int64(t.Month()), 10)
344 b = append(b, []byte{0x2f}...)
345 b = strconv.AppendInt(b, int64(t.Day()), 10)
346 b = append(b, []byte{0x2f}...)
349 b = append(b, strconv.Itoa(t.Year())[2:]...)
351 b = append(b, strconv.Itoa(t.Year())[1:]...)
357 // FmtDateMedium returns the medium date representation of 't' for 'ee'
358 func (ee *ee) FmtDateMedium(t time.Time) string {
360 b := make([]byte, 0, 32)
362 b = append(b, ee.monthsAbbreviated[t.Month()]...)
363 b = append(b, []byte{0x20}...)
364 b = strconv.AppendInt(b, int64(t.Day()), 10)
365 b = append(b, []byte{0x20, 0x6c, 0x69, 0x61}...)
366 b = append(b, []byte{0x2c, 0x20}...)
369 b = strconv.AppendInt(b, int64(t.Year()), 10)
371 b = strconv.AppendInt(b, int64(-t.Year()), 10)
377 // FmtDateLong returns the long date representation of 't' for 'ee'
378 func (ee *ee) FmtDateLong(t time.Time) string {
380 b := make([]byte, 0, 32)
382 b = append(b, ee.monthsWide[t.Month()]...)
383 b = append(b, []byte{0x20}...)
384 b = strconv.AppendInt(b, int64(t.Day()), 10)
385 b = append(b, []byte{0x20, 0x6c, 0x69, 0x61}...)
386 b = append(b, []byte{0x20}...)
389 b = strconv.AppendInt(b, int64(t.Year()), 10)
391 b = strconv.AppendInt(b, int64(-t.Year()), 10)
397 // FmtDateFull returns the full date representation of 't' for 'ee'
398 func (ee *ee) FmtDateFull(t time.Time) string {
400 b := make([]byte, 0, 32)
402 b = append(b, ee.daysWide[t.Weekday()]...)
403 b = append(b, []byte{0x2c, 0x20}...)
404 b = append(b, ee.monthsWide[t.Month()]...)
405 b = append(b, []byte{0x20}...)
406 b = strconv.AppendInt(b, int64(t.Day()), 10)
407 b = append(b, []byte{0x20, 0x6c, 0x69, 0x61}...)
408 b = append(b, []byte{0x20}...)
411 b = strconv.AppendInt(b, int64(t.Year()), 10)
413 b = strconv.AppendInt(b, int64(-t.Year()), 10)
419 // FmtTimeShort returns the short time representation of 't' for 'ee'
420 func (ee *ee) FmtTimeShort(t time.Time) string {
422 b := make([]byte, 0, 32)
425 b = append(b, ee.periodsAbbreviated[0]...)
427 b = append(b, ee.periodsAbbreviated[1]...)
430 b = append(b, []byte{0x20, 0x67, 0x61}...)
431 b = append(b, []byte{0x20}...)
439 b = strconv.AppendInt(b, int64(h), 10)
440 b = append(b, ee.timeSeparator...)
446 b = strconv.AppendInt(b, int64(t.Minute()), 10)
451 // FmtTimeMedium returns the medium time representation of 't' for 'ee'
452 func (ee *ee) FmtTimeMedium(t time.Time) string {
454 b := make([]byte, 0, 32)
457 b = append(b, ee.periodsAbbreviated[0]...)
459 b = append(b, ee.periodsAbbreviated[1]...)
462 b = append(b, []byte{0x20, 0x67, 0x61}...)
463 b = append(b, []byte{0x20}...)
471 b = strconv.AppendInt(b, int64(h), 10)
472 b = append(b, ee.timeSeparator...)
478 b = strconv.AppendInt(b, int64(t.Minute()), 10)
479 b = append(b, ee.timeSeparator...)
485 b = strconv.AppendInt(b, int64(t.Second()), 10)
490 // FmtTimeLong returns the long time representation of 't' for 'ee'
491 func (ee *ee) FmtTimeLong(t time.Time) string {
493 b := make([]byte, 0, 32)
496 b = append(b, ee.periodsAbbreviated[0]...)
498 b = append(b, ee.periodsAbbreviated[1]...)
501 b = append(b, []byte{0x20, 0x67, 0x61}...)
502 b = append(b, []byte{0x20}...)
510 b = strconv.AppendInt(b, int64(h), 10)
511 b = append(b, ee.timeSeparator...)
517 b = strconv.AppendInt(b, int64(t.Minute()), 10)
518 b = append(b, ee.timeSeparator...)
524 b = strconv.AppendInt(b, int64(t.Second()), 10)
525 b = append(b, []byte{0x20}...)
533 // FmtTimeFull returns the full time representation of 't' for 'ee'
534 func (ee *ee) FmtTimeFull(t time.Time) string {
536 b := make([]byte, 0, 32)
539 b = append(b, ee.periodsAbbreviated[0]...)
541 b = append(b, ee.periodsAbbreviated[1]...)
544 b = append(b, []byte{0x20, 0x67, 0x61}...)
545 b = append(b, []byte{0x20}...)
553 b = strconv.AppendInt(b, int64(h), 10)
554 b = append(b, ee.timeSeparator...)
560 b = strconv.AppendInt(b, int64(t.Minute()), 10)
561 b = append(b, ee.timeSeparator...)
567 b = strconv.AppendInt(b, int64(t.Second()), 10)
568 b = append(b, []byte{0x20}...)
572 if btz, ok := ee.timezones[tz]; ok {
573 b = append(b, btz...)