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 'root' locale
43 func New() locales.Translator {
46 pluralsCardinal: []locales.PluralRule{6},
47 pluralsOrdinal: []locales.PluralRule{6},
56 currencies: []string{"ADP", "AED", "AFA", "AFN", "ALK", "ALL", "AMD", "ANG", "Kz", "AOK", "AON", "AOR", "ARA", "ARL", "ARM", "ARP", "$", "ATS", "A$", "AWG", "AZM", "AZN", "BAD", "KM", "BAN", "$", "৳", "BEC", "BEF", "BEL", "BGL", "BGM", "BGN", "BGO", "BHD", "BIF", "$", "$", "Bs", "BOL", "BOP", "BOV", "BRB", "BRC", "BRE", "R$", "BRN", "BRR", "BRZ", "$", "BTN", "BUK", "P", "BYB", "р.", "BYR", "$", "CA$", "CDF", "CHE", "CHF", "CHW", "CLE", "CLF", "$", "CNX", "CN¥", "$", "COU", "₡", "CSD", "CSK", "$", "$", "CVE", "CYP", "Kč", "DDM", "DEM", "DJF", "kr", "$", "DZD", "ECS", "ECV", "EEK", "E£", "ERN", "ESA", "ESB", "₧", "ETB", "€", "FIM", "$", "£", "FRF", "£", "GEK", "₾", "GHC", "GHS", "£", "GMD", "FG", "GNS", "GQE", "GRD", "Q", "GWE", "GWP", "$", "HK$", "L", "HRD", "kn", "HTG", "Ft", "Rp", "IEP", "ILP", "ILR", "₪", "₹", "IQD", "IRR", "ISJ", "kr", "ITL", "$", "JOD", "JP¥", "KES", "KGS", "៛", "CF", "₩", "KRH", "KRO", "₩", "KWD", "$", "₸", "₭", "L£", "Rs", "$", "LSL", "Lt", "LTT", "LUC", "LUF", "LUL", "Ls", "LVR", "LYD", "MAD", "MAF", "MCF", "MDC", "MDL", "Ar", "MGF", "MKD", "MKN", "MLF", "K", "₮", "MOP", "MRO", "MTL", "MTP", "Rs", "MVP", "MVR", "MWK", "MX$", "MXP", "MXV", "RM", "MZE", "MZM", "MZN", "$", "₦", "NIC", "C$", "NLG", "kr", "Rs", "NZ$", "OMR", "PAB", "PEI", "PEN", "PES", "PGK", "₱", "Rs", "zł", "PLZ", "PTE", "₲", "QAR", "RHD", "ROL", "lei", "RSD", "₽", "р.", "RF", "SAR", "$", "SCR", "SDD", "SDG", "SDP", "kr", "$", "£", "SIT", "SKK", "SLL", "SOS", "$", "SRG", "£", "Db", "SUR", "SVC", "£", "SZL", "฿", "TJR", "TJS", "TMM", "TMT", "TND", "T$", "TPE", "TRL", "₺", "$", "NT$", "TZS", "₴", "UAK", "UGS", "UGX", "US$", "USN", "USS", "UYI", "UYP", "$", "UZS", "VEB", "Bs", "₫", "VNN", "VUV", "WST", "FCFA", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "EC$", "XDR", "XEU", "XFO", "XFU", "CFA", "XPD", "CFPF", "XPT", "XRE", "XSU", "XTS", "XUA", "XXX", "YDD", "YER", "YUD", "YUM", "YUN", "YUR", "ZAL", "R", "ZMK", "ZK", "ZRN", "ZRZ", "ZWD", "ZWL", "ZWR"},
57 monthsNarrow: []string{"", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"},
58 monthsWide: []string{"", "M01", "M02", "M03", "M04", "M05", "M06", "M07", "M08", "M09", "M10", "M11", "M12"},
59 daysNarrow: []string{"S", "M", "T", "W", "T", "F", "S"},
60 daysWide: []string{"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"},
61 periodsAbbreviated: []string{"AM", "PM"},
62 periodsNarrow: []string{"", ""},
63 periodsWide: []string{"", ""},
64 erasAbbreviated: []string{"BCE", "CE"},
65 erasNarrow: []string{"", ""},
66 erasWide: []string{"", ""},
67 timezones: map[string]string{"NZST": "NZST", "WITA": "WITA", "OEZ": "OEZ", "HKT": "HKT", "GMT": "GMT", "HNPMX": "HNPMX", "CAT": "CAT", "∅∅∅": "∅∅∅", "VET": "VET", "HNNOMX": "HNNOMX", "JDT": "JDT", "OESZ": "OESZ", "COT": "COT", "HKST": "HKST", "ECT": "ECT", "HEPM": "HEPM", "BOT": "BOT", "SRT": "SRT", "TMT": "TMT", "ART": "ART", "GYT": "GYT", "AKDT": "AKDT", "WEZ": "WEZ", "PDT": "PDT", "MYT": "MYT", "EAT": "EAT", "WESZ": "WESZ", "HNPM": "HNPM", "CHADT": "CHADT", "HNCU": "HNCU", "HECU": "HECU", "HAST": "HAST", "WIB": "WIB", "HEPMX": "HEPMX", "ACDT": "ACDT", "BT": "BT", "CDT": "CDT", "MST": "MST", "MDT": "MDT", "UYT": "UYT", "AST": "AST", "HEEG": "HEEG", "UYST": "UYST", "TMST": "TMST", "AWST": "AWST", "AWDT": "AWDT", "HADT": "HADT", "LHDT": "LHDT", "EST": "EST", "JST": "JST", "GFT": "GFT", "HNT": "HNT", "ACWST": "ACWST", "ACWDT": "ACWDT", "MESZ": "MESZ", "SAST": "SAST", "WAT": "WAT", "CHAST": "CHAST", "WARST": "WARST", "AEST": "AEST", "HNEG": "HNEG", "HAT": "HAT", "WIT": "WIT", "MEZ": "MEZ", "NZDT": "NZDT", "WART": "WART", "HENOMX": "HENOMX", "HNOG": "HNOG", "WAST": "WAST", "CLT": "CLT", "CLST": "CLST", "AKST": "AKST", "ADT": "ADT", "ARST": "ARST", "COST": "COST", "EDT": "EDT", "ACST": "ACST", "CST": "CST", "LHST": "LHST", "HEOG": "HEOG", "PST": "PST", "IST": "IST", "AEDT": "AEDT", "SGT": "SGT", "ChST": "ChST"},
71 // Locale returns the current translators string locale
72 func (root *root) Locale() string {
76 // PluralsCardinal returns the list of cardinal plural rules associated with 'root'
77 func (root *root) PluralsCardinal() []locales.PluralRule {
78 return root.pluralsCardinal
81 // PluralsOrdinal returns the list of ordinal plural rules associated with 'root'
82 func (root *root) PluralsOrdinal() []locales.PluralRule {
83 return root.pluralsOrdinal
86 // PluralsRange returns the list of range plural rules associated with 'root'
87 func (root *root) PluralsRange() []locales.PluralRule {
88 return root.pluralsRange
91 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'root'
92 func (root *root) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
93 return locales.PluralRuleOther
96 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'root'
97 func (root *root) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
98 return locales.PluralRuleOther
101 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'root'
102 func (root *root) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
103 return locales.PluralRuleUnknown
106 // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
107 func (root *root) MonthAbbreviated(month time.Month) string {
108 return root.monthsAbbreviated[month]
111 // MonthsAbbreviated returns the locales abbreviated months
112 func (root *root) MonthsAbbreviated() []string {
116 // MonthNarrow returns the locales narrow month given the 'month' provided
117 func (root *root) MonthNarrow(month time.Month) string {
118 return root.monthsNarrow[month]
121 // MonthsNarrow returns the locales narrow months
122 func (root *root) MonthsNarrow() []string {
123 return root.monthsNarrow[1:]
126 // MonthWide returns the locales wide month given the 'month' provided
127 func (root *root) MonthWide(month time.Month) string {
128 return root.monthsWide[month]
131 // MonthsWide returns the locales wide months
132 func (root *root) MonthsWide() []string {
133 return root.monthsWide[1:]
136 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
137 func (root *root) WeekdayAbbreviated(weekday time.Weekday) string {
138 return root.daysAbbreviated[weekday]
141 // WeekdaysAbbreviated returns the locales abbreviated weekdays
142 func (root *root) WeekdaysAbbreviated() []string {
143 return root.daysAbbreviated
146 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
147 func (root *root) WeekdayNarrow(weekday time.Weekday) string {
148 return root.daysNarrow[weekday]
151 // WeekdaysNarrow returns the locales narrow weekdays
152 func (root *root) WeekdaysNarrow() []string {
153 return root.daysNarrow
156 // WeekdayShort returns the locales short weekday given the 'weekday' provided
157 func (root *root) WeekdayShort(weekday time.Weekday) string {
158 return root.daysShort[weekday]
161 // WeekdaysShort returns the locales short weekdays
162 func (root *root) WeekdaysShort() []string {
163 return root.daysShort
166 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
167 func (root *root) WeekdayWide(weekday time.Weekday) string {
168 return root.daysWide[weekday]
171 // WeekdaysWide returns the locales wide weekdays
172 func (root *root) WeekdaysWide() []string {
176 // Decimal returns the decimal point of number
177 func (root *root) Decimal() string {
181 // Group returns the group of number
182 func (root *root) Group() string {
186 // Group returns the minus sign of number
187 func (root *root) Minus() string {
191 // FmtNumber returns 'num' with digits/precision of 'v' for 'root' and handles both Whole and Real numbers based on 'v'
192 func (root *root) FmtNumber(num float64, v uint64) string {
194 return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
197 // FmtPercent returns 'num' with digits/precision of 'v' for 'root' and handles both Whole and Real numbers based on 'v'
198 // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
199 func (root *root) FmtPercent(num float64, v uint64) string {
200 return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
203 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'root'
204 func (root *root) FmtCurrency(num float64, v uint64, currency currency.Type) string {
206 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
207 symbol := root.currencies[currency]
208 return string(append(append([]byte{}, symbol...), s...))
211 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'root'
212 // in accounting notation.
213 func (root *root) FmtAccounting(num float64, v uint64, currency currency.Type) string {
215 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
216 symbol := root.currencies[currency]
217 return string(append(append([]byte{}, symbol...), s...))
220 // FmtDateShort returns the short date representation of 't' for 'root'
221 func (root *root) FmtDateShort(t time.Time) string {
223 b := make([]byte, 0, 32)
226 b = strconv.AppendInt(b, int64(t.Year()), 10)
228 b = strconv.AppendInt(b, int64(-t.Year()), 10)
231 b = append(b, []byte{0x2d}...)
237 b = strconv.AppendInt(b, int64(t.Month()), 10)
239 b = append(b, []byte{0x2d}...)
245 b = strconv.AppendInt(b, int64(t.Day()), 10)
250 // FmtDateMedium returns the medium date representation of 't' for 'root'
251 func (root *root) FmtDateMedium(t time.Time) string {
253 b := make([]byte, 0, 32)
256 b = strconv.AppendInt(b, int64(t.Year()), 10)
258 b = strconv.AppendInt(b, int64(-t.Year()), 10)
261 b = append(b, []byte{0x20}...)
262 b = append(b, root.monthsAbbreviated[t.Month()]...)
263 b = append(b, []byte{0x20}...)
264 b = strconv.AppendInt(b, int64(t.Day()), 10)
269 // FmtDateLong returns the long date representation of 't' for 'root'
270 func (root *root) FmtDateLong(t time.Time) string {
272 b := make([]byte, 0, 32)
275 b = strconv.AppendInt(b, int64(t.Year()), 10)
277 b = strconv.AppendInt(b, int64(-t.Year()), 10)
280 b = append(b, []byte{0x20}...)
281 b = append(b, root.monthsWide[t.Month()]...)
282 b = append(b, []byte{0x20}...)
283 b = strconv.AppendInt(b, int64(t.Day()), 10)
288 // FmtDateFull returns the full date representation of 't' for 'root'
289 func (root *root) FmtDateFull(t time.Time) string {
291 b := make([]byte, 0, 32)
294 b = strconv.AppendInt(b, int64(t.Year()), 10)
296 b = strconv.AppendInt(b, int64(-t.Year()), 10)
299 b = append(b, []byte{0x20}...)
300 b = append(b, root.monthsWide[t.Month()]...)
301 b = append(b, []byte{0x20}...)
302 b = strconv.AppendInt(b, int64(t.Day()), 10)
303 b = append(b, []byte{0x2c, 0x20}...)
304 b = append(b, root.daysWide[t.Weekday()]...)
309 // FmtTimeShort returns the short time representation of 't' for 'root'
310 func (root *root) FmtTimeShort(t time.Time) string {
312 b := make([]byte, 0, 32)
318 b = strconv.AppendInt(b, int64(t.Hour()), 10)
319 b = append(b, root.timeSeparator...)
325 b = strconv.AppendInt(b, int64(t.Minute()), 10)
330 // FmtTimeMedium returns the medium time representation of 't' for 'root'
331 func (root *root) FmtTimeMedium(t time.Time) string {
333 b := make([]byte, 0, 32)
339 b = strconv.AppendInt(b, int64(t.Hour()), 10)
340 b = append(b, root.timeSeparator...)
346 b = strconv.AppendInt(b, int64(t.Minute()), 10)
347 b = append(b, root.timeSeparator...)
353 b = strconv.AppendInt(b, int64(t.Second()), 10)
358 // FmtTimeLong returns the long time representation of 't' for 'root'
359 func (root *root) FmtTimeLong(t time.Time) string {
361 b := make([]byte, 0, 32)
367 b = strconv.AppendInt(b, int64(t.Hour()), 10)
368 b = append(b, root.timeSeparator...)
374 b = strconv.AppendInt(b, int64(t.Minute()), 10)
375 b = append(b, root.timeSeparator...)
381 b = strconv.AppendInt(b, int64(t.Second()), 10)
382 b = append(b, []byte{0x20}...)
390 // FmtTimeFull returns the full time representation of 't' for 'root'
391 func (root *root) FmtTimeFull(t time.Time) string {
393 b := make([]byte, 0, 32)
399 b = strconv.AppendInt(b, int64(t.Hour()), 10)
400 b = append(b, root.timeSeparator...)
406 b = strconv.AppendInt(b, int64(t.Minute()), 10)
407 b = append(b, root.timeSeparator...)
413 b = strconv.AppendInt(b, int64(t.Second()), 10)
414 b = append(b, []byte{0x20}...)
418 if btz, ok := root.timezones[tz]; ok {
419 b = append(b, btz...)