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 currencyPositiveSuffix 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 'xog' 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", "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", "USh", "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 currencyPositiveSuffix: " ",
54 currencyNegativeSuffix: " ",
55 monthsAbbreviated: []string{"", "Jan", "Feb", "Mar", "Apu", "Maa", "Juu", "Jul", "Agu", "Seb", "Oki", "Nov", "Des"},
56 monthsNarrow: []string{"", "J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"},
57 monthsWide: []string{"", "Janwaliyo", "Febwaliyo", "Marisi", "Apuli", "Maayi", "Juuni", "Julaayi", "Agusito", "Sebuttemba", "Okitobba", "Novemba", "Desemba"},
58 daysAbbreviated: []string{"Sabi", "Bala", "Kubi", "Kusa", "Kuna", "Kuta", "Muka"},
59 daysNarrow: []string{"S", "B", "B", "S", "K", "K", "M"},
60 daysWide: []string{"Sabiiti", "Balaza", "Owokubili", "Owokusatu", "Olokuna", "Olokutaanu", "Olomukaaga"},
61 periodsAbbreviated: []string{"Munkyo", "Eigulo"},
62 periodsWide: []string{"Munkyo", "Eigulo"},
63 erasAbbreviated: []string{"AZ", "AF"},
64 erasNarrow: []string{"", ""},
65 erasWide: []string{"Kulisto nga azilawo", "Kulisto nga affile"},
66 timezones: map[string]string{"MDT": "MDT", "COT": "COT", "CHADT": "CHADT", "BOT": "BOT", "CDT": "CDT", "WIT": "WIT", "NZST": "NZST", "JDT": "JDT", "AEDT": "AEDT", "HEEG": "HEEG", "AKDT": "AKDT", "ECT": "ECT", "SGT": "SGT", "HAST": "HAST", "HADT": "HADT", "VET": "VET", "HNCU": "HNCU", "HAT": "HAT", "CLT": "CLT", "WESZ": "WESZ", "BT": "BT", "ARST": "ARST", "EAT": "EAT", "WAST": "WAST", "WART": "WART", "WARST": "WARST", "HEPMX": "HEPMX", "GYT": "GYT", "HNPMX": "HNPMX", "PDT": "PDT", "CHAST": "CHAST", "MESZ": "MESZ", "HKT": "HKT", "GFT": "GFT", "HKST": "HKST", "JST": "JST", "OESZ": "OESZ", "HNEG": "HNEG", "MYT": "MYT", "EDT": "EDT", "SRT": "SRT", "PST": "PST", "ACWDT": "ACWDT", "OEZ": "OEZ", "IST": "IST", "WITA": "WITA", "HNNOMX": "HNNOMX", "HENOMX": "HENOMX", "HNOG": "HNOG", "ACST": "ACST", "TMT": "TMT", "LHDT": "LHDT", "ADT": "ADT", "WAT": "WAT", "CAT": "CAT", "WEZ": "WEZ", "ChST": "ChST", "HECU": "HECU", "UYST": "UYST", "TMST": "TMST", "∅∅∅": "∅∅∅", "CST": "CST", "GMT": "GMT", "AWST": "AWST", "AWDT": "AWDT", "NZDT": "NZDT", "HEOG": "HEOG", "EST": "EST", "HNPM": "HNPM", "HNT": "HNT", "COST": "COST", "WIB": "WIB", "ART": "ART", "ACDT": "ACDT", "ACWST": "ACWST", "MEZ": "MEZ", "MST": "MST", "UYT": "UYT", "AEST": "AEST", "CLST": "CLST", "AKST": "AKST", "HEPM": "HEPM", "LHST": "LHST", "AST": "AST", "SAST": "SAST"},
70 // Locale returns the current translators string locale
71 func (xog *xog) Locale() string {
75 // PluralsCardinal returns the list of cardinal plural rules associated with 'xog'
76 func (xog *xog) PluralsCardinal() []locales.PluralRule {
77 return xog.pluralsCardinal
80 // PluralsOrdinal returns the list of ordinal plural rules associated with 'xog'
81 func (xog *xog) PluralsOrdinal() []locales.PluralRule {
82 return xog.pluralsOrdinal
85 // PluralsRange returns the list of range plural rules associated with 'xog'
86 func (xog *xog) PluralsRange() []locales.PluralRule {
87 return xog.pluralsRange
90 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'xog'
91 func (xog *xog) 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 'xog'
103 func (xog *xog) 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 'xog'
108 func (xog *xog) 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 (xog *xog) MonthAbbreviated(month time.Month) string {
114 return xog.monthsAbbreviated[month]
117 // MonthsAbbreviated returns the locales abbreviated months
118 func (xog *xog) MonthsAbbreviated() []string {
119 return xog.monthsAbbreviated[1:]
122 // MonthNarrow returns the locales narrow month given the 'month' provided
123 func (xog *xog) MonthNarrow(month time.Month) string {
124 return xog.monthsNarrow[month]
127 // MonthsNarrow returns the locales narrow months
128 func (xog *xog) MonthsNarrow() []string {
129 return xog.monthsNarrow[1:]
132 // MonthWide returns the locales wide month given the 'month' provided
133 func (xog *xog) MonthWide(month time.Month) string {
134 return xog.monthsWide[month]
137 // MonthsWide returns the locales wide months
138 func (xog *xog) MonthsWide() []string {
139 return xog.monthsWide[1:]
142 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
143 func (xog *xog) WeekdayAbbreviated(weekday time.Weekday) string {
144 return xog.daysAbbreviated[weekday]
147 // WeekdaysAbbreviated returns the locales abbreviated weekdays
148 func (xog *xog) WeekdaysAbbreviated() []string {
149 return xog.daysAbbreviated
152 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
153 func (xog *xog) WeekdayNarrow(weekday time.Weekday) string {
154 return xog.daysNarrow[weekday]
157 // WeekdaysNarrow returns the locales narrow weekdays
158 func (xog *xog) WeekdaysNarrow() []string {
159 return xog.daysNarrow
162 // WeekdayShort returns the locales short weekday given the 'weekday' provided
163 func (xog *xog) WeekdayShort(weekday time.Weekday) string {
164 return xog.daysShort[weekday]
167 // WeekdaysShort returns the locales short weekdays
168 func (xog *xog) WeekdaysShort() []string {
172 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
173 func (xog *xog) WeekdayWide(weekday time.Weekday) string {
174 return xog.daysWide[weekday]
177 // WeekdaysWide returns the locales wide weekdays
178 func (xog *xog) WeekdaysWide() []string {
182 // Decimal returns the decimal point of number
183 func (xog *xog) Decimal() string {
187 // Group returns the group of number
188 func (xog *xog) Group() string {
192 // Group returns the minus sign of number
193 func (xog *xog) Minus() string {
197 // FmtNumber returns 'num' with digits/precision of 'v' for 'xog' and handles both Whole and Real numbers based on 'v'
198 func (xog *xog) 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 'xog' 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 (xog *xog) 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 'xog'
210 func (xog *xog) FmtCurrency(num float64, v uint64, currency currency.Type) string {
212 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
213 symbol := xog.currencies[currency]
214 l := len(s) + len(symbol) + 2
217 b := make([]byte, 0, l)
219 for i := len(s) - 1; i >= 0; i-- {
222 b = append(b, xog.decimal[0])
229 b = append(b, xog.group[0])
240 b = append(b, xog.minus[0])
244 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
245 b[i], b[j] = b[j], b[i]
251 b = append(b, xog.decimal...)
254 for i := 0; i < 2-int(v); i++ {
259 b = append(b, xog.currencyPositiveSuffix...)
261 b = append(b, symbol...)
266 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'xog'
267 // in accounting notation.
268 func (xog *xog) FmtAccounting(num float64, v uint64, currency currency.Type) string {
270 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
271 symbol := xog.currencies[currency]
272 l := len(s) + len(symbol) + 2
275 b := make([]byte, 0, l)
277 for i := len(s) - 1; i >= 0; i-- {
280 b = append(b, xog.decimal[0])
287 b = append(b, xog.group[0])
299 b = append(b, xog.minus[0])
304 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
305 b[i], b[j] = b[j], b[i]
311 b = append(b, xog.decimal...)
314 for i := 0; i < 2-int(v); i++ {
320 b = append(b, xog.currencyNegativeSuffix...)
321 b = append(b, symbol...)
324 b = append(b, xog.currencyPositiveSuffix...)
325 b = append(b, symbol...)
331 // FmtDateShort returns the short date representation of 't' for 'xog'
332 func (xog *xog) FmtDateShort(t time.Time) string {
334 b := make([]byte, 0, 32)
340 b = strconv.AppendInt(b, int64(t.Day()), 10)
341 b = append(b, []byte{0x2f}...)
347 b = strconv.AppendInt(b, int64(t.Month()), 10)
349 b = append(b, []byte{0x2f}...)
352 b = strconv.AppendInt(b, int64(t.Year()), 10)
354 b = strconv.AppendInt(b, int64(-t.Year()), 10)
360 // FmtDateMedium returns the medium date representation of 't' for 'xog'
361 func (xog *xog) FmtDateMedium(t time.Time) string {
363 b := make([]byte, 0, 32)
365 b = strconv.AppendInt(b, int64(t.Day()), 10)
366 b = append(b, []byte{0x20}...)
367 b = append(b, xog.monthsAbbreviated[t.Month()]...)
368 b = append(b, []byte{0x20}...)
371 b = strconv.AppendInt(b, int64(t.Year()), 10)
373 b = strconv.AppendInt(b, int64(-t.Year()), 10)
379 // FmtDateLong returns the long date representation of 't' for 'xog'
380 func (xog *xog) FmtDateLong(t time.Time) string {
382 b := make([]byte, 0, 32)
384 b = strconv.AppendInt(b, int64(t.Day()), 10)
385 b = append(b, []byte{0x20}...)
386 b = append(b, xog.monthsWide[t.Month()]...)
387 b = append(b, []byte{0x20}...)
390 b = strconv.AppendInt(b, int64(t.Year()), 10)
392 b = strconv.AppendInt(b, int64(-t.Year()), 10)
398 // FmtDateFull returns the full date representation of 't' for 'xog'
399 func (xog *xog) FmtDateFull(t time.Time) string {
401 b := make([]byte, 0, 32)
403 b = append(b, xog.daysWide[t.Weekday()]...)
404 b = append(b, []byte{0x2c, 0x20}...)
405 b = strconv.AppendInt(b, int64(t.Day()), 10)
406 b = append(b, []byte{0x20}...)
407 b = append(b, xog.monthsWide[t.Month()]...)
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 'xog'
420 func (xog *xog) FmtTimeShort(t time.Time) string {
422 b := make([]byte, 0, 32)
428 b = strconv.AppendInt(b, int64(t.Hour()), 10)
429 b = append(b, xog.timeSeparator...)
435 b = strconv.AppendInt(b, int64(t.Minute()), 10)
440 // FmtTimeMedium returns the medium time representation of 't' for 'xog'
441 func (xog *xog) FmtTimeMedium(t time.Time) string {
443 b := make([]byte, 0, 32)
449 b = strconv.AppendInt(b, int64(t.Hour()), 10)
450 b = append(b, xog.timeSeparator...)
456 b = strconv.AppendInt(b, int64(t.Minute()), 10)
457 b = append(b, xog.timeSeparator...)
463 b = strconv.AppendInt(b, int64(t.Second()), 10)
468 // FmtTimeLong returns the long time representation of 't' for 'xog'
469 func (xog *xog) FmtTimeLong(t time.Time) string {
471 b := make([]byte, 0, 32)
477 b = strconv.AppendInt(b, int64(t.Hour()), 10)
478 b = append(b, xog.timeSeparator...)
484 b = strconv.AppendInt(b, int64(t.Minute()), 10)
485 b = append(b, xog.timeSeparator...)
491 b = strconv.AppendInt(b, int64(t.Second()), 10)
492 b = append(b, []byte{0x20}...)
500 // FmtTimeFull returns the full time representation of 't' for 'xog'
501 func (xog *xog) FmtTimeFull(t time.Time) string {
503 b := make([]byte, 0, 32)
509 b = strconv.AppendInt(b, int64(t.Hour()), 10)
510 b = append(b, xog.timeSeparator...)
516 b = strconv.AppendInt(b, int64(t.Minute()), 10)
517 b = append(b, xog.timeSeparator...)
523 b = strconv.AppendInt(b, int64(t.Second()), 10)
524 b = append(b, []byte{0x20}...)
528 if btz, ok := xog.timezones[tz]; ok {
529 b = append(b, btz...)