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
25 currencies []string // idx = enum of currency code
26 currencyPositiveSuffix string
27 currencyNegativeSuffix string
28 monthsAbbreviated []string
31 daysAbbreviated []string
35 periodsAbbreviated []string
36 periodsNarrow []string
39 erasAbbreviated []string
42 timezones map[string]string
45 // New returns a new instance of translator for the 'dua' locale
46 func New() locales.Translator {
55 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"},
57 currencyPositiveSuffix: " ",
58 currencyNegativeSuffix: " ",
59 monthsAbbreviated: []string{"", "di", "ŋgɔn", "sɔŋ", "diɓ", "emi", "esɔ", "mad", "diŋ", "nyɛt", "may", "tin", "elá"},
60 monthsNarrow: []string{"", "d", "ŋ", "s", "d", "e", "e", "m", "d", "n", "m", "t", "e"},
61 monthsWide: []string{"", "dimɔ́di", "ŋgɔndɛ", "sɔŋɛ", "diɓáɓá", "emiasele", "esɔpɛsɔpɛ", "madiɓɛ́díɓɛ́", "diŋgindi", "nyɛtɛki", "mayésɛ́", "tiníní", "eláŋgɛ́"},
62 daysAbbreviated: []string{"ét", "mɔ́s", "kwa", "muk", "ŋgi", "ɗón", "esa"},
63 daysNarrow: []string{"e", "m", "k", "m", "ŋ", "ɗ", "e"},
64 daysWide: []string{"éti", "mɔ́sú", "kwasú", "mukɔ́sú", "ŋgisú", "ɗónɛsú", "esaɓasú"},
65 periodsAbbreviated: []string{"idiɓa", "ebyámu"},
66 periodsWide: []string{"idiɓa", "ebyámu"},
67 erasAbbreviated: []string{"ɓ.Ys", "mb.Ys"},
68 erasNarrow: []string{"", ""},
69 erasWide: []string{"ɓoso ɓwá yáɓe lá", "mbúsa kwédi a Yés"},
70 timezones: map[string]string{"ARST": "ARST", "OESZ": "OESZ", "LHDT": "LHDT", "AST": "AST", "WAT": "WAT", "CLT": "CLT", "MDT": "MDT", "UYST": "UYST", "PDT": "PDT", "MST": "MST", "ACDT": "ACDT", "AWDT": "AWDT", "AEDT": "AEDT", "SAST": "SAST", "HKT": "HKT", "EDT": "EDT", "GYT": "GYT", "AWST": "AWST", "HAST": "HAST", "IST": "IST", "WAST": "WAST", "EST": "EST", "WESZ": "WESZ", "SGT": "SGT", "HEPM": "HEPM", "MYT": "MYT", "UYT": "UYT", "HNNOMX": "HNNOMX", "WITA": "WITA", "∅∅∅": "∅∅∅", "CAT": "CAT", "CLST": "CLST", "ART": "ART", "HEOG": "HEOG", "MESZ": "MESZ", "NZST": "NZST", "JST": "JST", "AKST": "AKST", "ACWDT": "ACWDT", "VET": "VET", "AEST": "AEST", "COST": "COST", "HNPMX": "HNPMX", "CDT": "CDT", "TMT": "TMT", "HENOMX": "HENOMX", "HEEG": "HEEG", "GMT": "GMT", "HNCU": "HNCU", "JDT": "JDT", "HAT": "HAT", "AKDT": "AKDT", "WEZ": "WEZ", "TMST": "TMST", "LHST": "LHST", "ChST": "ChST", "HECU": "HECU", "WIT": "WIT", "OEZ": "OEZ", "HNOG": "HNOG", "EAT": "EAT", "PST": "PST", "BT": "BT", "ACWST": "ACWST", "MEZ": "MEZ", "NZDT": "NZDT", "HNEG": "HNEG", "HKST": "HKST", "GFT": "GFT", "ACST": "ACST", "CST": "CST", "CHADT": "CHADT", "BOT": "BOT", "HADT": "HADT", "HNT": "HNT", "ECT": "ECT", "HEPMX": "HEPMX", "WART": "WART", "ADT": "ADT", "WIB": "WIB", "SRT": "SRT", "WARST": "WARST", "COT": "COT", "CHAST": "CHAST", "HNPM": "HNPM"},
74 // Locale returns the current translators string locale
75 func (dua *dua) Locale() string {
79 // PluralsCardinal returns the list of cardinal plural rules associated with 'dua'
80 func (dua *dua) PluralsCardinal() []locales.PluralRule {
81 return dua.pluralsCardinal
84 // PluralsOrdinal returns the list of ordinal plural rules associated with 'dua'
85 func (dua *dua) PluralsOrdinal() []locales.PluralRule {
86 return dua.pluralsOrdinal
89 // PluralsRange returns the list of range plural rules associated with 'dua'
90 func (dua *dua) PluralsRange() []locales.PluralRule {
91 return dua.pluralsRange
94 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'dua'
95 func (dua *dua) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
96 return locales.PluralRuleUnknown
99 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'dua'
100 func (dua *dua) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
101 return locales.PluralRuleUnknown
104 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'dua'
105 func (dua *dua) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
106 return locales.PluralRuleUnknown
109 // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
110 func (dua *dua) MonthAbbreviated(month time.Month) string {
111 return dua.monthsAbbreviated[month]
114 // MonthsAbbreviated returns the locales abbreviated months
115 func (dua *dua) MonthsAbbreviated() []string {
116 return dua.monthsAbbreviated[1:]
119 // MonthNarrow returns the locales narrow month given the 'month' provided
120 func (dua *dua) MonthNarrow(month time.Month) string {
121 return dua.monthsNarrow[month]
124 // MonthsNarrow returns the locales narrow months
125 func (dua *dua) MonthsNarrow() []string {
126 return dua.monthsNarrow[1:]
129 // MonthWide returns the locales wide month given the 'month' provided
130 func (dua *dua) MonthWide(month time.Month) string {
131 return dua.monthsWide[month]
134 // MonthsWide returns the locales wide months
135 func (dua *dua) MonthsWide() []string {
136 return dua.monthsWide[1:]
139 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
140 func (dua *dua) WeekdayAbbreviated(weekday time.Weekday) string {
141 return dua.daysAbbreviated[weekday]
144 // WeekdaysAbbreviated returns the locales abbreviated weekdays
145 func (dua *dua) WeekdaysAbbreviated() []string {
146 return dua.daysAbbreviated
149 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
150 func (dua *dua) WeekdayNarrow(weekday time.Weekday) string {
151 return dua.daysNarrow[weekday]
154 // WeekdaysNarrow returns the locales narrow weekdays
155 func (dua *dua) WeekdaysNarrow() []string {
156 return dua.daysNarrow
159 // WeekdayShort returns the locales short weekday given the 'weekday' provided
160 func (dua *dua) WeekdayShort(weekday time.Weekday) string {
161 return dua.daysShort[weekday]
164 // WeekdaysShort returns the locales short weekdays
165 func (dua *dua) WeekdaysShort() []string {
169 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
170 func (dua *dua) WeekdayWide(weekday time.Weekday) string {
171 return dua.daysWide[weekday]
174 // WeekdaysWide returns the locales wide weekdays
175 func (dua *dua) WeekdaysWide() []string {
179 // Decimal returns the decimal point of number
180 func (dua *dua) Decimal() string {
184 // Group returns the group of number
185 func (dua *dua) Group() string {
189 // Group returns the minus sign of number
190 func (dua *dua) Minus() string {
194 // FmtNumber returns 'num' with digits/precision of 'v' for 'dua' and handles both Whole and Real numbers based on 'v'
195 func (dua *dua) FmtNumber(num float64, v uint64) string {
197 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
198 l := len(s) + 1 + 2*len(s[:len(s)-int(v)-1])/3
201 b := make([]byte, 0, l)
203 for i := len(s) - 1; i >= 0; i-- {
206 b = append(b, dua.decimal[0])
213 for j := len(dua.group) - 1; j >= 0; j-- {
214 b = append(b, dua.group[j])
226 b = append(b, dua.minus[0])
230 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
231 b[i], b[j] = b[j], b[i]
237 // FmtPercent returns 'num' with digits/precision of 'v' for 'dua' and handles both Whole and Real numbers based on 'v'
238 // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
239 func (dua *dua) FmtPercent(num float64, v uint64) string {
240 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
242 b := make([]byte, 0, l)
244 for i := len(s) - 1; i >= 0; i-- {
247 b = append(b, dua.decimal[0])
255 b = append(b, dua.minus[0])
259 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
260 b[i], b[j] = b[j], b[i]
263 b = append(b, dua.percentSuffix...)
265 b = append(b, dua.percent...)
270 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'dua'
271 func (dua *dua) FmtCurrency(num float64, v uint64, currency currency.Type) string {
273 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
274 symbol := dua.currencies[currency]
275 l := len(s) + len(symbol) + 3 + 2*len(s[:len(s)-int(v)-1])/3
278 b := make([]byte, 0, l)
280 for i := len(s) - 1; i >= 0; i-- {
283 b = append(b, dua.decimal[0])
290 for j := len(dua.group) - 1; j >= 0; j-- {
291 b = append(b, dua.group[j])
303 b = append(b, dua.minus[0])
307 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
308 b[i], b[j] = b[j], b[i]
314 b = append(b, dua.decimal...)
317 for i := 0; i < 2-int(v); i++ {
322 b = append(b, dua.currencyPositiveSuffix...)
324 b = append(b, symbol...)
329 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'dua'
330 // in accounting notation.
331 func (dua *dua) FmtAccounting(num float64, v uint64, currency currency.Type) string {
333 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
334 symbol := dua.currencies[currency]
335 l := len(s) + len(symbol) + 3 + 2*len(s[:len(s)-int(v)-1])/3
338 b := make([]byte, 0, l)
340 for i := len(s) - 1; i >= 0; i-- {
343 b = append(b, dua.decimal[0])
350 for j := len(dua.group) - 1; j >= 0; j-- {
351 b = append(b, dua.group[j])
364 b = append(b, dua.minus[0])
369 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
370 b[i], b[j] = b[j], b[i]
376 b = append(b, dua.decimal...)
379 for i := 0; i < 2-int(v); i++ {
385 b = append(b, dua.currencyNegativeSuffix...)
386 b = append(b, symbol...)
389 b = append(b, dua.currencyPositiveSuffix...)
390 b = append(b, symbol...)
396 // FmtDateShort returns the short date representation of 't' for 'dua'
397 func (dua *dua) FmtDateShort(t time.Time) string {
399 b := make([]byte, 0, 32)
401 b = strconv.AppendInt(b, int64(t.Day()), 10)
402 b = append(b, []byte{0x2f}...)
403 b = strconv.AppendInt(b, int64(t.Month()), 10)
404 b = append(b, []byte{0x2f}...)
407 b = strconv.AppendInt(b, int64(t.Year()), 10)
409 b = strconv.AppendInt(b, int64(-t.Year()), 10)
415 // FmtDateMedium returns the medium date representation of 't' for 'dua'
416 func (dua *dua) FmtDateMedium(t time.Time) string {
418 b := make([]byte, 0, 32)
420 b = strconv.AppendInt(b, int64(t.Day()), 10)
421 b = append(b, []byte{0x20}...)
422 b = append(b, dua.monthsAbbreviated[t.Month()]...)
423 b = append(b, []byte{0x20}...)
426 b = strconv.AppendInt(b, int64(t.Year()), 10)
428 b = strconv.AppendInt(b, int64(-t.Year()), 10)
434 // FmtDateLong returns the long date representation of 't' for 'dua'
435 func (dua *dua) FmtDateLong(t time.Time) string {
437 b := make([]byte, 0, 32)
439 b = strconv.AppendInt(b, int64(t.Day()), 10)
440 b = append(b, []byte{0x20}...)
441 b = append(b, dua.monthsWide[t.Month()]...)
442 b = append(b, []byte{0x20}...)
445 b = strconv.AppendInt(b, int64(t.Year()), 10)
447 b = strconv.AppendInt(b, int64(-t.Year()), 10)
453 // FmtDateFull returns the full date representation of 't' for 'dua'
454 func (dua *dua) FmtDateFull(t time.Time) string {
456 b := make([]byte, 0, 32)
458 b = append(b, dua.daysWide[t.Weekday()]...)
459 b = append(b, []byte{0x20}...)
460 b = strconv.AppendInt(b, int64(t.Day()), 10)
461 b = append(b, []byte{0x20}...)
462 b = append(b, dua.monthsWide[t.Month()]...)
463 b = append(b, []byte{0x20}...)
466 b = strconv.AppendInt(b, int64(t.Year()), 10)
468 b = strconv.AppendInt(b, int64(-t.Year()), 10)
474 // FmtTimeShort returns the short time representation of 't' for 'dua'
475 func (dua *dua) FmtTimeShort(t time.Time) string {
477 b := make([]byte, 0, 32)
483 b = strconv.AppendInt(b, int64(t.Hour()), 10)
484 b = append(b, dua.timeSeparator...)
490 b = strconv.AppendInt(b, int64(t.Minute()), 10)
495 // FmtTimeMedium returns the medium time representation of 't' for 'dua'
496 func (dua *dua) FmtTimeMedium(t time.Time) string {
498 b := make([]byte, 0, 32)
504 b = strconv.AppendInt(b, int64(t.Hour()), 10)
505 b = append(b, dua.timeSeparator...)
511 b = strconv.AppendInt(b, int64(t.Minute()), 10)
512 b = append(b, dua.timeSeparator...)
518 b = strconv.AppendInt(b, int64(t.Second()), 10)
523 // FmtTimeLong returns the long time representation of 't' for 'dua'
524 func (dua *dua) FmtTimeLong(t time.Time) string {
526 b := make([]byte, 0, 32)
532 b = strconv.AppendInt(b, int64(t.Hour()), 10)
533 b = append(b, dua.timeSeparator...)
539 b = strconv.AppendInt(b, int64(t.Minute()), 10)
540 b = append(b, dua.timeSeparator...)
546 b = strconv.AppendInt(b, int64(t.Second()), 10)
547 b = append(b, []byte{0x20}...)
555 // FmtTimeFull returns the full time representation of 't' for 'dua'
556 func (dua *dua) FmtTimeFull(t time.Time) string {
558 b := make([]byte, 0, 32)
564 b = strconv.AppendInt(b, int64(t.Hour()), 10)
565 b = append(b, dua.timeSeparator...)
571 b = strconv.AppendInt(b, int64(t.Minute()), 10)
572 b = append(b, dua.timeSeparator...)
578 b = strconv.AppendInt(b, int64(t.Second()), 10)
579 b = append(b, []byte{0x20}...)
583 if btz, ok := dua.timezones[tz]; ok {
584 b = append(b, btz...)