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 monthsAbbreviated []string
28 daysAbbreviated []string
32 periodsAbbreviated []string
33 periodsNarrow []string
36 erasAbbreviated []string
39 timezones map[string]string
42 // New returns a new instance of translator for the 'so' locale
43 func New() locales.Translator {
46 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", "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", "S", "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 monthsAbbreviated: []string{"", "Kob", "Lab", "Sad", "Afr", "Sha", "Lix", "Tod", "Sid", "Sag", "Tob", "KIT", "LIT"},
54 monthsNarrow: []string{"", "K", "L", "S", "A", "S", "L", "T", "S", "S", "T", "K", "L"},
55 monthsWide: []string{"", "Bisha Koobaad", "Bisha Labaad", "Bisha Saddexaad", "Bisha Afraad", "Bisha Shanaad", "Bisha Lixaad", "Bisha Todobaad", "Bisha Sideedaad", "Bisha Sagaalaad", "Bisha Tobnaad", "Bisha Kow iyo Tobnaad", "Bisha Laba iyo Tobnaad"},
56 daysAbbreviated: []string{"Axd", "Isn", "Tal", "Arb", "Kha", "Jim", "Sab"},
57 daysNarrow: []string{"A", "I", "T", "A", "Kh", "J", "S"},
58 daysShort: []string{"Axd", "Isn", "Tal", "Arb", "Kha", "Jim", "Sab"},
59 daysWide: []string{"Axad", "Isniin", "Talaado", "Arbaco", "Khamiis", "Jimco", "Sabti"},
60 periodsAbbreviated: []string{"sn.", "gn."},
61 periodsNarrow: []string{"sn.", "gn."},
62 periodsWide: []string{"sn.", "gn."},
63 erasAbbreviated: []string{"CK", "CD"},
64 erasNarrow: []string{"", ""},
65 erasWide: []string{"CK", "CD"},
66 timezones: map[string]string{"GYT": "GYT", "HECU": "HECU", "UYST": "UYST", "NZST": "NZST", "HAT": "HAT", "MDT": "MDT", "AST": "AST", "PDT": "PDT", "BT": "BT", "MYT": "MYT", "WART": "WART", "HNT": "HNT", "HKT": "HKT", "ACDT": "ACDT", "HNCU": "HNCU", "ACWST": "ACWST", "UYT": "UYT", "HNOG": "HNOG", "GFT": "GFT", "WEZ": "WEZ", "ChST": "ChST", "AWDT": "AWDT", "WAST": "WAST", "∅∅∅": "∅∅∅", "HEEG": "HEEG", "COT": "Waqtiyada Caadiga ah ee kolambiya", "WIT": "WIT", "HENOMX": "HENOMX", "COST": "Waqtiyada Xagaaga Kolambiya", "GMT": "GMT", "HEPMX": "HEPMX", "CDT": "CDT", "LHST": "LHST", "ACST": "ACST", "HNPM": "HNPM", "CHADT": "CHADT", "CST": "CST", "MEZ": "MEZ", "HADT": "HADT", "NZDT": "NZDT", "HNNOMX": "HNNOMX", "CLST": "CLST", "ADT": "ADT", "IST": "IST", "SAST": "SAST", "HNPMX": "HNPMX", "WITA": "WITA", "HEOG": "HEOG", "ARST": "ARST", "WAT": "WAT", "CLT": "CLT", "EST": "EST", "ECT": "ECT", "HAST": "HAST", "JDT": "JDT", "ART": "ART", "SGT": "SGT", "MESZ": "MESZ", "LHDT": "LHDT", "HNEG": "HNEG", "CAT": "CAT", "WESZ": "WESZ", "HEPM": "HEPM", "TMT": "TMT", "JST": "JST", "AEST": "AEST", "EDT": "EDT", "AKST": "AKST", "AKDT": "AKDT", "MST": "MST", "OESZ": "OESZ", "AEDT": "AEDT", "EAT": "EAT", "HKST": "HKST", "CHAST": "CHAST", "BOT": "BOT", "SRT": "SRT", "WARST": "WARST", "OEZ": "OEZ", "WIB": "WIB", "PST": "PST", "AWST": "AWST", "ACWDT": "ACWDT", "TMST": "TMST", "VET": "VET"},
70 // Locale returns the current translators string locale
71 func (so *so) Locale() string {
75 // PluralsCardinal returns the list of cardinal plural rules associated with 'so'
76 func (so *so) PluralsCardinal() []locales.PluralRule {
77 return so.pluralsCardinal
80 // PluralsOrdinal returns the list of ordinal plural rules associated with 'so'
81 func (so *so) PluralsOrdinal() []locales.PluralRule {
82 return so.pluralsOrdinal
85 // PluralsRange returns the list of range plural rules associated with 'so'
86 func (so *so) PluralsRange() []locales.PluralRule {
87 return so.pluralsRange
90 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'so'
91 func (so *so) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
96 return locales.PluralRuleOne
99 return locales.PluralRuleOther
102 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'so'
103 func (so *so) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
104 return locales.PluralRuleUnknown
107 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'so'
108 func (so *so) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
109 return locales.PluralRuleUnknown
112 // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
113 func (so *so) MonthAbbreviated(month time.Month) string {
114 return so.monthsAbbreviated[month]
117 // MonthsAbbreviated returns the locales abbreviated months
118 func (so *so) MonthsAbbreviated() []string {
119 return so.monthsAbbreviated[1:]
122 // MonthNarrow returns the locales narrow month given the 'month' provided
123 func (so *so) MonthNarrow(month time.Month) string {
124 return so.monthsNarrow[month]
127 // MonthsNarrow returns the locales narrow months
128 func (so *so) MonthsNarrow() []string {
129 return so.monthsNarrow[1:]
132 // MonthWide returns the locales wide month given the 'month' provided
133 func (so *so) MonthWide(month time.Month) string {
134 return so.monthsWide[month]
137 // MonthsWide returns the locales wide months
138 func (so *so) MonthsWide() []string {
139 return so.monthsWide[1:]
142 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
143 func (so *so) WeekdayAbbreviated(weekday time.Weekday) string {
144 return so.daysAbbreviated[weekday]
147 // WeekdaysAbbreviated returns the locales abbreviated weekdays
148 func (so *so) WeekdaysAbbreviated() []string {
149 return so.daysAbbreviated
152 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
153 func (so *so) WeekdayNarrow(weekday time.Weekday) string {
154 return so.daysNarrow[weekday]
157 // WeekdaysNarrow returns the locales narrow weekdays
158 func (so *so) WeekdaysNarrow() []string {
162 // WeekdayShort returns the locales short weekday given the 'weekday' provided
163 func (so *so) WeekdayShort(weekday time.Weekday) string {
164 return so.daysShort[weekday]
167 // WeekdaysShort returns the locales short weekdays
168 func (so *so) WeekdaysShort() []string {
172 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
173 func (so *so) WeekdayWide(weekday time.Weekday) string {
174 return so.daysWide[weekday]
177 // WeekdaysWide returns the locales wide weekdays
178 func (so *so) WeekdaysWide() []string {
182 // Decimal returns the decimal point of number
183 func (so *so) Decimal() string {
187 // Group returns the group of number
188 func (so *so) Group() string {
192 // Group returns the minus sign of number
193 func (so *so) Minus() string {
197 // FmtNumber returns 'num' with digits/precision of 'v' for 'so' and handles both Whole and Real numbers based on 'v'
198 func (so *so) FmtNumber(num float64, v uint64) string {
200 return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
203 // FmtPercent returns 'num' with digits/precision of 'v' for 'so' and handles both Whole and Real numbers based on 'v'
204 // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
205 func (so *so) FmtPercent(num float64, v uint64) string {
206 return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
209 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'so'
210 func (so *so) FmtCurrency(num float64, v uint64, currency currency.Type) string {
212 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
213 symbol := so.currencies[currency]
214 l := len(s) + len(symbol) + 1 + 1*len(s[:len(s)-int(v)-1])/3
217 b := make([]byte, 0, l)
219 for i := len(s) - 1; i >= 0; i-- {
222 b = append(b, so.decimal[0])
229 b = append(b, so.group[0])
239 for j := len(symbol) - 1; j >= 0; j-- {
240 b = append(b, symbol[j])
244 b = append(b, so.minus[0])
248 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
249 b[i], b[j] = b[j], b[i]
255 b = append(b, so.decimal...)
258 for i := 0; i < 2-int(v); i++ {
266 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'so'
267 // in accounting notation.
268 func (so *so) FmtAccounting(num float64, v uint64, currency currency.Type) string {
270 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
271 symbol := so.currencies[currency]
272 l := len(s) + len(symbol) + 1 + 1*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, so.decimal[0])
287 b = append(b, so.group[0])
299 for j := len(symbol) - 1; j >= 0; j-- {
300 b = append(b, symbol[j])
303 b = append(b, so.minus[0])
307 for j := len(symbol) - 1; j >= 0; j-- {
308 b = append(b, symbol[j])
314 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
315 b[i], b[j] = b[j], b[i]
321 b = append(b, so.decimal...)
324 for i := 0; i < 2-int(v); i++ {
332 // FmtDateShort returns the short date representation of 't' for 'so'
333 func (so *so) FmtDateShort(t time.Time) string {
335 b := make([]byte, 0, 32)
341 b = strconv.AppendInt(b, int64(t.Day()), 10)
342 b = append(b, []byte{0x2f}...)
348 b = strconv.AppendInt(b, int64(t.Month()), 10)
350 b = append(b, []byte{0x2f}...)
353 b = append(b, strconv.Itoa(t.Year())[2:]...)
355 b = append(b, strconv.Itoa(t.Year())[1:]...)
361 // FmtDateMedium returns the medium date representation of 't' for 'so'
362 func (so *so) FmtDateMedium(t time.Time) string {
364 b := make([]byte, 0, 32)
370 b = strconv.AppendInt(b, int64(t.Day()), 10)
371 b = append(b, []byte{0x2d}...)
372 b = append(b, so.monthsAbbreviated[t.Month()]...)
373 b = append(b, []byte{0x2d}...)
376 b = strconv.AppendInt(b, int64(t.Year()), 10)
378 b = strconv.AppendInt(b, int64(-t.Year()), 10)
384 // FmtDateLong returns the long date representation of 't' for 'so'
385 func (so *so) FmtDateLong(t time.Time) string {
387 b := make([]byte, 0, 32)
393 b = strconv.AppendInt(b, int64(t.Day()), 10)
394 b = append(b, []byte{0x20}...)
395 b = append(b, so.monthsWide[t.Month()]...)
396 b = append(b, []byte{0x20}...)
399 b = strconv.AppendInt(b, int64(t.Year()), 10)
401 b = strconv.AppendInt(b, int64(-t.Year()), 10)
407 // FmtDateFull returns the full date representation of 't' for 'so'
408 func (so *so) FmtDateFull(t time.Time) string {
410 b := make([]byte, 0, 32)
412 b = append(b, so.daysWide[t.Weekday()]...)
413 b = append(b, []byte{0x2c, 0x20}...)
414 b = append(b, so.monthsWide[t.Month()]...)
415 b = append(b, []byte{0x20}...)
421 b = strconv.AppendInt(b, int64(t.Day()), 10)
422 b = append(b, []byte{0x2c, 0x20}...)
425 b = strconv.AppendInt(b, int64(t.Year()), 10)
427 b = strconv.AppendInt(b, int64(-t.Year()), 10)
433 // FmtTimeShort returns the short time representation of 't' for 'so'
434 func (so *so) FmtTimeShort(t time.Time) string {
436 b := make([]byte, 0, 32)
444 b = strconv.AppendInt(b, int64(h), 10)
445 b = append(b, so.timeSeparator...)
451 b = strconv.AppendInt(b, int64(t.Minute()), 10)
452 b = append(b, []byte{0x20}...)
455 b = append(b, so.periodsAbbreviated[0]...)
457 b = append(b, so.periodsAbbreviated[1]...)
463 // FmtTimeMedium returns the medium time representation of 't' for 'so'
464 func (so *so) FmtTimeMedium(t time.Time) string {
466 b := make([]byte, 0, 32)
474 b = strconv.AppendInt(b, int64(h), 10)
475 b = append(b, so.timeSeparator...)
481 b = strconv.AppendInt(b, int64(t.Minute()), 10)
482 b = append(b, so.timeSeparator...)
488 b = strconv.AppendInt(b, int64(t.Second()), 10)
489 b = append(b, []byte{0x20}...)
492 b = append(b, so.periodsAbbreviated[0]...)
494 b = append(b, so.periodsAbbreviated[1]...)
500 // FmtTimeLong returns the long time representation of 't' for 'so'
501 func (so *so) FmtTimeLong(t time.Time) string {
503 b := make([]byte, 0, 32)
511 b = strconv.AppendInt(b, int64(h), 10)
512 b = append(b, so.timeSeparator...)
518 b = strconv.AppendInt(b, int64(t.Minute()), 10)
519 b = append(b, so.timeSeparator...)
525 b = strconv.AppendInt(b, int64(t.Second()), 10)
526 b = append(b, []byte{0x20}...)
529 b = append(b, so.periodsAbbreviated[0]...)
531 b = append(b, so.periodsAbbreviated[1]...)
534 b = append(b, []byte{0x20}...)
542 // FmtTimeFull returns the full time representation of 't' for 'so'
543 func (so *so) FmtTimeFull(t time.Time) string {
545 b := make([]byte, 0, 32)
553 b = strconv.AppendInt(b, int64(h), 10)
554 b = append(b, so.timeSeparator...)
560 b = strconv.AppendInt(b, int64(t.Minute()), 10)
561 b = append(b, so.timeSeparator...)
567 b = strconv.AppendInt(b, int64(t.Second()), 10)
568 b = append(b, []byte{0x20}...)
571 b = append(b, so.periodsAbbreviated[0]...)
573 b = append(b, so.periodsAbbreviated[1]...)
576 b = append(b, []byte{0x20}...)
580 if btz, ok := so.timezones[tz]; ok {
581 b = append(b, btz...)