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 currencyPositivePrefix string
26 currencyNegativePrefix 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 'jgo' locale
45 func New() locales.Translator {
48 pluralsCardinal: []locales.PluralRule{2, 6},
58 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", "FCFA", "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"},
59 currencyPositivePrefix: " ",
60 currencyNegativePrefix: " ",
61 monthsAbbreviated: []string{"", "Nduŋmbi Saŋ", "Pɛsaŋ Pɛ́pá", "Pɛsaŋ Pɛ́tát", "Pɛsaŋ Pɛ́nɛ́kwa", "Pɛsaŋ Pataa", "Pɛsaŋ Pɛ́nɛ́ntúkú", "Pɛsaŋ Saambá", "Pɛsaŋ Pɛ́nɛ́fɔm", "Pɛsaŋ Pɛ́nɛ́pfúꞋú", "Pɛsaŋ Nɛgɛ́m", "Pɛsaŋ Ntsɔ̌pmɔ́", "Pɛsaŋ Ntsɔ̌ppá"},
62 monthsNarrow: []string{"", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"},
63 monthsWide: []string{"", "Nduŋmbi Saŋ", "Pɛsaŋ Pɛ́pá", "Pɛsaŋ Pɛ́tát", "Pɛsaŋ Pɛ́nɛ́kwa", "Pɛsaŋ Pataa", "Pɛsaŋ Pɛ́nɛ́ntúkú", "Pɛsaŋ Saambá", "Pɛsaŋ Pɛ́nɛ́fɔm", "Pɛsaŋ Pɛ́nɛ́pfúꞋú", "Pɛsaŋ Nɛgɛ́m", "Pɛsaŋ Ntsɔ̌pmɔ́", "Pɛsaŋ Ntsɔ̌ppá"},
64 daysAbbreviated: []string{"Sɔ́ndi", "Mɔ́ndi", "Ápta Mɔ́ndi", "Wɛ́nɛsɛdɛ", "Tɔ́sɛdɛ", "Fɛlâyɛdɛ", "Sásidɛ"},
65 daysNarrow: []string{"Sɔ́", "Mɔ́", "ÁM", "Wɛ́", "Tɔ́", "Fɛ", "Sá"},
66 daysWide: []string{"Sɔ́ndi", "Mɔ́ndi", "Ápta Mɔ́ndi", "Wɛ́nɛsɛdɛ", "Tɔ́sɛdɛ", "Fɛlâyɛdɛ", "Sásidɛ"},
67 periodsAbbreviated: []string{"mbaꞌmbaꞌ", "ŋka mbɔ́t nji"},
68 periodsWide: []string{"mbaꞌmbaꞌ", "ŋka mbɔ́t nji"},
69 erasAbbreviated: []string{"BCE", "CE"},
70 erasNarrow: []string{"", ""},
71 erasWide: []string{"tsɛttsɛt mɛŋguꞌ mi ɛ́ lɛɛnɛ Kɛlísɛtɔ gɔ ńɔ́", "tsɛttsɛt mɛŋguꞌ mi ɛ́ fúnɛ Kɛlísɛtɔ tɔ́ mɔ́"},
72 timezones: map[string]string{"CHAST": "CHAST", "NZDT": "NZDT", "WITA": "WITA", "HNT": "HNT", "EDT": "EDT", "ACDT": "ACDT", "HNCU": "HNCU", "VET": "VET", "HENOMX": "HENOMX", "GMT": "GMT", "CHADT": "CHADT", "HAST": "HAST", "IST": "IST", "BT": "BT", "AWST": "AWST", "HECU": "HECU", "BOT": "BOT", "CST": "CST", "UYT": "UYT", "NZST": "NZST", "MDT": "MDT", "OESZ": "OESZ", "AEST": "AEST", "WAT": "WAT", "EAT": "EAT", "WART": "WART", "WARST": "WARST", "HEOG": "HEOG", "SAST": "SAST", "SRT": "SRT", "ACWDT": "ACWDT", "WESZ": "WESZ", "WIB": "WIB", "HEPM": "HEPM", "CDT": "CDT", "ACWST": "ACWST", "TMST": "TMST", "OEZ": "OEZ", "ARST": "ARST", "HAT": "HAT", "SGT": "SGT", "PDT": "PDT", "PST": "PST", "HNNOMX": "HNNOMX", "HKST": "HKST", "WEZ": "WEZ", "HEPMX": "HEPMX", "ChST": "ChST", "ART": "ART", "HNEG": "HNEG", "GYT": "GYT", "TMT": "TMT", "HADT": "HADT", "JST": "JST", "LHST": "LHST", "HEEG": "HEEG", "AKDT": "AKDT", "CAT": "CAT", "MST": "MST", "HNOG": "HNOG", "WAST": "WAST", "EST": "EST", "MYT": "MYT", "HNPMX": "HNPMX", "WIT": "WIT", "AST": "AST", "ADT": "ADT", "CLST": "CLST", "COT": "COT", "AKST": "AKST", "JDT": "JDT", "AEDT": "AEDT", "MESZ": "MESZ", "∅∅∅": "∅∅∅", "ECT": "ECT", "HNPM": "HNPM", "AWDT": "AWDT", "ACST": "ACST", "UYST": "UYST", "MEZ": "MEZ", "LHDT": "LHDT", "CLT": "CLT", "COST": "COST", "GFT": "GFT", "HKT": "HKT"},
76 // Locale returns the current translators string locale
77 func (jgo *jgo) Locale() string {
81 // PluralsCardinal returns the list of cardinal plural rules associated with 'jgo'
82 func (jgo *jgo) PluralsCardinal() []locales.PluralRule {
83 return jgo.pluralsCardinal
86 // PluralsOrdinal returns the list of ordinal plural rules associated with 'jgo'
87 func (jgo *jgo) PluralsOrdinal() []locales.PluralRule {
88 return jgo.pluralsOrdinal
91 // PluralsRange returns the list of range plural rules associated with 'jgo'
92 func (jgo *jgo) PluralsRange() []locales.PluralRule {
93 return jgo.pluralsRange
96 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'jgo'
97 func (jgo *jgo) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
102 return locales.PluralRuleOne
105 return locales.PluralRuleOther
108 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'jgo'
109 func (jgo *jgo) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
110 return locales.PluralRuleUnknown
113 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'jgo'
114 func (jgo *jgo) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
115 return locales.PluralRuleUnknown
118 // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
119 func (jgo *jgo) MonthAbbreviated(month time.Month) string {
120 return jgo.monthsAbbreviated[month]
123 // MonthsAbbreviated returns the locales abbreviated months
124 func (jgo *jgo) MonthsAbbreviated() []string {
125 return jgo.monthsAbbreviated[1:]
128 // MonthNarrow returns the locales narrow month given the 'month' provided
129 func (jgo *jgo) MonthNarrow(month time.Month) string {
130 return jgo.monthsNarrow[month]
133 // MonthsNarrow returns the locales narrow months
134 func (jgo *jgo) MonthsNarrow() []string {
135 return jgo.monthsNarrow[1:]
138 // MonthWide returns the locales wide month given the 'month' provided
139 func (jgo *jgo) MonthWide(month time.Month) string {
140 return jgo.monthsWide[month]
143 // MonthsWide returns the locales wide months
144 func (jgo *jgo) MonthsWide() []string {
145 return jgo.monthsWide[1:]
148 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
149 func (jgo *jgo) WeekdayAbbreviated(weekday time.Weekday) string {
150 return jgo.daysAbbreviated[weekday]
153 // WeekdaysAbbreviated returns the locales abbreviated weekdays
154 func (jgo *jgo) WeekdaysAbbreviated() []string {
155 return jgo.daysAbbreviated
158 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
159 func (jgo *jgo) WeekdayNarrow(weekday time.Weekday) string {
160 return jgo.daysNarrow[weekday]
163 // WeekdaysNarrow returns the locales narrow weekdays
164 func (jgo *jgo) WeekdaysNarrow() []string {
165 return jgo.daysNarrow
168 // WeekdayShort returns the locales short weekday given the 'weekday' provided
169 func (jgo *jgo) WeekdayShort(weekday time.Weekday) string {
170 return jgo.daysShort[weekday]
173 // WeekdaysShort returns the locales short weekdays
174 func (jgo *jgo) WeekdaysShort() []string {
178 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
179 func (jgo *jgo) WeekdayWide(weekday time.Weekday) string {
180 return jgo.daysWide[weekday]
183 // WeekdaysWide returns the locales wide weekdays
184 func (jgo *jgo) WeekdaysWide() []string {
188 // Decimal returns the decimal point of number
189 func (jgo *jgo) Decimal() string {
193 // Group returns the group of number
194 func (jgo *jgo) Group() string {
198 // Group returns the minus sign of number
199 func (jgo *jgo) Minus() string {
203 // FmtNumber returns 'num' with digits/precision of 'v' for 'jgo' and handles both Whole and Real numbers based on 'v'
204 func (jgo *jgo) FmtNumber(num float64, v uint64) string {
206 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
207 l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
210 b := make([]byte, 0, l)
212 for i := len(s) - 1; i >= 0; i-- {
215 b = append(b, jgo.decimal[0])
222 b = append(b, jgo.group[0])
233 b = append(b, jgo.minus[0])
237 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
238 b[i], b[j] = b[j], b[i]
244 // FmtPercent returns 'num' with digits/precision of 'v' for 'jgo' and handles both Whole and Real numbers based on 'v'
245 // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
246 func (jgo *jgo) FmtPercent(num float64, v uint64) string {
247 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
249 b := make([]byte, 0, l)
251 for i := len(s) - 1; i >= 0; i-- {
254 b = append(b, jgo.decimal[0])
262 b = append(b, jgo.minus[0])
266 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
267 b[i], b[j] = b[j], b[i]
270 b = append(b, jgo.percent...)
275 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'jgo'
276 func (jgo *jgo) FmtCurrency(num float64, v uint64, currency currency.Type) string {
278 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
279 symbol := jgo.currencies[currency]
280 l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
283 b := make([]byte, 0, l)
285 for i := len(s) - 1; i >= 0; i-- {
288 b = append(b, jgo.decimal[0])
295 b = append(b, jgo.group[0])
305 for j := len(symbol) - 1; j >= 0; j-- {
306 b = append(b, symbol[j])
309 for j := len(jgo.currencyPositivePrefix) - 1; j >= 0; j-- {
310 b = append(b, jgo.currencyPositivePrefix[j])
314 b = append(b, jgo.minus[0])
318 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
319 b[i], b[j] = b[j], b[i]
325 b = append(b, jgo.decimal...)
328 for i := 0; i < 2-int(v); i++ {
336 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'jgo'
337 // in accounting notation.
338 func (jgo *jgo) FmtAccounting(num float64, v uint64, currency currency.Type) string {
340 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
341 symbol := jgo.currencies[currency]
342 l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
345 b := make([]byte, 0, l)
347 for i := len(s) - 1; i >= 0; i-- {
350 b = append(b, jgo.decimal[0])
357 b = append(b, jgo.group[0])
369 for j := len(symbol) - 1; j >= 0; j-- {
370 b = append(b, symbol[j])
373 for j := len(jgo.currencyNegativePrefix) - 1; j >= 0; j-- {
374 b = append(b, jgo.currencyNegativePrefix[j])
377 b = append(b, jgo.minus[0])
381 for j := len(symbol) - 1; j >= 0; j-- {
382 b = append(b, symbol[j])
385 for j := len(jgo.currencyPositivePrefix) - 1; j >= 0; j-- {
386 b = append(b, jgo.currencyPositivePrefix[j])
392 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
393 b[i], b[j] = b[j], b[i]
399 b = append(b, jgo.decimal...)
402 for i := 0; i < 2-int(v); i++ {
410 // FmtDateShort returns the short date representation of 't' for 'jgo'
411 func (jgo *jgo) FmtDateShort(t time.Time) string {
413 b := make([]byte, 0, 32)
416 b = strconv.AppendInt(b, int64(t.Year()), 10)
418 b = strconv.AppendInt(b, int64(-t.Year()), 10)
421 b = append(b, []byte{0x2d}...)
427 b = strconv.AppendInt(b, int64(t.Month()), 10)
429 b = append(b, []byte{0x2d}...)
435 b = strconv.AppendInt(b, int64(t.Day()), 10)
440 // FmtDateMedium returns the medium date representation of 't' for 'jgo'
441 func (jgo *jgo) FmtDateMedium(t time.Time) string {
443 b := make([]byte, 0, 32)
446 b = strconv.AppendInt(b, int64(t.Year()), 10)
448 b = strconv.AppendInt(b, int64(-t.Year()), 10)
451 b = append(b, []byte{0x20}...)
452 b = append(b, jgo.monthsAbbreviated[t.Month()]...)
453 b = append(b, []byte{0x20}...)
454 b = strconv.AppendInt(b, int64(t.Day()), 10)
459 // FmtDateLong returns the long date representation of 't' for 'jgo'
460 func (jgo *jgo) FmtDateLong(t time.Time) string {
462 b := make([]byte, 0, 32)
465 b = strconv.AppendInt(b, int64(t.Year()), 10)
467 b = strconv.AppendInt(b, int64(-t.Year()), 10)
470 b = append(b, []byte{0x20}...)
471 b = append(b, jgo.monthsWide[t.Month()]...)
472 b = append(b, []byte{0x20}...)
473 b = strconv.AppendInt(b, int64(t.Day()), 10)
478 // FmtDateFull returns the full date representation of 't' for 'jgo'
479 func (jgo *jgo) FmtDateFull(t time.Time) string {
481 b := make([]byte, 0, 32)
483 b = append(b, jgo.daysWide[t.Weekday()]...)
484 b = append(b, []byte{0x2c, 0x20}...)
487 b = strconv.AppendInt(b, int64(t.Year()), 10)
489 b = strconv.AppendInt(b, int64(-t.Year()), 10)
492 b = append(b, []byte{0x20}...)
493 b = append(b, jgo.monthsWide[t.Month()]...)
494 b = append(b, []byte{0x20}...)
500 b = strconv.AppendInt(b, int64(t.Day()), 10)
505 // FmtTimeShort returns the short time representation of 't' for 'jgo'
506 func (jgo *jgo) FmtTimeShort(t time.Time) string {
508 b := make([]byte, 0, 32)
514 b = strconv.AppendInt(b, int64(t.Hour()), 10)
515 b = append(b, jgo.timeSeparator...)
521 b = strconv.AppendInt(b, int64(t.Minute()), 10)
526 // FmtTimeMedium returns the medium time representation of 't' for 'jgo'
527 func (jgo *jgo) FmtTimeMedium(t time.Time) string {
529 b := make([]byte, 0, 32)
535 b = strconv.AppendInt(b, int64(t.Hour()), 10)
536 b = append(b, jgo.timeSeparator...)
542 b = strconv.AppendInt(b, int64(t.Minute()), 10)
543 b = append(b, jgo.timeSeparator...)
549 b = strconv.AppendInt(b, int64(t.Second()), 10)
554 // FmtTimeLong returns the long time representation of 't' for 'jgo'
555 func (jgo *jgo) FmtTimeLong(t time.Time) string {
557 b := make([]byte, 0, 32)
563 b = strconv.AppendInt(b, int64(t.Hour()), 10)
564 b = append(b, jgo.timeSeparator...)
570 b = strconv.AppendInt(b, int64(t.Minute()), 10)
571 b = append(b, jgo.timeSeparator...)
577 b = strconv.AppendInt(b, int64(t.Second()), 10)
578 b = append(b, []byte{0x20}...)
586 // FmtTimeFull returns the full time representation of 't' for 'jgo'
587 func (jgo *jgo) FmtTimeFull(t time.Time) string {
589 b := make([]byte, 0, 32)
595 b = strconv.AppendInt(b, int64(t.Hour()), 10)
596 b = append(b, jgo.timeSeparator...)
602 b = strconv.AppendInt(b, int64(t.Minute()), 10)
603 b = append(b, jgo.timeSeparator...)
609 b = strconv.AppendInt(b, int64(t.Second()), 10)
610 b = append(b, []byte{0x20}...)
614 if btz, ok := jgo.timezones[tz]; ok {
615 b = append(b, btz...)