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 currencyPositivePrefix string
26 currencyPositiveSuffix string
27 currencyNegativePrefix string
28 currencyNegativeSuffix string
29 monthsAbbreviated []string
32 daysAbbreviated []string
36 periodsAbbreviated []string
37 periodsNarrow []string
40 erasAbbreviated []string
43 timezones map[string]string
46 // New returns a new instance of translator for the 'lkt' locale
47 func New() locales.Translator {
50 pluralsCardinal: []locales.PluralRule{6},
60 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", "$", "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"},
61 currencyPositivePrefix: " ",
62 currencyPositiveSuffix: "K",
63 currencyNegativePrefix: " ",
64 currencyNegativeSuffix: "K",
65 monthsWide: []string{"", "Wiótheȟika Wí", "Thiyóȟeyuŋka Wí", "Ištáwičhayazaŋ Wí", "Pȟežítȟo Wí", "Čhaŋwápetȟo Wí", "Wípazukȟa-wašté Wí", "Čhaŋpȟásapa Wí", "Wasútȟuŋ Wí", "Čhaŋwápeǧi Wí", "Čhaŋwápe-kasná Wí", "Waníyetu Wí", "Tȟahékapšuŋ Wí"},
66 daysNarrow: []string{"A", "W", "N", "Y", "T", "Z", "O"},
67 daysWide: []string{"Aŋpétuwakȟaŋ", "Aŋpétuwaŋži", "Aŋpétunuŋpa", "Aŋpétuyamni", "Aŋpétutopa", "Aŋpétuzaptaŋ", "Owáŋgyužažapi"},
68 timezones: map[string]string{"WARST": "WARST", "ADT": "ADT", "HEEG": "HEEG", "EDT": "EDT", "ChST": "ChST", "HNPMX": "HNPMX", "HEPMX": "HEPMX", "MDT": "MDT", "CST": "CST", "MEZ": "MEZ", "HNPM": "HNPM", "CHADT": "CHADT", "ACWDT": "ACWDT", "TMT": "TMT", "LHDT": "LHDT", "JDT": "JDT", "AEDT": "AEDT", "EST": "EST", "AKDT": "AKDT", "HECU": "HECU", "BT": "BT", "JST": "JST", "EAT": "EAT", "COST": "COST", "MYT": "MYT", "UYT": "UYT", "ARST": "ARST", "LHST": "LHST", "ART": "ART", "SRT": "SRT", "TMST": "TMST", "OEZ": "OEZ", "HKT": "HKT", "GYT": "GYT", "AKST": "AKST", "ACST": "ACST", "ACDT": "ACDT", "HENOMX": "HENOMX", "WIB": "WIB", "HNEG": "HNEG", "GFT": "GFT", "HNCU": "HNCU", "NZDT": "NZDT", "HNOG": "HNOG", "IST": "IST", "WEZ": "WEZ", "GMT": "GMT", "ACWST": "ACWST", "HAST": "HAST", "HADT": "HADT", "MST": "MST", "ECT": "ECT", "AST": "AST", "AEST": "AEST", "HAT": "HAT", "SGT": "SGT", "HEPM": "HEPM", "BOT": "BOT", "WIT": "WIT", "WITA": "WITA", "COT": "COT", "WESZ": "WESZ", "PDT": "PDT", "AWST": "AWST", "NZST": "NZST", "HNNOMX": "HNNOMX", "OESZ": "OESZ", "SAST": "SAST", "HNT": "HNT", "CAT": "CAT", "PST": "PST", "AWDT": "AWDT", "VET": "VET", "CLT": "CLT", "HKST": "HKST", "CLST": "CLST", "CDT": "CDT", "MESZ": "MESZ", "∅∅∅": "∅∅∅", "HEOG": "HEOG", "WAT": "WAT", "WAST": "WAST", "CHAST": "CHAST", "UYST": "UYST", "WART": "WART"},
72 // Locale returns the current translators string locale
73 func (lkt *lkt) Locale() string {
77 // PluralsCardinal returns the list of cardinal plural rules associated with 'lkt'
78 func (lkt *lkt) PluralsCardinal() []locales.PluralRule {
79 return lkt.pluralsCardinal
82 // PluralsOrdinal returns the list of ordinal plural rules associated with 'lkt'
83 func (lkt *lkt) PluralsOrdinal() []locales.PluralRule {
84 return lkt.pluralsOrdinal
87 // PluralsRange returns the list of range plural rules associated with 'lkt'
88 func (lkt *lkt) PluralsRange() []locales.PluralRule {
89 return lkt.pluralsRange
92 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'lkt'
93 func (lkt *lkt) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
94 return locales.PluralRuleOther
97 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'lkt'
98 func (lkt *lkt) 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 'lkt'
103 func (lkt *lkt) 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 (lkt *lkt) MonthAbbreviated(month time.Month) string {
109 return lkt.monthsAbbreviated[month]
112 // MonthsAbbreviated returns the locales abbreviated months
113 func (lkt *lkt) MonthsAbbreviated() []string {
117 // MonthNarrow returns the locales narrow month given the 'month' provided
118 func (lkt *lkt) MonthNarrow(month time.Month) string {
119 return lkt.monthsNarrow[month]
122 // MonthsNarrow returns the locales narrow months
123 func (lkt *lkt) MonthsNarrow() []string {
127 // MonthWide returns the locales wide month given the 'month' provided
128 func (lkt *lkt) MonthWide(month time.Month) string {
129 return lkt.monthsWide[month]
132 // MonthsWide returns the locales wide months
133 func (lkt *lkt) MonthsWide() []string {
134 return lkt.monthsWide[1:]
137 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
138 func (lkt *lkt) WeekdayAbbreviated(weekday time.Weekday) string {
139 return lkt.daysAbbreviated[weekday]
142 // WeekdaysAbbreviated returns the locales abbreviated weekdays
143 func (lkt *lkt) WeekdaysAbbreviated() []string {
144 return lkt.daysAbbreviated
147 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
148 func (lkt *lkt) WeekdayNarrow(weekday time.Weekday) string {
149 return lkt.daysNarrow[weekday]
152 // WeekdaysNarrow returns the locales narrow weekdays
153 func (lkt *lkt) WeekdaysNarrow() []string {
154 return lkt.daysNarrow
157 // WeekdayShort returns the locales short weekday given the 'weekday' provided
158 func (lkt *lkt) WeekdayShort(weekday time.Weekday) string {
159 return lkt.daysShort[weekday]
162 // WeekdaysShort returns the locales short weekdays
163 func (lkt *lkt) WeekdaysShort() []string {
167 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
168 func (lkt *lkt) WeekdayWide(weekday time.Weekday) string {
169 return lkt.daysWide[weekday]
172 // WeekdaysWide returns the locales wide weekdays
173 func (lkt *lkt) WeekdaysWide() []string {
177 // Decimal returns the decimal point of number
178 func (lkt *lkt) Decimal() string {
182 // Group returns the group of number
183 func (lkt *lkt) Group() string {
187 // Group returns the minus sign of number
188 func (lkt *lkt) Minus() string {
192 // FmtNumber returns 'num' with digits/precision of 'v' for 'lkt' and handles both Whole and Real numbers based on 'v'
193 func (lkt *lkt) FmtNumber(num float64, v uint64) string {
195 return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
198 // FmtPercent returns 'num' with digits/precision of 'v' for 'lkt' and handles both Whole and Real numbers based on 'v'
199 // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
200 func (lkt *lkt) FmtPercent(num float64, v uint64) string {
201 return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
204 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'lkt'
205 func (lkt *lkt) FmtCurrency(num float64, v uint64, currency currency.Type) string {
207 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
208 symbol := lkt.currencies[currency]
209 l := len(s) + len(symbol) + 5
211 b := make([]byte, 0, l)
213 for i := len(s) - 1; i >= 0; i-- {
216 b = append(b, lkt.decimal[0])
223 for j := len(symbol) - 1; j >= 0; j-- {
224 b = append(b, symbol[j])
227 for j := len(lkt.currencyPositivePrefix) - 1; j >= 0; j-- {
228 b = append(b, lkt.currencyPositivePrefix[j])
232 b = append(b, lkt.minus[0])
236 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
237 b[i], b[j] = b[j], b[i]
240 b = append(b, lkt.currencyPositiveSuffix...)
245 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'lkt'
246 // in accounting notation.
247 func (lkt *lkt) FmtAccounting(num float64, v uint64, currency currency.Type) string {
249 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
250 symbol := lkt.currencies[currency]
251 l := len(s) + len(symbol) + 5
253 b := make([]byte, 0, l)
255 for i := len(s) - 1; i >= 0; i-- {
258 b = append(b, lkt.decimal[0])
267 for j := len(symbol) - 1; j >= 0; j-- {
268 b = append(b, symbol[j])
271 for j := len(lkt.currencyNegativePrefix) - 1; j >= 0; j-- {
272 b = append(b, lkt.currencyNegativePrefix[j])
275 b = append(b, lkt.minus[0])
279 for j := len(symbol) - 1; j >= 0; j-- {
280 b = append(b, symbol[j])
283 for j := len(lkt.currencyPositivePrefix) - 1; j >= 0; j-- {
284 b = append(b, lkt.currencyPositivePrefix[j])
290 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
291 b[i], b[j] = b[j], b[i]
295 b = append(b, lkt.currencyNegativeSuffix...)
298 b = append(b, lkt.currencyPositiveSuffix...)
304 // FmtDateShort returns the short date representation of 't' for 'lkt'
305 func (lkt *lkt) FmtDateShort(t time.Time) string {
307 b := make([]byte, 0, 32)
309 b = strconv.AppendInt(b, int64(t.Month()), 10)
310 b = append(b, []byte{0x2f}...)
311 b = strconv.AppendInt(b, int64(t.Day()), 10)
312 b = append(b, []byte{0x2f}...)
315 b = append(b, strconv.Itoa(t.Year())[2:]...)
317 b = append(b, strconv.Itoa(t.Year())[1:]...)
323 // FmtDateMedium returns the medium date representation of 't' for 'lkt'
324 func (lkt *lkt) FmtDateMedium(t time.Time) string {
326 b := make([]byte, 0, 32)
328 b = append(b, lkt.monthsAbbreviated[t.Month()]...)
329 b = append(b, []byte{0x20}...)
330 b = strconv.AppendInt(b, int64(t.Day()), 10)
331 b = append(b, []byte{0x2c, 0x20}...)
334 b = strconv.AppendInt(b, int64(t.Year()), 10)
336 b = strconv.AppendInt(b, int64(-t.Year()), 10)
342 // FmtDateLong returns the long date representation of 't' for 'lkt'
343 func (lkt *lkt) FmtDateLong(t time.Time) string {
345 b := make([]byte, 0, 32)
347 b = append(b, lkt.monthsWide[t.Month()]...)
348 b = append(b, []byte{0x20}...)
349 b = strconv.AppendInt(b, int64(t.Day()), 10)
350 b = append(b, []byte{0x2c, 0x20}...)
353 b = strconv.AppendInt(b, int64(t.Year()), 10)
355 b = strconv.AppendInt(b, int64(-t.Year()), 10)
361 // FmtDateFull returns the full date representation of 't' for 'lkt'
362 func (lkt *lkt) FmtDateFull(t time.Time) string {
364 b := make([]byte, 0, 32)
366 b = append(b, lkt.daysWide[t.Weekday()]...)
367 b = append(b, []byte{0x2c, 0x20}...)
368 b = append(b, lkt.monthsWide[t.Month()]...)
369 b = append(b, []byte{0x20}...)
370 b = strconv.AppendInt(b, int64(t.Day()), 10)
371 b = append(b, []byte{0x2c, 0x20}...)
374 b = strconv.AppendInt(b, int64(t.Year()), 10)
376 b = strconv.AppendInt(b, int64(-t.Year()), 10)
382 // FmtTimeShort returns the short time representation of 't' for 'lkt'
383 func (lkt *lkt) FmtTimeShort(t time.Time) string {
385 b := make([]byte, 0, 32)
393 b = strconv.AppendInt(b, int64(h), 10)
394 b = append(b, lkt.timeSeparator...)
400 b = strconv.AppendInt(b, int64(t.Minute()), 10)
401 b = append(b, []byte{0x20}...)
404 b = append(b, lkt.periodsAbbreviated[0]...)
406 b = append(b, lkt.periodsAbbreviated[1]...)
412 // FmtTimeMedium returns the medium time representation of 't' for 'lkt'
413 func (lkt *lkt) FmtTimeMedium(t time.Time) string {
415 b := make([]byte, 0, 32)
423 b = strconv.AppendInt(b, int64(h), 10)
424 b = append(b, lkt.timeSeparator...)
430 b = strconv.AppendInt(b, int64(t.Minute()), 10)
431 b = append(b, lkt.timeSeparator...)
437 b = strconv.AppendInt(b, int64(t.Second()), 10)
438 b = append(b, []byte{0x20}...)
441 b = append(b, lkt.periodsAbbreviated[0]...)
443 b = append(b, lkt.periodsAbbreviated[1]...)
449 // FmtTimeLong returns the long time representation of 't' for 'lkt'
450 func (lkt *lkt) FmtTimeLong(t time.Time) string {
452 b := make([]byte, 0, 32)
460 b = strconv.AppendInt(b, int64(h), 10)
461 b = append(b, lkt.timeSeparator...)
467 b = strconv.AppendInt(b, int64(t.Minute()), 10)
468 b = append(b, lkt.timeSeparator...)
474 b = strconv.AppendInt(b, int64(t.Second()), 10)
475 b = append(b, []byte{0x20}...)
478 b = append(b, lkt.periodsAbbreviated[0]...)
480 b = append(b, lkt.periodsAbbreviated[1]...)
483 b = append(b, []byte{0x20}...)
491 // FmtTimeFull returns the full time representation of 't' for 'lkt'
492 func (lkt *lkt) FmtTimeFull(t time.Time) string {
494 b := make([]byte, 0, 32)
502 b = strconv.AppendInt(b, int64(h), 10)
503 b = append(b, lkt.timeSeparator...)
509 b = strconv.AppendInt(b, int64(t.Minute()), 10)
510 b = append(b, lkt.timeSeparator...)
516 b = strconv.AppendInt(b, int64(t.Second()), 10)
517 b = append(b, []byte{0x20}...)
520 b = append(b, lkt.periodsAbbreviated[0]...)
522 b = append(b, lkt.periodsAbbreviated[1]...)
525 b = append(b, []byte{0x20}...)
529 if btz, ok := lkt.timezones[tz]; ok {
530 b = append(b, btz...)