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 currencyNegativePrefix 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 'nus' 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", "GB£", "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", "£", "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 currencyNegativePrefix: "(",
56 currencyNegativeSuffix: ")",
57 monthsAbbreviated: []string{"", "Tiop", "Pɛt", "Duɔ̱ɔ̱", "Guak", "Duä", "Kor", "Pay", "Thoo", "Tɛɛ", "Laa", "Kur", "Tid"},
58 monthsNarrow: []string{"", "T", "P", "D", "G", "D", "K", "P", "T", "T", "L", "K", "T"},
59 monthsWide: []string{"", "Tiop thar pɛt", "Pɛt", "Duɔ̱ɔ̱ŋ", "Guak", "Duät", "Kornyoot", "Pay yie̱tni", "Tho̱o̱r", "Tɛɛr", "Laath", "Kur", "Tio̱p in di̱i̱t"},
60 daysAbbreviated: []string{"Cäŋ", "Jiec", "Rɛw", "Diɔ̱k", "Ŋuaan", "Dhieec", "Bäkɛl"},
61 daysNarrow: []string{"C", "J", "R", "D", "Ŋ", "D", "B"},
62 daysWide: []string{"Cäŋ kuɔth", "Jiec la̱t", "Rɛw lätni", "Diɔ̱k lätni", "Ŋuaan lätni", "Dhieec lätni", "Bäkɛl lätni"},
63 periodsAbbreviated: []string{"RW", "TŊ"},
64 periodsWide: []string{"RW", "TŊ"},
65 erasAbbreviated: []string{"AY", "ƐY"},
66 erasNarrow: []string{"", ""},
67 erasWide: []string{"A ka̱n Yecu ni dap", "Ɛ ca Yecu dap"},
68 timezones: map[string]string{"HENOMX": "HENOMX", "UYT": "UYT", "HADT": "HADT", "MESZ": "MESZ", "OEZ": "OEZ", "OESZ": "OESZ", "AEDT": "AEDT", "COT": "COT", "ChST": "ChST", "HNPMX": "HNPMX", "AWDT": "AWDT", "IST": "IST", "CLT": "CLT", "GMT": "GMT", "HEPMX": "HEPMX", "HNPM": "HNPM", "ARST": "ARST", "HAT": "HAT", "ACST": "ACST", "HNCU": "HNCU", "HECU": "HECU", "ACWDT": "ACWDT", "TMST": "TMST", "HEEG": "HEEG", "WESZ": "WESZ", "TMT": "TMT", "LHDT": "LHDT", "ART": "ART", "WAT": "WAT", "HNEG": "HNEG", "COST": "COST", "AKDT": "AKDT", "CHADT": "CHADT", "MST": "MST", "JST": "JST", "WAST": "WAST", "WIB": "WIB", "CHAST": "CHAST", "AWST": "AWST", "WITA": "WITA", "SAST": "SAST", "GYT": "GYT", "AKST": "AKST", "CDT": "CDT", "LHST": "LHST", "VET": "VET", "GFT": "GFT", "PDT": "PDT", "MDT": "MDT", "WART": "WART", "HKT": "HKT", "EST": "EST", "ECT": "ECT", "CLST": "CLST", "PST": "PST", "BOT": "BOT", "EDT": "EDT", "HEPM": "HEPM", "CST": "CST", "MYT": "MYT", "MEZ": "MEZ", "UYST": "UYST", "WARST": "WARST", "∅∅∅": "∅∅∅", "ADT": "ADT", "AEST": "AEST", "SGT": "SGT", "SRT": "SRT", "ACWST": "ACWST", "NZDT": "NZDT", "EAT": "EAT", "BT": "BT", "HAST": "HAST", "HNNOMX": "HNNOMX", "JDT": "JDT", "AST": "AST", "HEOG": "HEOG", "HKST": "HKST", "CAT": "CAT", "WIT": "WIT", "HNOG": "HNOG", "HNT": "HNT", "ACDT": "ACDT", "WEZ": "WEZ", "NZST": "NZST"},
72 // Locale returns the current translators string locale
73 func (nus *nus) Locale() string {
77 // PluralsCardinal returns the list of cardinal plural rules associated with 'nus'
78 func (nus *nus) PluralsCardinal() []locales.PluralRule {
79 return nus.pluralsCardinal
82 // PluralsOrdinal returns the list of ordinal plural rules associated with 'nus'
83 func (nus *nus) PluralsOrdinal() []locales.PluralRule {
84 return nus.pluralsOrdinal
87 // PluralsRange returns the list of range plural rules associated with 'nus'
88 func (nus *nus) PluralsRange() []locales.PluralRule {
89 return nus.pluralsRange
92 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'nus'
93 func (nus *nus) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
94 return locales.PluralRuleUnknown
97 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'nus'
98 func (nus *nus) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
99 return locales.PluralRuleUnknown
102 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'nus'
103 func (nus *nus) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
104 return locales.PluralRuleUnknown
107 // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
108 func (nus *nus) MonthAbbreviated(month time.Month) string {
109 return nus.monthsAbbreviated[month]
112 // MonthsAbbreviated returns the locales abbreviated months
113 func (nus *nus) MonthsAbbreviated() []string {
114 return nus.monthsAbbreviated[1:]
117 // MonthNarrow returns the locales narrow month given the 'month' provided
118 func (nus *nus) MonthNarrow(month time.Month) string {
119 return nus.monthsNarrow[month]
122 // MonthsNarrow returns the locales narrow months
123 func (nus *nus) MonthsNarrow() []string {
124 return nus.monthsNarrow[1:]
127 // MonthWide returns the locales wide month given the 'month' provided
128 func (nus *nus) MonthWide(month time.Month) string {
129 return nus.monthsWide[month]
132 // MonthsWide returns the locales wide months
133 func (nus *nus) MonthsWide() []string {
134 return nus.monthsWide[1:]
137 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
138 func (nus *nus) WeekdayAbbreviated(weekday time.Weekday) string {
139 return nus.daysAbbreviated[weekday]
142 // WeekdaysAbbreviated returns the locales abbreviated weekdays
143 func (nus *nus) WeekdaysAbbreviated() []string {
144 return nus.daysAbbreviated
147 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
148 func (nus *nus) WeekdayNarrow(weekday time.Weekday) string {
149 return nus.daysNarrow[weekday]
152 // WeekdaysNarrow returns the locales narrow weekdays
153 func (nus *nus) WeekdaysNarrow() []string {
154 return nus.daysNarrow
157 // WeekdayShort returns the locales short weekday given the 'weekday' provided
158 func (nus *nus) WeekdayShort(weekday time.Weekday) string {
159 return nus.daysShort[weekday]
162 // WeekdaysShort returns the locales short weekdays
163 func (nus *nus) WeekdaysShort() []string {
167 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
168 func (nus *nus) WeekdayWide(weekday time.Weekday) string {
169 return nus.daysWide[weekday]
172 // WeekdaysWide returns the locales wide weekdays
173 func (nus *nus) WeekdaysWide() []string {
177 // Decimal returns the decimal point of number
178 func (nus *nus) Decimal() string {
182 // Group returns the group of number
183 func (nus *nus) Group() string {
187 // Group returns the minus sign of number
188 func (nus *nus) Minus() string {
192 // FmtNumber returns 'num' with digits/precision of 'v' for 'nus' and handles both Whole and Real numbers based on 'v'
193 func (nus *nus) FmtNumber(num float64, v uint64) string {
195 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
196 l := len(s) + 1 + 1*len(s[:len(s)-int(v)-1])/3
199 b := make([]byte, 0, l)
201 for i := len(s) - 1; i >= 0; i-- {
204 b = append(b, nus.decimal[0])
211 b = append(b, nus.group[0])
222 b = append(b, nus.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 'nus' 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 (nus *nus) 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, nus.decimal[0])
251 b = append(b, nus.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, nus.percent...)
264 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'nus'
265 func (nus *nus) FmtCurrency(num float64, v uint64, currency currency.Type) string {
267 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
268 symbol := nus.currencies[currency]
269 l := len(s) + len(symbol) + 1 + 1*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, nus.decimal[0])
284 b = append(b, nus.group[0])
294 for j := len(symbol) - 1; j >= 0; j-- {
295 b = append(b, symbol[j])
299 b = append(b, nus.minus[0])
303 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
304 b[i], b[j] = b[j], b[i]
310 b = append(b, nus.decimal...)
313 for i := 0; i < 2-int(v); i++ {
321 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'nus'
322 // in accounting notation.
323 func (nus *nus) FmtAccounting(num float64, v uint64, currency currency.Type) string {
325 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
326 symbol := nus.currencies[currency]
327 l := len(s) + len(symbol) + 3 + 1*len(s[:len(s)-int(v)-1])/3
330 b := make([]byte, 0, l)
332 for i := len(s) - 1; i >= 0; i-- {
335 b = append(b, nus.decimal[0])
342 b = append(b, nus.group[0])
354 for j := len(symbol) - 1; j >= 0; j-- {
355 b = append(b, symbol[j])
358 b = append(b, nus.currencyNegativePrefix[0])
362 for j := len(symbol) - 1; j >= 0; j-- {
363 b = append(b, symbol[j])
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, nus.decimal...)
379 for i := 0; i < 2-int(v); i++ {
385 b = append(b, nus.currencyNegativeSuffix...)
391 // FmtDateShort returns the short date representation of 't' for 'nus'
392 func (nus *nus) FmtDateShort(t time.Time) string {
394 b := make([]byte, 0, 32)
396 b = strconv.AppendInt(b, int64(t.Day()), 10)
397 b = append(b, []byte{0x2f}...)
403 b = strconv.AppendInt(b, int64(t.Month()), 10)
405 b = append(b, []byte{0x2f}...)
408 b = strconv.AppendInt(b, int64(t.Year()), 10)
410 b = strconv.AppendInt(b, int64(-t.Year()), 10)
416 // FmtDateMedium returns the medium date representation of 't' for 'nus'
417 func (nus *nus) FmtDateMedium(t time.Time) string {
419 b := make([]byte, 0, 32)
421 b = strconv.AppendInt(b, int64(t.Day()), 10)
422 b = append(b, []byte{0x20}...)
423 b = append(b, nus.monthsAbbreviated[t.Month()]...)
424 b = append(b, []byte{0x20}...)
427 b = strconv.AppendInt(b, int64(t.Year()), 10)
429 b = strconv.AppendInt(b, int64(-t.Year()), 10)
435 // FmtDateLong returns the long date representation of 't' for 'nus'
436 func (nus *nus) FmtDateLong(t time.Time) string {
438 b := make([]byte, 0, 32)
440 b = strconv.AppendInt(b, int64(t.Day()), 10)
441 b = append(b, []byte{0x20}...)
442 b = append(b, nus.monthsWide[t.Month()]...)
443 b = append(b, []byte{0x20}...)
446 b = strconv.AppendInt(b, int64(t.Year()), 10)
448 b = strconv.AppendInt(b, int64(-t.Year()), 10)
454 // FmtDateFull returns the full date representation of 't' for 'nus'
455 func (nus *nus) FmtDateFull(t time.Time) string {
457 b := make([]byte, 0, 32)
459 b = append(b, nus.daysWide[t.Weekday()]...)
460 b = append(b, []byte{0x20}...)
461 b = strconv.AppendInt(b, int64(t.Day()), 10)
462 b = append(b, []byte{0x20}...)
463 b = append(b, nus.monthsWide[t.Month()]...)
464 b = append(b, []byte{0x20}...)
467 b = strconv.AppendInt(b, int64(t.Year()), 10)
469 b = strconv.AppendInt(b, int64(-t.Year()), 10)
475 // FmtTimeShort returns the short time representation of 't' for 'nus'
476 func (nus *nus) FmtTimeShort(t time.Time) string {
478 b := make([]byte, 0, 32)
486 b = strconv.AppendInt(b, int64(h), 10)
487 b = append(b, nus.timeSeparator...)
493 b = strconv.AppendInt(b, int64(t.Minute()), 10)
494 b = append(b, []byte{0x20}...)
497 b = append(b, nus.periodsAbbreviated[0]...)
499 b = append(b, nus.periodsAbbreviated[1]...)
505 // FmtTimeMedium returns the medium time representation of 't' for 'nus'
506 func (nus *nus) FmtTimeMedium(t time.Time) string {
508 b := make([]byte, 0, 32)
516 b = strconv.AppendInt(b, int64(h), 10)
517 b = append(b, nus.timeSeparator...)
523 b = strconv.AppendInt(b, int64(t.Minute()), 10)
524 b = append(b, nus.timeSeparator...)
530 b = strconv.AppendInt(b, int64(t.Second()), 10)
531 b = append(b, []byte{0x20}...)
534 b = append(b, nus.periodsAbbreviated[0]...)
536 b = append(b, nus.periodsAbbreviated[1]...)
542 // FmtTimeLong returns the long time representation of 't' for 'nus'
543 func (nus *nus) FmtTimeLong(t time.Time) string {
545 b := make([]byte, 0, 32)
550 b = append(b, []byte{0x20}...)
558 b = strconv.AppendInt(b, int64(h), 10)
559 b = append(b, nus.timeSeparator...)
565 b = strconv.AppendInt(b, int64(t.Minute()), 10)
566 b = append(b, nus.timeSeparator...)
572 b = strconv.AppendInt(b, int64(t.Second()), 10)
573 b = append(b, []byte{0x20}...)
576 b = append(b, nus.periodsAbbreviated[0]...)
578 b = append(b, nus.periodsAbbreviated[1]...)
584 // FmtTimeFull returns the full time representation of 't' for 'nus'
585 func (nus *nus) FmtTimeFull(t time.Time) string {
587 b := make([]byte, 0, 32)
591 if btz, ok := nus.timezones[tz]; ok {
592 b = append(b, btz...)
597 b = append(b, []byte{0x20}...)
605 b = strconv.AppendInt(b, int64(h), 10)
606 b = append(b, nus.timeSeparator...)
612 b = strconv.AppendInt(b, int64(t.Minute()), 10)
613 b = append(b, nus.timeSeparator...)
619 b = strconv.AppendInt(b, int64(t.Second()), 10)
620 b = append(b, []byte{0x20}...)
623 b = append(b, nus.periodsAbbreviated[0]...)
625 b = append(b, nus.periodsAbbreviated[1]...)