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 'dje' locale
43 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", "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"},
53 monthsAbbreviated: []string{"", "Žan", "Fee", "Mar", "Awi", "Me", "Žuw", "Žuy", "Ut", "Sek", "Okt", "Noo", "Dee"},
54 monthsNarrow: []string{"", "Ž", "F", "M", "A", "M", "Ž", "Ž", "U", "S", "O", "N", "D"},
55 monthsWide: []string{"", "Žanwiye", "Feewiriye", "Marsi", "Awiril", "Me", "Žuweŋ", "Žuyye", "Ut", "Sektanbur", "Oktoobur", "Noowanbur", "Deesanbur"},
56 daysAbbreviated: []string{"Alh", "Ati", "Ata", "Ala", "Alm", "Alz", "Asi"},
57 daysNarrow: []string{"H", "T", "T", "L", "M", "Z", "S"},
58 daysWide: []string{"Alhadi", "Atinni", "Atalaata", "Alarba", "Alhamisi", "Alzuma", "Asibti"},
59 periodsAbbreviated: []string{"Subbaahi", "Zaarikay b"},
60 periodsWide: []string{"Subbaahi", "Zaarikay b"},
61 erasAbbreviated: []string{"IJ", "IZ"},
62 erasNarrow: []string{"", ""},
63 erasWide: []string{"Isaa jine", "Isaa zamanoo"},
64 timezones: map[string]string{"AKST": "AKST", "WIB": "WIB", "CHAST": "CHAST", "HAST": "HAST", "HADT": "HADT", "IST": "IST", "COST": "COST", "WEZ": "WEZ", "AWDT": "AWDT", "EAT": "EAT", "GYT": "GYT", "SAST": "SAST", "PDT": "PDT", "CDT": "CDT", "ACWST": "ACWST", "ACWDT": "ACWDT", "HENOMX": "HENOMX", "AST": "AST", "ARST": "ARST", "HNPM": "HNPM", "WART": "WART", "WAT": "WAT", "HKST": "HKST", "EST": "EST", "HNPMX": "HNPMX", "HNCU": "HNCU", "BT": "BT", "∅∅∅": "∅∅∅", "HNOG": "HNOG", "MDT": "MDT", "TMT": "TMT", "MESZ": "MESZ", "JST": "JST", "HNNOMX": "HNNOMX", "HKT": "HKT", "EDT": "EDT", "ChST": "ChST", "AWST": "AWST", "UYT": "UYT", "NZDT": "NZDT", "WITA": "WITA", "ADT": "ADT", "WAST": "WAST", "SGT": "SGT", "CHADT": "CHADT", "BOT": "BOT", "COT": "COT", "CAT": "CAT", "WIT": "WIT", "JDT": "JDT", "OEZ": "OEZ", "ACDT": "ACDT", "SRT": "SRT", "HEEG": "HEEG", "HNT": "HNT", "CLST": "CLST", "GMT": "GMT", "TMST": "TMST", "AEDT": "AEDT", "HEOG": "HEOG", "HECU": "HECU", "CST": "CST", "MST": "MST", "MEZ": "MEZ", "OESZ": "OESZ", "VET": "VET", "HNEG": "HNEG", "HAT": "HAT", "MYT": "MYT", "UYST": "UYST", "AEST": "AEST", "PST": "PST", "HEPMX": "HEPMX", "NZST": "NZST", "LHDT": "LHDT", "ART": "ART", "WESZ": "WESZ", "HEPM": "HEPM", "LHST": "LHST", "WARST": "WARST", "AKDT": "AKDT", "ACST": "ACST", "ECT": "ECT", "CLT": "CLT", "GFT": "GFT"},
68 // Locale returns the current translators string locale
69 func (dje *dje) Locale() string {
73 // PluralsCardinal returns the list of cardinal plural rules associated with 'dje'
74 func (dje *dje) PluralsCardinal() []locales.PluralRule {
75 return dje.pluralsCardinal
78 // PluralsOrdinal returns the list of ordinal plural rules associated with 'dje'
79 func (dje *dje) PluralsOrdinal() []locales.PluralRule {
80 return dje.pluralsOrdinal
83 // PluralsRange returns the list of range plural rules associated with 'dje'
84 func (dje *dje) PluralsRange() []locales.PluralRule {
85 return dje.pluralsRange
88 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'dje'
89 func (dje *dje) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
90 return locales.PluralRuleUnknown
93 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'dje'
94 func (dje *dje) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
95 return locales.PluralRuleUnknown
98 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'dje'
99 func (dje *dje) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
100 return locales.PluralRuleUnknown
103 // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
104 func (dje *dje) MonthAbbreviated(month time.Month) string {
105 return dje.monthsAbbreviated[month]
108 // MonthsAbbreviated returns the locales abbreviated months
109 func (dje *dje) MonthsAbbreviated() []string {
110 return dje.monthsAbbreviated[1:]
113 // MonthNarrow returns the locales narrow month given the 'month' provided
114 func (dje *dje) MonthNarrow(month time.Month) string {
115 return dje.monthsNarrow[month]
118 // MonthsNarrow returns the locales narrow months
119 func (dje *dje) MonthsNarrow() []string {
120 return dje.monthsNarrow[1:]
123 // MonthWide returns the locales wide month given the 'month' provided
124 func (dje *dje) MonthWide(month time.Month) string {
125 return dje.monthsWide[month]
128 // MonthsWide returns the locales wide months
129 func (dje *dje) MonthsWide() []string {
130 return dje.monthsWide[1:]
133 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
134 func (dje *dje) WeekdayAbbreviated(weekday time.Weekday) string {
135 return dje.daysAbbreviated[weekday]
138 // WeekdaysAbbreviated returns the locales abbreviated weekdays
139 func (dje *dje) WeekdaysAbbreviated() []string {
140 return dje.daysAbbreviated
143 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
144 func (dje *dje) WeekdayNarrow(weekday time.Weekday) string {
145 return dje.daysNarrow[weekday]
148 // WeekdaysNarrow returns the locales narrow weekdays
149 func (dje *dje) WeekdaysNarrow() []string {
150 return dje.daysNarrow
153 // WeekdayShort returns the locales short weekday given the 'weekday' provided
154 func (dje *dje) WeekdayShort(weekday time.Weekday) string {
155 return dje.daysShort[weekday]
158 // WeekdaysShort returns the locales short weekdays
159 func (dje *dje) WeekdaysShort() []string {
163 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
164 func (dje *dje) WeekdayWide(weekday time.Weekday) string {
165 return dje.daysWide[weekday]
168 // WeekdaysWide returns the locales wide weekdays
169 func (dje *dje) WeekdaysWide() []string {
173 // Decimal returns the decimal point of number
174 func (dje *dje) Decimal() string {
178 // Group returns the group of number
179 func (dje *dje) Group() string {
183 // Group returns the minus sign of number
184 func (dje *dje) Minus() string {
188 // FmtNumber returns 'num' with digits/precision of 'v' for 'dje' and handles both Whole and Real numbers based on 'v'
189 func (dje *dje) FmtNumber(num float64, v uint64) string {
191 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
192 l := len(s) + 1 + 2*len(s[:len(s)-int(v)-1])/3
195 b := make([]byte, 0, l)
197 for i := len(s) - 1; i >= 0; i-- {
200 b = append(b, dje.decimal[0])
207 for j := len(dje.group) - 1; j >= 0; j-- {
208 b = append(b, dje.group[j])
220 b = append(b, dje.minus[0])
224 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
225 b[i], b[j] = b[j], b[i]
231 // FmtPercent returns 'num' with digits/precision of 'v' for 'dje' and handles both Whole and Real numbers based on 'v'
232 // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
233 func (dje *dje) FmtPercent(num float64, v uint64) string {
234 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
236 b := make([]byte, 0, l)
238 for i := len(s) - 1; i >= 0; i-- {
241 b = append(b, dje.decimal[0])
249 b = append(b, dje.minus[0])
253 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
254 b[i], b[j] = b[j], b[i]
257 b = append(b, dje.percent...)
262 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'dje'
263 func (dje *dje) FmtCurrency(num float64, v uint64, currency currency.Type) string {
265 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
266 symbol := dje.currencies[currency]
267 l := len(s) + len(symbol) + 1 + 2*len(s[:len(s)-int(v)-1])/3
270 b := make([]byte, 0, l)
272 for i := len(s) - 1; i >= 0; i-- {
275 b = append(b, dje.decimal[0])
282 for j := len(dje.group) - 1; j >= 0; j-- {
283 b = append(b, dje.group[j])
295 b = append(b, dje.minus[0])
299 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
300 b[i], b[j] = b[j], b[i]
306 b = append(b, dje.decimal...)
309 for i := 0; i < 2-int(v); i++ {
314 b = append(b, symbol...)
319 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'dje'
320 // in accounting notation.
321 func (dje *dje) FmtAccounting(num float64, v uint64, currency currency.Type) string {
323 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
324 symbol := dje.currencies[currency]
325 l := len(s) + len(symbol) + 1 + 2*len(s[:len(s)-int(v)-1])/3
328 b := make([]byte, 0, l)
330 for i := len(s) - 1; i >= 0; i-- {
333 b = append(b, dje.decimal[0])
340 for j := len(dje.group) - 1; j >= 0; j-- {
341 b = append(b, dje.group[j])
354 b = append(b, dje.minus[0])
359 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
360 b[i], b[j] = b[j], b[i]
366 b = append(b, dje.decimal...)
369 for i := 0; i < 2-int(v); i++ {
375 b = append(b, symbol...)
378 b = append(b, symbol...)
384 // FmtDateShort returns the short date representation of 't' for 'dje'
385 func (dje *dje) FmtDateShort(t time.Time) string {
387 b := make([]byte, 0, 32)
389 b = strconv.AppendInt(b, int64(t.Day()), 10)
390 b = append(b, []byte{0x2f}...)
391 b = strconv.AppendInt(b, int64(t.Month()), 10)
392 b = append(b, []byte{0x2f}...)
395 b = strconv.AppendInt(b, int64(t.Year()), 10)
397 b = strconv.AppendInt(b, int64(-t.Year()), 10)
403 // FmtDateMedium returns the medium date representation of 't' for 'dje'
404 func (dje *dje) FmtDateMedium(t time.Time) string {
406 b := make([]byte, 0, 32)
408 b = strconv.AppendInt(b, int64(t.Day()), 10)
409 b = append(b, []byte{0x20}...)
410 b = append(b, dje.monthsAbbreviated[t.Month()]...)
411 b = append(b, []byte{0x2c, 0x20}...)
414 b = strconv.AppendInt(b, int64(t.Year()), 10)
416 b = strconv.AppendInt(b, int64(-t.Year()), 10)
422 // FmtDateLong returns the long date representation of 't' for 'dje'
423 func (dje *dje) FmtDateLong(t time.Time) string {
425 b := make([]byte, 0, 32)
427 b = strconv.AppendInt(b, int64(t.Day()), 10)
428 b = append(b, []byte{0x20}...)
429 b = append(b, dje.monthsWide[t.Month()]...)
430 b = append(b, []byte{0x20}...)
433 b = strconv.AppendInt(b, int64(t.Year()), 10)
435 b = strconv.AppendInt(b, int64(-t.Year()), 10)
441 // FmtDateFull returns the full date representation of 't' for 'dje'
442 func (dje *dje) FmtDateFull(t time.Time) string {
444 b := make([]byte, 0, 32)
446 b = append(b, dje.daysWide[t.Weekday()]...)
447 b = append(b, []byte{0x20}...)
448 b = strconv.AppendInt(b, int64(t.Day()), 10)
449 b = append(b, []byte{0x20}...)
450 b = append(b, dje.monthsWide[t.Month()]...)
451 b = append(b, []byte{0x20}...)
454 b = strconv.AppendInt(b, int64(t.Year()), 10)
456 b = strconv.AppendInt(b, int64(-t.Year()), 10)
462 // FmtTimeShort returns the short time representation of 't' for 'dje'
463 func (dje *dje) FmtTimeShort(t time.Time) string {
465 b := make([]byte, 0, 32)
471 b = strconv.AppendInt(b, int64(t.Hour()), 10)
472 b = append(b, dje.timeSeparator...)
478 b = strconv.AppendInt(b, int64(t.Minute()), 10)
483 // FmtTimeMedium returns the medium time representation of 't' for 'dje'
484 func (dje *dje) FmtTimeMedium(t time.Time) string {
486 b := make([]byte, 0, 32)
492 b = strconv.AppendInt(b, int64(t.Hour()), 10)
493 b = append(b, dje.timeSeparator...)
499 b = strconv.AppendInt(b, int64(t.Minute()), 10)
500 b = append(b, dje.timeSeparator...)
506 b = strconv.AppendInt(b, int64(t.Second()), 10)
511 // FmtTimeLong returns the long time representation of 't' for 'dje'
512 func (dje *dje) FmtTimeLong(t time.Time) string {
514 b := make([]byte, 0, 32)
520 b = strconv.AppendInt(b, int64(t.Hour()), 10)
521 b = append(b, dje.timeSeparator...)
527 b = strconv.AppendInt(b, int64(t.Minute()), 10)
528 b = append(b, dje.timeSeparator...)
534 b = strconv.AppendInt(b, int64(t.Second()), 10)
535 b = append(b, []byte{0x20}...)
543 // FmtTimeFull returns the full time representation of 't' for 'dje'
544 func (dje *dje) FmtTimeFull(t time.Time) string {
546 b := make([]byte, 0, 32)
552 b = strconv.AppendInt(b, int64(t.Hour()), 10)
553 b = append(b, dje.timeSeparator...)
559 b = strconv.AppendInt(b, int64(t.Minute()), 10)
560 b = append(b, dje.timeSeparator...)
566 b = strconv.AppendInt(b, int64(t.Second()), 10)
567 b = append(b, []byte{0x20}...)
571 if btz, ok := dje.timezones[tz]; ok {
572 b = append(b, btz...)