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 currencyNegativePrefix 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 'lrc' locale
45 func New() locales.Translator {
56 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", "R$", "BRN", "BRR", "BRZ", "BSD", "BTN", "BUK", "BWP", "BYB", "BYN", "BYR", "BZD", "CAD", "CDF", "CHE", "CHF", "CHW", "CLE", "CLF", "CLP", "CNX", "CN¥", "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", "€", "FIM", "FJD", "FKP", "FRF", "£", "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", "₹", "IQD", "IRR", "ISJ", "ISK", "ITL", "JMD", "JOD", "JP¥", "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", "US$", "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 currencyPositivePrefix: " ",
58 currencyNegativePrefix: " ",
59 monthsAbbreviated: []string{"", "جانڤیە", "فئڤریە", "مارس", "آڤریل", "مئی", "جوٙأن", "جوٙلا", "آگوست", "سئپتامر", "ئوکتوڤر", "نوڤامر", "دئسامر"},
60 monthsNarrow: []string{"", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"},
61 monthsWide: []string{"", "جانڤیە", "فئڤریە", "مارس", "آڤریل", "مئی", "جوٙأن", "جوٙلا", "آگوست", "سئپتامر", "ئوکتوڤر", "نوڤامر", "دئسامر"},
62 periodsAbbreviated: []string{"AM", "PM"},
63 periodsWide: []string{"AM", "PM"},
64 erasAbbreviated: []string{"BCE", "CE"},
65 erasNarrow: []string{"", ""},
66 erasWide: []string{"", ""},
67 timezones: map[string]string{"MST": "MST", "OESZ": "OESZ", "ECT": "ECT", "HECU": "HECU", "LHST": "LHST", "VET": "VET", "HEPM": "HEPM", "HADT": "HADT", "HNOG": "HNOG", "HNPMX": "HNPMX", "SRT": "SRT", "NZDT": "NZDT", "JST": "JST", "CLST": "CLST", "HNPM": "HNPM", "ACWDT": "ACWDT", "MEZ": "MEZ", "HNNOMX": "HNNOMX", "HKT": "HKT", "AKST": "AKST", "WEZ": "WEZ", "CDT": "روٙشنایی نئهادار روٙز", "TMST": "TMST", "AEDT": "AEDT", "EAT": "EAT", "MESZ": "MESZ", "TMT": "TMT", "ADT": "ADT", "COST": "COST", "AKDT": "AKDT", "∅∅∅": "∅∅∅", "ACWST": "ACWST", "IST": "IST", "ART": "ART", "HAT": "HAT", "HKST": "HKST", "WIB": "WIB", "WAST": "WAST", "BOT": "BOT", "CAT": "CAT", "CST": "گاٛت مینجاٛیی ئستاٛنداٛرد", "MDT": "MDT", "MYT": "MYT", "AST": "AST", "HEOG": "HEOG", "SAST": "SAST", "COT": "COT", "WESZ": "WESZ", "CHAST": "CHAST", "HNCU": "HNCU", "HAST": "HAST", "WART": "WART", "GFT": "GFT", "ACST": "ACST", "ACDT": "ACDT", "AWDT": "AWDT", "JDT": "JDT", "HNEG": "HNEG", "EDT": "EDT", "ChST": "ChST", "PDT": "PDT", "GYT": "GYT", "AWST": "AWST", "UYST": "UYST", "WIT": "WIT", "OEZ": "OEZ", "HENOMX": "HENOMX", "HEEG": "HEEG", "CLT": "CLT", "GMT": "GMT", "HEPMX": "HEPMX", "NZST": "NZST", "WARST": "WARST", "WITA": "WITA", "AEST": "AEST", "SGT": "SGT", "CHADT": "CHADT", "BT": "BT", "UYT": "UYT", "LHDT": "LHDT", "ARST": "ARST", "WAT": "WAT", "HNT": "HNT", "EST": "EST", "PST": "PST"},
71 // Locale returns the current translators string locale
72 func (lrc *lrc) Locale() string {
76 // PluralsCardinal returns the list of cardinal plural rules associated with 'lrc'
77 func (lrc *lrc) PluralsCardinal() []locales.PluralRule {
78 return lrc.pluralsCardinal
81 // PluralsOrdinal returns the list of ordinal plural rules associated with 'lrc'
82 func (lrc *lrc) PluralsOrdinal() []locales.PluralRule {
83 return lrc.pluralsOrdinal
86 // PluralsRange returns the list of range plural rules associated with 'lrc'
87 func (lrc *lrc) PluralsRange() []locales.PluralRule {
88 return lrc.pluralsRange
91 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'lrc'
92 func (lrc *lrc) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
93 return locales.PluralRuleUnknown
96 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'lrc'
97 func (lrc *lrc) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
98 return locales.PluralRuleUnknown
101 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'lrc'
102 func (lrc *lrc) 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 (lrc *lrc) MonthAbbreviated(month time.Month) string {
108 return lrc.monthsAbbreviated[month]
111 // MonthsAbbreviated returns the locales abbreviated months
112 func (lrc *lrc) MonthsAbbreviated() []string {
113 return lrc.monthsAbbreviated[1:]
116 // MonthNarrow returns the locales narrow month given the 'month' provided
117 func (lrc *lrc) MonthNarrow(month time.Month) string {
118 return lrc.monthsNarrow[month]
121 // MonthsNarrow returns the locales narrow months
122 func (lrc *lrc) MonthsNarrow() []string {
123 return lrc.monthsNarrow[1:]
126 // MonthWide returns the locales wide month given the 'month' provided
127 func (lrc *lrc) MonthWide(month time.Month) string {
128 return lrc.monthsWide[month]
131 // MonthsWide returns the locales wide months
132 func (lrc *lrc) MonthsWide() []string {
133 return lrc.monthsWide[1:]
136 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
137 func (lrc *lrc) WeekdayAbbreviated(weekday time.Weekday) string {
138 return lrc.daysAbbreviated[weekday]
141 // WeekdaysAbbreviated returns the locales abbreviated weekdays
142 func (lrc *lrc) WeekdaysAbbreviated() []string {
143 return lrc.daysAbbreviated
146 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
147 func (lrc *lrc) WeekdayNarrow(weekday time.Weekday) string {
148 return lrc.daysNarrow[weekday]
151 // WeekdaysNarrow returns the locales narrow weekdays
152 func (lrc *lrc) WeekdaysNarrow() []string {
153 return lrc.daysNarrow
156 // WeekdayShort returns the locales short weekday given the 'weekday' provided
157 func (lrc *lrc) WeekdayShort(weekday time.Weekday) string {
158 return lrc.daysShort[weekday]
161 // WeekdaysShort returns the locales short weekdays
162 func (lrc *lrc) WeekdaysShort() []string {
166 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
167 func (lrc *lrc) WeekdayWide(weekday time.Weekday) string {
168 return lrc.daysWide[weekday]
171 // WeekdaysWide returns the locales wide weekdays
172 func (lrc *lrc) WeekdaysWide() []string {
176 // Decimal returns the decimal point of number
177 func (lrc *lrc) Decimal() string {
181 // Group returns the group of number
182 func (lrc *lrc) Group() string {
186 // Group returns the minus sign of number
187 func (lrc *lrc) Minus() string {
191 // FmtNumber returns 'num' with digits/precision of 'v' for 'lrc' and handles both Whole and Real numbers based on 'v'
192 func (lrc *lrc) FmtNumber(num float64, v uint64) string {
194 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
195 l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
198 b := make([]byte, 0, l)
200 for i := len(s) - 1; i >= 0; i-- {
203 b = append(b, lrc.decimal[0])
210 b = append(b, lrc.group[0])
221 b = append(b, lrc.minus[0])
225 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
226 b[i], b[j] = b[j], b[i]
232 // FmtPercent returns 'num' with digits/precision of 'v' for 'lrc' and handles both Whole and Real numbers based on 'v'
233 // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
234 func (lrc *lrc) FmtPercent(num float64, v uint64) string {
235 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
237 b := make([]byte, 0, l)
239 for i := len(s) - 1; i >= 0; i-- {
242 b = append(b, lrc.decimal[0])
250 b = append(b, lrc.minus[0])
254 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
255 b[i], b[j] = b[j], b[i]
258 b = append(b, lrc.percent...)
263 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'lrc'
264 func (lrc *lrc) FmtCurrency(num float64, v uint64, currency currency.Type) string {
266 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
267 symbol := lrc.currencies[currency]
268 l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
271 b := make([]byte, 0, l)
273 for i := len(s) - 1; i >= 0; i-- {
276 b = append(b, lrc.decimal[0])
283 b = append(b, lrc.group[0])
293 for j := len(symbol) - 1; j >= 0; j-- {
294 b = append(b, symbol[j])
297 for j := len(lrc.currencyPositivePrefix) - 1; j >= 0; j-- {
298 b = append(b, lrc.currencyPositivePrefix[j])
302 b = append(b, lrc.minus[0])
306 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
307 b[i], b[j] = b[j], b[i]
313 b = append(b, lrc.decimal...)
316 for i := 0; i < 2-int(v); i++ {
324 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'lrc'
325 // in accounting notation.
326 func (lrc *lrc) FmtAccounting(num float64, v uint64, currency currency.Type) string {
328 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
329 symbol := lrc.currencies[currency]
330 l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
333 b := make([]byte, 0, l)
335 for i := len(s) - 1; i >= 0; i-- {
338 b = append(b, lrc.decimal[0])
345 b = append(b, lrc.group[0])
357 for j := len(symbol) - 1; j >= 0; j-- {
358 b = append(b, symbol[j])
361 for j := len(lrc.currencyNegativePrefix) - 1; j >= 0; j-- {
362 b = append(b, lrc.currencyNegativePrefix[j])
365 b = append(b, lrc.minus[0])
369 for j := len(symbol) - 1; j >= 0; j-- {
370 b = append(b, symbol[j])
373 for j := len(lrc.currencyPositivePrefix) - 1; j >= 0; j-- {
374 b = append(b, lrc.currencyPositivePrefix[j])
380 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
381 b[i], b[j] = b[j], b[i]
387 b = append(b, lrc.decimal...)
390 for i := 0; i < 2-int(v); i++ {
398 // FmtDateShort returns the short date representation of 't' for 'lrc'
399 func (lrc *lrc) FmtDateShort(t time.Time) string {
401 b := make([]byte, 0, 32)
404 b = strconv.AppendInt(b, int64(t.Year()), 10)
406 b = strconv.AppendInt(b, int64(-t.Year()), 10)
409 b = append(b, []byte{0x2d}...)
415 b = strconv.AppendInt(b, int64(t.Month()), 10)
417 b = append(b, []byte{0x2d}...)
423 b = strconv.AppendInt(b, int64(t.Day()), 10)
428 // FmtDateMedium returns the medium date representation of 't' for 'lrc'
429 func (lrc *lrc) FmtDateMedium(t time.Time) string {
431 b := make([]byte, 0, 32)
434 b = strconv.AppendInt(b, int64(t.Year()), 10)
436 b = strconv.AppendInt(b, int64(-t.Year()), 10)
439 b = append(b, []byte{0x20}...)
440 b = append(b, lrc.monthsAbbreviated[t.Month()]...)
441 b = append(b, []byte{0x20}...)
442 b = strconv.AppendInt(b, int64(t.Day()), 10)
447 // FmtDateLong returns the long date representation of 't' for 'lrc'
448 func (lrc *lrc) FmtDateLong(t time.Time) string {
450 b := make([]byte, 0, 32)
453 b = strconv.AppendInt(b, int64(t.Year()), 10)
455 b = strconv.AppendInt(b, int64(-t.Year()), 10)
458 b = append(b, []byte{0x20}...)
459 b = append(b, lrc.monthsWide[t.Month()]...)
460 b = append(b, []byte{0x20}...)
461 b = strconv.AppendInt(b, int64(t.Day()), 10)
466 // FmtDateFull returns the full date representation of 't' for 'lrc'
467 func (lrc *lrc) FmtDateFull(t time.Time) string {
469 b := make([]byte, 0, 32)
472 b = strconv.AppendInt(b, int64(t.Year()), 10)
474 b = strconv.AppendInt(b, int64(-t.Year()), 10)
477 b = append(b, []byte{0x20}...)
478 b = append(b, lrc.monthsWide[t.Month()]...)
479 b = append(b, []byte{0x20}...)
480 b = strconv.AppendInt(b, int64(t.Day()), 10)
481 b = append(b, []byte{0x2c, 0x20}...)
482 b = append(b, lrc.daysWide[t.Weekday()]...)
487 // FmtTimeShort returns the short time representation of 't' for 'lrc'
488 func (lrc *lrc) FmtTimeShort(t time.Time) string {
490 b := make([]byte, 0, 32)
496 b = strconv.AppendInt(b, int64(t.Hour()), 10)
497 b = append(b, lrc.timeSeparator...)
503 b = strconv.AppendInt(b, int64(t.Minute()), 10)
508 // FmtTimeMedium returns the medium time representation of 't' for 'lrc'
509 func (lrc *lrc) FmtTimeMedium(t time.Time) string {
511 b := make([]byte, 0, 32)
517 b = strconv.AppendInt(b, int64(t.Hour()), 10)
518 b = append(b, lrc.timeSeparator...)
524 b = strconv.AppendInt(b, int64(t.Minute()), 10)
525 b = append(b, lrc.timeSeparator...)
531 b = strconv.AppendInt(b, int64(t.Second()), 10)
536 // FmtTimeLong returns the long time representation of 't' for 'lrc'
537 func (lrc *lrc) FmtTimeLong(t time.Time) string {
539 b := make([]byte, 0, 32)
545 b = strconv.AppendInt(b, int64(t.Hour()), 10)
546 b = append(b, lrc.timeSeparator...)
552 b = strconv.AppendInt(b, int64(t.Minute()), 10)
553 b = append(b, lrc.timeSeparator...)
559 b = strconv.AppendInt(b, int64(t.Second()), 10)
560 b = append(b, []byte{0x20}...)
568 // FmtTimeFull returns the full time representation of 't' for 'lrc'
569 func (lrc *lrc) FmtTimeFull(t time.Time) string {
571 b := make([]byte, 0, 32)
577 b = strconv.AppendInt(b, int64(t.Hour()), 10)
578 b = append(b, lrc.timeSeparator...)
584 b = strconv.AppendInt(b, int64(t.Minute()), 10)
585 b = append(b, lrc.timeSeparator...)
591 b = strconv.AppendInt(b, int64(t.Second()), 10)
592 b = append(b, []byte{0x20}...)
596 if btz, ok := lrc.timezones[tz]; ok {
597 b = append(b, btz...)