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
25 currencies []string // idx = enum of currency code
26 currencyPositiveSuffix 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 'smn' locale
46 func New() locales.Translator {
49 pluralsCardinal: []locales.PluralRule{2, 3, 6},
59 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"},
61 currencyPositiveSuffix: " ",
62 currencyNegativeSuffix: " ",
63 monthsAbbreviated: []string{"", "uđiv", "kuovâ", "njuhčâ", "cuáŋui", "vyesi", "kesi", "syeini", "porge", "čohčâ", "roovvâd", "skammâ", "juovlâ"},
64 monthsNarrow: []string{"", "U", "K", "NJ", "C", "V", "K", "S", "P", "Č", "R", "S", "J"},
65 monthsWide: []string{"", "uđđâivemáánu", "kuovâmáánu", "njuhčâmáánu", "cuáŋuimáánu", "vyesimáánu", "kesimáánu", "syeinimáánu", "porgemáánu", "čohčâmáánu", "roovvâdmáánu", "skammâmáánu", "juovlâmáánu"},
66 daysAbbreviated: []string{"pas", "vuo", "maj", "kos", "tuo", "vás", "láv"},
67 daysNarrow: []string{"p", "V", "M", "K", "T", "V", "L"},
68 daysShort: []string{"pa", "vu", "ma", "ko", "tu", "vá", "lá"},
69 daysWide: []string{"pasepeeivi", "vuossaargâ", "majebaargâ", "koskoho", "tuorâstuv", "vástuppeeivi", "lávurduv"},
70 periodsAbbreviated: []string{"ip.", "ep."},
71 periodsNarrow: []string{"ip.", "ep."},
72 periodsWide: []string{"ip.", "ep."},
73 erasAbbreviated: []string{"oKr.", "mKr."},
74 erasNarrow: []string{"", ""},
75 erasWide: []string{"Ovdil Kristus šoddâm", "maŋa Kristus šoddâm"},
76 timezones: map[string]string{"JDT": "JDT", "SAST": "SAST", "WAST": "WAST", "EDT": "EDT", "GYT": "GYT", "WEZ": "WEZ", "HEPM": "HEPM", "MESZ": "MESZ", "HEPMX": "HEPMX", "IST": "IST", "CST": "CST", "WIT": "WIT", "TMST": "TMST", "MEZ": "MEZ", "WART": "WART", "JST": "JST", "CLT": "CLT", "BOT": "BOT", "SGT": "SGT", "AKDT": "AKDT", "HEEG": "HEEG", "ECT": "ECT", "HNPM": "HNPM", "LHST": "LHST", "HNOG": "HNOG", "HNEG": "HNEG", "HNPMX": "HNPMX", "CHAST": "CHAST", "UYST": "UYST", "HNNOMX": "HNNOMX", "HENOMX": "HENOMX", "CLST": "CLST", "ACWST": "ACWST", "OEZ": "OEZ", "EST": "EST", "ACDT": "ACDT", "WIB": "WIB", "AWST": "AWST", "CDT": "CDT", "NZDT": "NZDT", "WITA": "WITA", "AKST": "AKST", "WESZ": "WESZ", "BT": "BT", "ACWDT": "ACWDT", "MYT": "MYT", "VET": "VET", "OESZ": "OESZ", "LHDT": "LHDT", "COT": "COT", "COST": "COST", "MDT": "MDT", "HNT": "HNT", "HAT": "HAT", "GFT": "GFT", "AWDT": "AWDT", "WARST": "WARST", "WAT": "WAT", "GMT": "GMT", "MST": "MST", "NZST": "NZST", "ARST": "ARST", "EAT": "EAT", "UYT": "UYT", "HADT": "HADT", "AST": "AST", "AEST": "AEST", "AEDT": "AEDT", "HKT": "HKT", "PST": "PST", "PDT": "PDT", "SRT": "SRT", "HNCU": "HNCU", "HEOG": "HEOG", "HKST": "HKST", "ACST": "ACST", "CHADT": "CHADT", "TMT": "TMT", "ADT": "ADT", "ChST": "ChST", "HECU": "HECU", "HAST": "HAST", "ART": "ART", "CAT": "CAT", "∅∅∅": "∅∅∅"},
80 // Locale returns the current translators string locale
81 func (smn *smn) Locale() string {
85 // PluralsCardinal returns the list of cardinal plural rules associated with 'smn'
86 func (smn *smn) PluralsCardinal() []locales.PluralRule {
87 return smn.pluralsCardinal
90 // PluralsOrdinal returns the list of ordinal plural rules associated with 'smn'
91 func (smn *smn) PluralsOrdinal() []locales.PluralRule {
92 return smn.pluralsOrdinal
95 // PluralsRange returns the list of range plural rules associated with 'smn'
96 func (smn *smn) PluralsRange() []locales.PluralRule {
97 return smn.pluralsRange
100 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'smn'
101 func (smn *smn) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
106 return locales.PluralRuleOne
108 return locales.PluralRuleTwo
111 return locales.PluralRuleOther
114 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'smn'
115 func (smn *smn) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
116 return locales.PluralRuleUnknown
119 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'smn'
120 func (smn *smn) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
121 return locales.PluralRuleUnknown
124 // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
125 func (smn *smn) MonthAbbreviated(month time.Month) string {
126 return smn.monthsAbbreviated[month]
129 // MonthsAbbreviated returns the locales abbreviated months
130 func (smn *smn) MonthsAbbreviated() []string {
131 return smn.monthsAbbreviated[1:]
134 // MonthNarrow returns the locales narrow month given the 'month' provided
135 func (smn *smn) MonthNarrow(month time.Month) string {
136 return smn.monthsNarrow[month]
139 // MonthsNarrow returns the locales narrow months
140 func (smn *smn) MonthsNarrow() []string {
141 return smn.monthsNarrow[1:]
144 // MonthWide returns the locales wide month given the 'month' provided
145 func (smn *smn) MonthWide(month time.Month) string {
146 return smn.monthsWide[month]
149 // MonthsWide returns the locales wide months
150 func (smn *smn) MonthsWide() []string {
151 return smn.monthsWide[1:]
154 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
155 func (smn *smn) WeekdayAbbreviated(weekday time.Weekday) string {
156 return smn.daysAbbreviated[weekday]
159 // WeekdaysAbbreviated returns the locales abbreviated weekdays
160 func (smn *smn) WeekdaysAbbreviated() []string {
161 return smn.daysAbbreviated
164 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
165 func (smn *smn) WeekdayNarrow(weekday time.Weekday) string {
166 return smn.daysNarrow[weekday]
169 // WeekdaysNarrow returns the locales narrow weekdays
170 func (smn *smn) WeekdaysNarrow() []string {
171 return smn.daysNarrow
174 // WeekdayShort returns the locales short weekday given the 'weekday' provided
175 func (smn *smn) WeekdayShort(weekday time.Weekday) string {
176 return smn.daysShort[weekday]
179 // WeekdaysShort returns the locales short weekdays
180 func (smn *smn) WeekdaysShort() []string {
184 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
185 func (smn *smn) WeekdayWide(weekday time.Weekday) string {
186 return smn.daysWide[weekday]
189 // WeekdaysWide returns the locales wide weekdays
190 func (smn *smn) WeekdaysWide() []string {
194 // Decimal returns the decimal point of number
195 func (smn *smn) Decimal() string {
199 // Group returns the group of number
200 func (smn *smn) Group() string {
204 // Group returns the minus sign of number
205 func (smn *smn) Minus() string {
209 // FmtNumber returns 'num' with digits/precision of 'v' for 'smn' and handles both Whole and Real numbers based on 'v'
210 func (smn *smn) FmtNumber(num float64, v uint64) string {
212 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
213 l := len(s) + 2 + 2*len(s[:len(s)-int(v)-1])/3
216 b := make([]byte, 0, l)
218 for i := len(s) - 1; i >= 0; i-- {
221 b = append(b, smn.decimal[0])
228 for j := len(smn.group) - 1; j >= 0; j-- {
229 b = append(b, smn.group[j])
241 b = append(b, smn.minus[0])
245 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
246 b[i], b[j] = b[j], b[i]
252 // FmtPercent returns 'num' with digits/precision of 'v' for 'smn' and handles both Whole and Real numbers based on 'v'
253 // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
254 func (smn *smn) FmtPercent(num float64, v uint64) string {
255 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
257 b := make([]byte, 0, l)
259 for i := len(s) - 1; i >= 0; i-- {
262 b = append(b, smn.decimal[0])
270 b = append(b, smn.minus[0])
274 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
275 b[i], b[j] = b[j], b[i]
278 b = append(b, smn.percentSuffix...)
280 b = append(b, smn.percent...)
285 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'smn'
286 func (smn *smn) FmtCurrency(num float64, v uint64, currency currency.Type) string {
288 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
289 symbol := smn.currencies[currency]
290 l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
293 b := make([]byte, 0, l)
295 for i := len(s) - 1; i >= 0; i-- {
298 b = append(b, smn.decimal[0])
305 for j := len(smn.group) - 1; j >= 0; j-- {
306 b = append(b, smn.group[j])
318 b = append(b, smn.minus[0])
322 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
323 b[i], b[j] = b[j], b[i]
329 b = append(b, smn.decimal...)
332 for i := 0; i < 2-int(v); i++ {
337 b = append(b, smn.currencyPositiveSuffix...)
339 b = append(b, symbol...)
344 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'smn'
345 // in accounting notation.
346 func (smn *smn) FmtAccounting(num float64, v uint64, currency currency.Type) string {
348 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
349 symbol := smn.currencies[currency]
350 l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
353 b := make([]byte, 0, l)
355 for i := len(s) - 1; i >= 0; i-- {
358 b = append(b, smn.decimal[0])
365 for j := len(smn.group) - 1; j >= 0; j-- {
366 b = append(b, smn.group[j])
379 b = append(b, smn.minus[0])
384 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
385 b[i], b[j] = b[j], b[i]
391 b = append(b, smn.decimal...)
394 for i := 0; i < 2-int(v); i++ {
400 b = append(b, smn.currencyNegativeSuffix...)
401 b = append(b, symbol...)
404 b = append(b, smn.currencyPositiveSuffix...)
405 b = append(b, symbol...)
411 // FmtDateShort returns the short date representation of 't' for 'smn'
412 func (smn *smn) FmtDateShort(t time.Time) string {
414 b := make([]byte, 0, 32)
416 b = strconv.AppendInt(b, int64(t.Day()), 10)
417 b = append(b, []byte{0x2e}...)
418 b = strconv.AppendInt(b, int64(t.Month()), 10)
419 b = append(b, []byte{0x2e}...)
422 b = strconv.AppendInt(b, int64(t.Year()), 10)
424 b = strconv.AppendInt(b, int64(-t.Year()), 10)
430 // FmtDateMedium returns the medium date representation of 't' for 'smn'
431 func (smn *smn) FmtDateMedium(t time.Time) string {
433 b := make([]byte, 0, 32)
435 b = append(b, smn.monthsAbbreviated[t.Month()]...)
436 b = append(b, []byte{0x20}...)
437 b = strconv.AppendInt(b, int64(t.Day()), 10)
438 b = append(b, []byte{0x2e, 0x20}...)
441 b = strconv.AppendInt(b, int64(t.Year()), 10)
443 b = strconv.AppendInt(b, int64(-t.Year()), 10)
449 // FmtDateLong returns the long date representation of 't' for 'smn'
450 func (smn *smn) FmtDateLong(t time.Time) string {
452 b := make([]byte, 0, 32)
454 b = append(b, smn.monthsWide[t.Month()]...)
455 b = append(b, []byte{0x20}...)
456 b = strconv.AppendInt(b, int64(t.Day()), 10)
457 b = append(b, []byte{0x2e, 0x20}...)
460 b = strconv.AppendInt(b, int64(t.Year()), 10)
462 b = strconv.AppendInt(b, int64(-t.Year()), 10)
468 // FmtDateFull returns the full date representation of 't' for 'smn'
469 func (smn *smn) FmtDateFull(t time.Time) string {
471 b := make([]byte, 0, 32)
473 b = append(b, []byte{0x63, 0x63, 0x63, 0x63, 0x2c, 0x20}...)
474 b = append(b, smn.monthsWide[t.Month()]...)
475 b = append(b, []byte{0x20}...)
476 b = strconv.AppendInt(b, int64(t.Day()), 10)
477 b = append(b, []byte{0x2e, 0x20}...)
480 b = strconv.AppendInt(b, int64(t.Year()), 10)
482 b = strconv.AppendInt(b, int64(-t.Year()), 10)
488 // FmtTimeShort returns the short time representation of 't' for 'smn'
489 func (smn *smn) FmtTimeShort(t time.Time) string {
491 b := make([]byte, 0, 32)
493 b = strconv.AppendInt(b, int64(t.Hour()), 10)
494 b = append(b, []byte{0x2e}...)
500 b = strconv.AppendInt(b, int64(t.Minute()), 10)
505 // FmtTimeMedium returns the medium time representation of 't' for 'smn'
506 func (smn *smn) FmtTimeMedium(t time.Time) string {
508 b := make([]byte, 0, 32)
510 b = strconv.AppendInt(b, int64(t.Hour()), 10)
511 b = append(b, []byte{0x2e}...)
517 b = strconv.AppendInt(b, int64(t.Minute()), 10)
518 b = append(b, []byte{0x2e}...)
524 b = strconv.AppendInt(b, int64(t.Second()), 10)
529 // FmtTimeLong returns the long time representation of 't' for 'smn'
530 func (smn *smn) FmtTimeLong(t time.Time) string {
532 b := make([]byte, 0, 32)
534 b = strconv.AppendInt(b, int64(t.Hour()), 10)
535 b = append(b, []byte{0x2e}...)
541 b = strconv.AppendInt(b, int64(t.Minute()), 10)
542 b = append(b, []byte{0x2e}...)
548 b = strconv.AppendInt(b, int64(t.Second()), 10)
549 b = append(b, []byte{0x20}...)
557 // FmtTimeFull returns the full time representation of 't' for 'smn'
558 func (smn *smn) FmtTimeFull(t time.Time) string {
560 b := make([]byte, 0, 32)
562 b = strconv.AppendInt(b, int64(t.Hour()), 10)
563 b = append(b, []byte{0x2e}...)
569 b = strconv.AppendInt(b, int64(t.Minute()), 10)
570 b = append(b, []byte{0x2e}...)
576 b = strconv.AppendInt(b, int64(t.Second()), 10)
577 b = append(b, []byte{0x20}...)
581 if btz, ok := smn.timezones[tz]; ok {
582 b = append(b, btz...)