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 'dyo' locale
45 func New() locales.Translator {
54 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"},
55 currencyPositiveSuffix: " ",
56 currencyNegativeSuffix: " ",
57 monthsAbbreviated: []string{"", "Sa", "Fe", "Ma", "Ab", "Me", "Su", "Sú", "Ut", "Se", "Ok", "No", "De"},
58 monthsNarrow: []string{"", "S", "F", "M", "A", "M", "S", "S", "U", "S", "O", "N", "D"},
59 monthsWide: []string{"", "Sanvie", "Fébirie", "Mars", "Aburil", "Mee", "Sueŋ", "Súuyee", "Ut", "Settembar", "Oktobar", "Novembar", "Disambar"},
60 daysAbbreviated: []string{"Dim", "Ten", "Tal", "Ala", "Ara", "Arj", "Sib"},
61 daysNarrow: []string{"D", "T", "T", "A", "A", "A", "S"},
62 daysWide: []string{"Dimas", "Teneŋ", "Talata", "Alarbay", "Aramisay", "Arjuma", "Sibiti"},
63 erasAbbreviated: []string{"ArY", "AtY"},
64 erasNarrow: []string{"", ""},
65 erasWide: []string{"Ariŋuu Yeesu", "Atooŋe Yeesu"},
66 timezones: map[string]string{"AKST": "AKST", "AKDT": "AKDT", "NZST": "NZST", "TMT": "TMT", "WART": "WART", "OESZ": "OESZ", "CLT": "CLT", "BOT": "BOT", "WARST": "WARST", "ECT": "ECT", "WESZ": "WESZ", "GYT": "GYT", "SGT": "SGT", "CAT": "CAT", "MDT": "MDT", "HAST": "HAST", "TMST": "TMST", "LHST": "LHST", "IST": "IST", "WIB": "WIB", "GMT": "GMT", "HNCU": "HNCU", "HEOG": "HEOG", "HEEG": "HEEG", "HKST": "HKST", "HAT": "HAT", "WEZ": "WEZ", "ChST": "ChST", "PST": "PST", "AWST": "AWST", "MEZ": "MEZ", "WAT": "WAT", "EAT": "EAT", "ACST": "ACST", "CDT": "CDT", "HADT": "HADT", "ARST": "ARST", "HKT": "HKT", "COT": "COT", "WITA": "WITA", "HNPM": "HNPM", "HEPM": "HEPM", "PDT": "PDT", "HECU": "HECU", "HNNOMX": "HNNOMX", "HENOMX": "HENOMX", "JDT": "JDT", "AEST": "AEST", "AST": "AST", "CST": "CST", "MESZ": "MESZ", "SAST": "SAST", "ACDT": "ACDT", "HNPMX": "HNPMX", "AWDT": "AWDT", "UYT": "UYT", "VET": "VET", "ART": "ART", "GFT": "GFT", "OEZ": "OEZ", "CHADT": "CHADT", "NZDT": "NZDT", "EDT": "EDT", "HEPMX": "HEPMX", "HNEG": "HNEG", "MST": "MST", "ACWDT": "ACWDT", "JST": "JST", "ADT": "ADT", "WAST": "WAST", "UYST": "UYST", "CLST": "CLST", "COST": "COST", "CHAST": "CHAST", "AEDT": "AEDT", "HNT": "HNT", "BT": "BT", "SRT": "SRT", "∅∅∅": "∅∅∅", "MYT": "MYT", "WIT": "WIT", "ACWST": "ACWST", "LHDT": "LHDT", "HNOG": "HNOG", "EST": "EST"},
70 // Locale returns the current translators string locale
71 func (dyo *dyo) Locale() string {
75 // PluralsCardinal returns the list of cardinal plural rules associated with 'dyo'
76 func (dyo *dyo) PluralsCardinal() []locales.PluralRule {
77 return dyo.pluralsCardinal
80 // PluralsOrdinal returns the list of ordinal plural rules associated with 'dyo'
81 func (dyo *dyo) PluralsOrdinal() []locales.PluralRule {
82 return dyo.pluralsOrdinal
85 // PluralsRange returns the list of range plural rules associated with 'dyo'
86 func (dyo *dyo) PluralsRange() []locales.PluralRule {
87 return dyo.pluralsRange
90 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'dyo'
91 func (dyo *dyo) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
92 return locales.PluralRuleUnknown
95 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'dyo'
96 func (dyo *dyo) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
97 return locales.PluralRuleUnknown
100 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'dyo'
101 func (dyo *dyo) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
102 return locales.PluralRuleUnknown
105 // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
106 func (dyo *dyo) MonthAbbreviated(month time.Month) string {
107 return dyo.monthsAbbreviated[month]
110 // MonthsAbbreviated returns the locales abbreviated months
111 func (dyo *dyo) MonthsAbbreviated() []string {
112 return dyo.monthsAbbreviated[1:]
115 // MonthNarrow returns the locales narrow month given the 'month' provided
116 func (dyo *dyo) MonthNarrow(month time.Month) string {
117 return dyo.monthsNarrow[month]
120 // MonthsNarrow returns the locales narrow months
121 func (dyo *dyo) MonthsNarrow() []string {
122 return dyo.monthsNarrow[1:]
125 // MonthWide returns the locales wide month given the 'month' provided
126 func (dyo *dyo) MonthWide(month time.Month) string {
127 return dyo.monthsWide[month]
130 // MonthsWide returns the locales wide months
131 func (dyo *dyo) MonthsWide() []string {
132 return dyo.monthsWide[1:]
135 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
136 func (dyo *dyo) WeekdayAbbreviated(weekday time.Weekday) string {
137 return dyo.daysAbbreviated[weekday]
140 // WeekdaysAbbreviated returns the locales abbreviated weekdays
141 func (dyo *dyo) WeekdaysAbbreviated() []string {
142 return dyo.daysAbbreviated
145 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
146 func (dyo *dyo) WeekdayNarrow(weekday time.Weekday) string {
147 return dyo.daysNarrow[weekday]
150 // WeekdaysNarrow returns the locales narrow weekdays
151 func (dyo *dyo) WeekdaysNarrow() []string {
152 return dyo.daysNarrow
155 // WeekdayShort returns the locales short weekday given the 'weekday' provided
156 func (dyo *dyo) WeekdayShort(weekday time.Weekday) string {
157 return dyo.daysShort[weekday]
160 // WeekdaysShort returns the locales short weekdays
161 func (dyo *dyo) WeekdaysShort() []string {
165 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
166 func (dyo *dyo) WeekdayWide(weekday time.Weekday) string {
167 return dyo.daysWide[weekday]
170 // WeekdaysWide returns the locales wide weekdays
171 func (dyo *dyo) WeekdaysWide() []string {
175 // Decimal returns the decimal point of number
176 func (dyo *dyo) Decimal() string {
180 // Group returns the group of number
181 func (dyo *dyo) Group() string {
185 // Group returns the minus sign of number
186 func (dyo *dyo) Minus() string {
190 // FmtNumber returns 'num' with digits/precision of 'v' for 'dyo' and handles both Whole and Real numbers based on 'v'
191 func (dyo *dyo) FmtNumber(num float64, v uint64) string {
193 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
194 l := len(s) + 1 + 2*len(s[:len(s)-int(v)-1])/3
197 b := make([]byte, 0, l)
199 for i := len(s) - 1; i >= 0; i-- {
202 b = append(b, dyo.decimal[0])
209 for j := len(dyo.group) - 1; j >= 0; j-- {
210 b = append(b, dyo.group[j])
222 b = append(b, dyo.minus[0])
226 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
227 b[i], b[j] = b[j], b[i]
233 // FmtPercent returns 'num' with digits/precision of 'v' for 'dyo' and handles both Whole and Real numbers based on 'v'
234 // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
235 func (dyo *dyo) FmtPercent(num float64, v uint64) string {
236 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
238 b := make([]byte, 0, l)
240 for i := len(s) - 1; i >= 0; i-- {
243 b = append(b, dyo.decimal[0])
251 b = append(b, dyo.minus[0])
255 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
256 b[i], b[j] = b[j], b[i]
259 b = append(b, dyo.percent...)
264 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'dyo'
265 func (dyo *dyo) FmtCurrency(num float64, v uint64, currency currency.Type) string {
267 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
268 symbol := dyo.currencies[currency]
269 l := len(s) + len(symbol) + 3 + 2*len(s[:len(s)-int(v)-1])/3
272 b := make([]byte, 0, l)
274 for i := len(s) - 1; i >= 0; i-- {
277 b = append(b, dyo.decimal[0])
284 for j := len(dyo.group) - 1; j >= 0; j-- {
285 b = append(b, dyo.group[j])
297 b = append(b, dyo.minus[0])
301 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
302 b[i], b[j] = b[j], b[i]
308 b = append(b, dyo.decimal...)
311 for i := 0; i < 2-int(v); i++ {
316 b = append(b, dyo.currencyPositiveSuffix...)
318 b = append(b, symbol...)
323 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'dyo'
324 // in accounting notation.
325 func (dyo *dyo) FmtAccounting(num float64, v uint64, currency currency.Type) string {
327 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
328 symbol := dyo.currencies[currency]
329 l := len(s) + len(symbol) + 3 + 2*len(s[:len(s)-int(v)-1])/3
332 b := make([]byte, 0, l)
334 for i := len(s) - 1; i >= 0; i-- {
337 b = append(b, dyo.decimal[0])
344 for j := len(dyo.group) - 1; j >= 0; j-- {
345 b = append(b, dyo.group[j])
358 b = append(b, dyo.minus[0])
363 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
364 b[i], b[j] = b[j], b[i]
370 b = append(b, dyo.decimal...)
373 for i := 0; i < 2-int(v); i++ {
379 b = append(b, dyo.currencyNegativeSuffix...)
380 b = append(b, symbol...)
383 b = append(b, dyo.currencyPositiveSuffix...)
384 b = append(b, symbol...)
390 // FmtDateShort returns the short date representation of 't' for 'dyo'
391 func (dyo *dyo) FmtDateShort(t time.Time) string {
393 b := make([]byte, 0, 32)
395 b = strconv.AppendInt(b, int64(t.Day()), 10)
396 b = append(b, []byte{0x2f}...)
397 b = strconv.AppendInt(b, int64(t.Month()), 10)
398 b = append(b, []byte{0x2f}...)
401 b = strconv.AppendInt(b, int64(t.Year()), 10)
403 b = strconv.AppendInt(b, int64(-t.Year()), 10)
409 // FmtDateMedium returns the medium date representation of 't' for 'dyo'
410 func (dyo *dyo) FmtDateMedium(t time.Time) string {
412 b := make([]byte, 0, 32)
414 b = strconv.AppendInt(b, int64(t.Day()), 10)
415 b = append(b, []byte{0x20}...)
416 b = append(b, dyo.monthsAbbreviated[t.Month()]...)
417 b = append(b, []byte{0x20}...)
420 b = strconv.AppendInt(b, int64(t.Year()), 10)
422 b = strconv.AppendInt(b, int64(-t.Year()), 10)
428 // FmtDateLong returns the long date representation of 't' for 'dyo'
429 func (dyo *dyo) FmtDateLong(t time.Time) string {
431 b := make([]byte, 0, 32)
433 b = strconv.AppendInt(b, int64(t.Day()), 10)
434 b = append(b, []byte{0x20}...)
435 b = append(b, dyo.monthsWide[t.Month()]...)
436 b = append(b, []byte{0x20}...)
439 b = strconv.AppendInt(b, int64(t.Year()), 10)
441 b = strconv.AppendInt(b, int64(-t.Year()), 10)
447 // FmtDateFull returns the full date representation of 't' for 'dyo'
448 func (dyo *dyo) FmtDateFull(t time.Time) string {
450 b := make([]byte, 0, 32)
452 b = append(b, dyo.daysWide[t.Weekday()]...)
453 b = append(b, []byte{0x20}...)
454 b = strconv.AppendInt(b, int64(t.Day()), 10)
455 b = append(b, []byte{0x20}...)
456 b = append(b, dyo.monthsWide[t.Month()]...)
457 b = append(b, []byte{0x20}...)
460 b = strconv.AppendInt(b, int64(t.Year()), 10)
462 b = strconv.AppendInt(b, int64(-t.Year()), 10)
468 // FmtTimeShort returns the short time representation of 't' for 'dyo'
469 func (dyo *dyo) FmtTimeShort(t time.Time) string {
471 b := make([]byte, 0, 32)
477 b = strconv.AppendInt(b, int64(t.Hour()), 10)
478 b = append(b, dyo.timeSeparator...)
484 b = strconv.AppendInt(b, int64(t.Minute()), 10)
489 // FmtTimeMedium returns the medium time representation of 't' for 'dyo'
490 func (dyo *dyo) FmtTimeMedium(t time.Time) string {
492 b := make([]byte, 0, 32)
498 b = strconv.AppendInt(b, int64(t.Hour()), 10)
499 b = append(b, dyo.timeSeparator...)
505 b = strconv.AppendInt(b, int64(t.Minute()), 10)
506 b = append(b, dyo.timeSeparator...)
512 b = strconv.AppendInt(b, int64(t.Second()), 10)
517 // FmtTimeLong returns the long time representation of 't' for 'dyo'
518 func (dyo *dyo) FmtTimeLong(t time.Time) string {
520 b := make([]byte, 0, 32)
526 b = strconv.AppendInt(b, int64(t.Hour()), 10)
527 b = append(b, dyo.timeSeparator...)
533 b = strconv.AppendInt(b, int64(t.Minute()), 10)
534 b = append(b, dyo.timeSeparator...)
540 b = strconv.AppendInt(b, int64(t.Second()), 10)
541 b = append(b, []byte{0x20}...)
549 // FmtTimeFull returns the full time representation of 't' for 'dyo'
550 func (dyo *dyo) FmtTimeFull(t time.Time) string {
552 b := make([]byte, 0, 32)
558 b = strconv.AppendInt(b, int64(t.Hour()), 10)
559 b = append(b, dyo.timeSeparator...)
565 b = strconv.AppendInt(b, int64(t.Minute()), 10)
566 b = append(b, dyo.timeSeparator...)
572 b = strconv.AppendInt(b, int64(t.Second()), 10)
573 b = append(b, []byte{0x20}...)
577 if btz, ok := dyo.timezones[tz]; ok {
578 b = append(b, btz...)