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 'mer' locale
45 func New() locales.Translator {
52 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", "Ksh", "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"},
53 currencyNegativePrefix: "(",
54 currencyNegativeSuffix: ")",
55 monthsAbbreviated: []string{"", "JAN", "FEB", "MAC", "ĨPU", "MĨĨ", "NJU", "NJR", "AGA", "SPT", "OKT", "NOV", "DEC"},
56 monthsNarrow: []string{"", "J", "F", "M", "Ĩ", "M", "N", "N", "A", "S", "O", "N", "D"},
57 monthsWide: []string{"", "Januarĩ", "Feburuarĩ", "Machi", "Ĩpurũ", "Mĩĩ", "Njuni", "Njuraĩ", "Agasti", "Septemba", "Oktũba", "Novemba", "Dicemba"},
58 daysAbbreviated: []string{"KIU", "MRA", "WAI", "WET", "WEN", "WTN", "JUM"},
59 daysNarrow: []string{"K", "M", "W", "W", "W", "W", "J"},
60 daysWide: []string{"Kiumia", "Muramuko", "Wairi", "Wethatu", "Wena", "Wetano", "Jumamosi"},
61 periodsAbbreviated: []string{"RŨ", "ŨG"},
62 periodsWide: []string{"RŨ", "ŨG"},
63 erasAbbreviated: []string{"MK", "NK"},
64 erasNarrow: []string{"", ""},
65 erasWide: []string{"Mbere ya Kristũ", "Nyuma ya Kristũ"},
66 timezones: map[string]string{"ACDT": "ACDT", "CAT": "CAT", "BT": "BT", "MDT": "MDT", "ACWDT": "ACWDT", "TMT": "TMT", "OESZ": "OESZ", "IST": "IST", "HNOG": "HNOG", "WAST": "WAST", "HNPMX": "HNPMX", "PDT": "PDT", "EDT": "EDT", "SGT": "SGT", "WARST": "WARST", "ARST": "ARST", "HNCU": "HNCU", "ACWST": "ACWST", "EST": "EST", "WESZ": "WESZ", "GMT": "GMT", "WIT": "WIT", "HENOMX": "HENOMX", "JST": "JST", "WAT": "WAT", "COT": "COT", "GFT": "GFT", "AKDT": "AKDT", "AWST": "AWST", "HAST": "HAST", "AEST": "AEST", "HKT": "HKT", "CLST": "CLST", "HNT": "HNT", "WITA": "WITA", "JDT": "JDT", "ChST": "ChST", "VET": "VET", "LHDT": "LHDT", "OEZ": "OEZ", "BOT": "BOT", "HADT": "HADT", "ECT": "ECT", "HEPM": "HEPM", "PST": "PST", "WART": "WART", "ART": "ART", "WEZ": "WEZ", "WIB": "WIB", "LHST": "LHST", "UYT": "UYT", "NZDT": "NZDT", "ADT": "ADT", "CLT": "CLT", "COST": "COST", "ACST": "ACST", "HEPMX": "HEPMX", "CHAST": "CHAST", "MST": "MST", "UYST": "UYST", "TMST": "TMST", "HNEG": "HNEG", "HAT": "HAT", "GYT": "GYT", "CHADT": "CHADT", "HNPM": "HNPM", "EAT": "EAT", "AKST": "AKST", "AST": "AST", "SAST": "SAST", "HNNOMX": "HNNOMX", "CST": "CST", "CDT": "CDT", "SRT": "SRT", "MYT": "MYT", "MEZ": "MEZ", "AEDT": "AEDT", "HKST": "HKST", "HECU": "HECU", "AWDT": "AWDT", "MESZ": "MESZ", "HEOG": "HEOG", "HEEG": "HEEG", "∅∅∅": "∅∅∅", "NZST": "NZST"},
70 // Locale returns the current translators string locale
71 func (mer *mer) Locale() string {
75 // PluralsCardinal returns the list of cardinal plural rules associated with 'mer'
76 func (mer *mer) PluralsCardinal() []locales.PluralRule {
77 return mer.pluralsCardinal
80 // PluralsOrdinal returns the list of ordinal plural rules associated with 'mer'
81 func (mer *mer) PluralsOrdinal() []locales.PluralRule {
82 return mer.pluralsOrdinal
85 // PluralsRange returns the list of range plural rules associated with 'mer'
86 func (mer *mer) PluralsRange() []locales.PluralRule {
87 return mer.pluralsRange
90 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'mer'
91 func (mer *mer) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
92 return locales.PluralRuleUnknown
95 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'mer'
96 func (mer *mer) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
97 return locales.PluralRuleUnknown
100 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'mer'
101 func (mer *mer) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
102 return locales.PluralRuleUnknown
105 // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
106 func (mer *mer) MonthAbbreviated(month time.Month) string {
107 return mer.monthsAbbreviated[month]
110 // MonthsAbbreviated returns the locales abbreviated months
111 func (mer *mer) MonthsAbbreviated() []string {
112 return mer.monthsAbbreviated[1:]
115 // MonthNarrow returns the locales narrow month given the 'month' provided
116 func (mer *mer) MonthNarrow(month time.Month) string {
117 return mer.monthsNarrow[month]
120 // MonthsNarrow returns the locales narrow months
121 func (mer *mer) MonthsNarrow() []string {
122 return mer.monthsNarrow[1:]
125 // MonthWide returns the locales wide month given the 'month' provided
126 func (mer *mer) MonthWide(month time.Month) string {
127 return mer.monthsWide[month]
130 // MonthsWide returns the locales wide months
131 func (mer *mer) MonthsWide() []string {
132 return mer.monthsWide[1:]
135 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
136 func (mer *mer) WeekdayAbbreviated(weekday time.Weekday) string {
137 return mer.daysAbbreviated[weekday]
140 // WeekdaysAbbreviated returns the locales abbreviated weekdays
141 func (mer *mer) WeekdaysAbbreviated() []string {
142 return mer.daysAbbreviated
145 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
146 func (mer *mer) WeekdayNarrow(weekday time.Weekday) string {
147 return mer.daysNarrow[weekday]
150 // WeekdaysNarrow returns the locales narrow weekdays
151 func (mer *mer) WeekdaysNarrow() []string {
152 return mer.daysNarrow
155 // WeekdayShort returns the locales short weekday given the 'weekday' provided
156 func (mer *mer) WeekdayShort(weekday time.Weekday) string {
157 return mer.daysShort[weekday]
160 // WeekdaysShort returns the locales short weekdays
161 func (mer *mer) WeekdaysShort() []string {
165 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
166 func (mer *mer) WeekdayWide(weekday time.Weekday) string {
167 return mer.daysWide[weekday]
170 // WeekdaysWide returns the locales wide weekdays
171 func (mer *mer) WeekdaysWide() []string {
175 // Decimal returns the decimal point of number
176 func (mer *mer) Decimal() string {
180 // Group returns the group of number
181 func (mer *mer) Group() string {
185 // Group returns the minus sign of number
186 func (mer *mer) Minus() string {
190 // FmtNumber returns 'num' with digits/precision of 'v' for 'mer' and handles both Whole and Real numbers based on 'v'
191 func (mer *mer) FmtNumber(num float64, v uint64) string {
193 return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
196 // FmtPercent returns 'num' with digits/precision of 'v' for 'mer' and handles both Whole and Real numbers based on 'v'
197 // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
198 func (mer *mer) FmtPercent(num float64, v uint64) string {
199 return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
202 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'mer'
203 func (mer *mer) FmtCurrency(num float64, v uint64, currency currency.Type) string {
205 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
206 symbol := mer.currencies[currency]
207 l := len(s) + len(symbol) + 0
210 b := make([]byte, 0, l)
212 for i := len(s) - 1; i >= 0; i-- {
215 b = append(b, mer.decimal[0])
222 b = append(b, mer.group[0])
232 for j := len(symbol) - 1; j >= 0; j-- {
233 b = append(b, symbol[j])
237 b = append(b, mer.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 b = append(b, mer.decimal...)
251 for i := 0; i < 2-int(v); i++ {
259 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'mer'
260 // in accounting notation.
261 func (mer *mer) FmtAccounting(num float64, v uint64, currency currency.Type) string {
263 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
264 symbol := mer.currencies[currency]
265 l := len(s) + len(symbol) + 2
268 b := make([]byte, 0, l)
270 for i := len(s) - 1; i >= 0; i-- {
273 b = append(b, mer.decimal[0])
280 b = append(b, mer.group[0])
292 for j := len(symbol) - 1; j >= 0; j-- {
293 b = append(b, symbol[j])
296 b = append(b, mer.currencyNegativePrefix[0])
300 for j := len(symbol) - 1; j >= 0; j-- {
301 b = append(b, symbol[j])
307 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
308 b[i], b[j] = b[j], b[i]
314 b = append(b, mer.decimal...)
317 for i := 0; i < 2-int(v); i++ {
323 b = append(b, mer.currencyNegativeSuffix...)
329 // FmtDateShort returns the short date representation of 't' for 'mer'
330 func (mer *mer) FmtDateShort(t time.Time) string {
332 b := make([]byte, 0, 32)
338 b = strconv.AppendInt(b, int64(t.Day()), 10)
339 b = append(b, []byte{0x2f}...)
345 b = strconv.AppendInt(b, int64(t.Month()), 10)
347 b = append(b, []byte{0x2f}...)
350 b = strconv.AppendInt(b, int64(t.Year()), 10)
352 b = strconv.AppendInt(b, int64(-t.Year()), 10)
358 // FmtDateMedium returns the medium date representation of 't' for 'mer'
359 func (mer *mer) FmtDateMedium(t time.Time) string {
361 b := make([]byte, 0, 32)
363 b = strconv.AppendInt(b, int64(t.Day()), 10)
364 b = append(b, []byte{0x20}...)
365 b = append(b, mer.monthsAbbreviated[t.Month()]...)
366 b = append(b, []byte{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 'mer'
378 func (mer *mer) FmtDateLong(t time.Time) string {
380 b := make([]byte, 0, 32)
382 b = strconv.AppendInt(b, int64(t.Day()), 10)
383 b = append(b, []byte{0x20}...)
384 b = append(b, mer.monthsWide[t.Month()]...)
385 b = append(b, []byte{0x20}...)
388 b = strconv.AppendInt(b, int64(t.Year()), 10)
390 b = strconv.AppendInt(b, int64(-t.Year()), 10)
396 // FmtDateFull returns the full date representation of 't' for 'mer'
397 func (mer *mer) FmtDateFull(t time.Time) string {
399 b := make([]byte, 0, 32)
401 b = append(b, mer.daysWide[t.Weekday()]...)
402 b = append(b, []byte{0x2c, 0x20}...)
403 b = strconv.AppendInt(b, int64(t.Day()), 10)
404 b = append(b, []byte{0x20}...)
405 b = append(b, mer.monthsWide[t.Month()]...)
406 b = append(b, []byte{0x20}...)
409 b = strconv.AppendInt(b, int64(t.Year()), 10)
411 b = strconv.AppendInt(b, int64(-t.Year()), 10)
417 // FmtTimeShort returns the short time representation of 't' for 'mer'
418 func (mer *mer) FmtTimeShort(t time.Time) string {
420 b := make([]byte, 0, 32)
426 b = strconv.AppendInt(b, int64(t.Hour()), 10)
427 b = append(b, mer.timeSeparator...)
433 b = strconv.AppendInt(b, int64(t.Minute()), 10)
438 // FmtTimeMedium returns the medium time representation of 't' for 'mer'
439 func (mer *mer) FmtTimeMedium(t time.Time) string {
441 b := make([]byte, 0, 32)
447 b = strconv.AppendInt(b, int64(t.Hour()), 10)
448 b = append(b, mer.timeSeparator...)
454 b = strconv.AppendInt(b, int64(t.Minute()), 10)
455 b = append(b, mer.timeSeparator...)
461 b = strconv.AppendInt(b, int64(t.Second()), 10)
466 // FmtTimeLong returns the long time representation of 't' for 'mer'
467 func (mer *mer) FmtTimeLong(t time.Time) string {
469 b := make([]byte, 0, 32)
475 b = strconv.AppendInt(b, int64(t.Hour()), 10)
476 b = append(b, mer.timeSeparator...)
482 b = strconv.AppendInt(b, int64(t.Minute()), 10)
483 b = append(b, mer.timeSeparator...)
489 b = strconv.AppendInt(b, int64(t.Second()), 10)
490 b = append(b, []byte{0x20}...)
498 // FmtTimeFull returns the full time representation of 't' for 'mer'
499 func (mer *mer) FmtTimeFull(t time.Time) string {
501 b := make([]byte, 0, 32)
507 b = strconv.AppendInt(b, int64(t.Hour()), 10)
508 b = append(b, mer.timeSeparator...)
514 b = strconv.AppendInt(b, int64(t.Minute()), 10)
515 b = append(b, mer.timeSeparator...)
521 b = strconv.AppendInt(b, int64(t.Second()), 10)
522 b = append(b, []byte{0x20}...)
526 if btz, ok := mer.timezones[tz]; ok {
527 b = append(b, btz...)