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 'ti' locale
43 func New() locales.Translator {
46 pluralsCardinal: []locales.PluralRule{2, 6},
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", "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", "Br", "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 monthsAbbreviated: []string{"", "ጥሪ", "ለካ", "መጋ", "ሚያ", "ግን", "ሰነ", "ሓም", "ነሓ", "መስ", "ጥቅ", "ሕዳ", "ታሕ"},
58 monthsNarrow: []string{"", "ጥ", "ለ", "መ", "ሚ", "ግ", "ሰ", "ሓ", "ነ", "መ", "ጥ", "ሕ", "ታ"},
59 monthsWide: []string{"", "ጥሪ", "ለካቲት", "መጋቢት", "ሚያዝያ", "ግንቦት", "ሰነ", "ሓምለ", "ነሓሰ", "መስከረም", "ጥቅምቲ", "ሕዳር", "ታሕሳስ"},
60 daysAbbreviated: []string{"ሰን", "ሰኑ", "ሰሉ", "ረቡ", "ሓሙ", "ዓር", "ቀዳ"},
61 daysNarrow: []string{"ሰ", "ሰ", "ሰ", "ረ", "ሓ", "ዓ", "ቀ"},
62 daysShort: []string{"ሰን", "ሰኑ", "ሰሉ", "ረቡ", "ሓሙ", "ዓር", "ቀዳ"},
63 daysWide: []string{"ሰንበት", "ሰኑይ", "ሠሉስ", "ረቡዕ", "ኃሙስ", "ዓርቢ", "ቀዳም"},
64 periodsAbbreviated: []string{"ንጉሆ ሰዓተ", "ድሕር ሰዓት"},
65 periodsWide: []string{"ንጉሆ ሰዓተ", "ድሕር ሰዓት"},
66 erasAbbreviated: []string{"ዓ/ዓ", "ዓ/ም"},
67 erasNarrow: []string{"", ""},
68 erasWide: []string{"ዓ/ዓ", "ዓመተ ምህረት"},
69 timezones: map[string]string{"GYT": "GYT", "WIB": "WIB", "SRT": "SRT", "HNNOMX": "HNNOMX", "HNPMX": "HNPMX", "AWDT": "AWDT", "AEST": "AEST", "SAST": "SAST", "HEEG": "HEEG", "HAT": "HAT", "HKT": "HKT", "SGT": "SGT", "WIT": "WIT", "MEZ": "MEZ", "COT": "COT", "HNCU": "HNCU", "AWST": "AWST", "MYT": "MYT", "JST": "JST", "AST": "AST", "GFT": "GFT", "ECT": "ECT", "CDT": "CDT", "LHST": "LHST", "WITA": "WITA", "∅∅∅": "∅∅∅", "CAT": "CAT", "PDT": "PDT", "HEPM": "HEPM", "AEDT": "AEDT", "HNPM": "HNPM", "BT": "BT", "MST": "MST", "HKST": "HKST", "WEZ": "WEZ", "OESZ": "OESZ", "HNEG": "HNEG", "ACDT": "ACDT", "PST": "PST", "HAST": "HAST", "WART": "WART", "CLT": "CLT", "EDT": "EDT", "AKST": "AKST", "WESZ": "WESZ", "CHAST": "CHAST", "CHADT": "CHADT", "ADT": "ADT", "ACST": "ACST", "BOT": "BOT", "TMT": "TMT", "TMST": "TMST", "EAT": "EAT", "CST": "CST", "MDT": "MDT", "ACWST": "ACWST", "MESZ": "MESZ", "JDT": "JDT", "ACWDT": "ACWDT", "UYT": "UYT", "ART": "ART", "ARST": "ARST", "HNOG": "HNOG", "CLST": "CLST", "EST": "EST", "HEPMX": "HEPMX", "NZDT": "NZDT", "VET": "VET", "HENOMX": "HENOMX", "HEOG": "HEOG", "WAST": "WAST", "COST": "COST", "GMT": "GMT", "ChST": "ChST", "IST": "IST", "AKDT": "AKDT", "HECU": "HECU", "HADT": "HADT", "NZST": "NZST", "WARST": "WARST", "WAT": "WAT", "HNT": "HNT", "UYST": "UYST", "OEZ": "OEZ", "LHDT": "LHDT"},
73 // Locale returns the current translators string locale
74 func (ti *ti) Locale() string {
78 // PluralsCardinal returns the list of cardinal plural rules associated with 'ti'
79 func (ti *ti) PluralsCardinal() []locales.PluralRule {
80 return ti.pluralsCardinal
83 // PluralsOrdinal returns the list of ordinal plural rules associated with 'ti'
84 func (ti *ti) PluralsOrdinal() []locales.PluralRule {
85 return ti.pluralsOrdinal
88 // PluralsRange returns the list of range plural rules associated with 'ti'
89 func (ti *ti) PluralsRange() []locales.PluralRule {
90 return ti.pluralsRange
93 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'ti'
94 func (ti *ti) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
99 return locales.PluralRuleOne
102 return locales.PluralRuleOther
105 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'ti'
106 func (ti *ti) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
107 return locales.PluralRuleUnknown
110 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'ti'
111 func (ti *ti) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
112 return locales.PluralRuleUnknown
115 // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
116 func (ti *ti) MonthAbbreviated(month time.Month) string {
117 return ti.monthsAbbreviated[month]
120 // MonthsAbbreviated returns the locales abbreviated months
121 func (ti *ti) MonthsAbbreviated() []string {
122 return ti.monthsAbbreviated[1:]
125 // MonthNarrow returns the locales narrow month given the 'month' provided
126 func (ti *ti) MonthNarrow(month time.Month) string {
127 return ti.monthsNarrow[month]
130 // MonthsNarrow returns the locales narrow months
131 func (ti *ti) MonthsNarrow() []string {
132 return ti.monthsNarrow[1:]
135 // MonthWide returns the locales wide month given the 'month' provided
136 func (ti *ti) MonthWide(month time.Month) string {
137 return ti.monthsWide[month]
140 // MonthsWide returns the locales wide months
141 func (ti *ti) MonthsWide() []string {
142 return ti.monthsWide[1:]
145 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
146 func (ti *ti) WeekdayAbbreviated(weekday time.Weekday) string {
147 return ti.daysAbbreviated[weekday]
150 // WeekdaysAbbreviated returns the locales abbreviated weekdays
151 func (ti *ti) WeekdaysAbbreviated() []string {
152 return ti.daysAbbreviated
155 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
156 func (ti *ti) WeekdayNarrow(weekday time.Weekday) string {
157 return ti.daysNarrow[weekday]
160 // WeekdaysNarrow returns the locales narrow weekdays
161 func (ti *ti) WeekdaysNarrow() []string {
165 // WeekdayShort returns the locales short weekday given the 'weekday' provided
166 func (ti *ti) WeekdayShort(weekday time.Weekday) string {
167 return ti.daysShort[weekday]
170 // WeekdaysShort returns the locales short weekdays
171 func (ti *ti) WeekdaysShort() []string {
175 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
176 func (ti *ti) WeekdayWide(weekday time.Weekday) string {
177 return ti.daysWide[weekday]
180 // WeekdaysWide returns the locales wide weekdays
181 func (ti *ti) WeekdaysWide() []string {
185 // Decimal returns the decimal point of number
186 func (ti *ti) Decimal() string {
190 // Group returns the group of number
191 func (ti *ti) Group() string {
195 // Group returns the minus sign of number
196 func (ti *ti) Minus() string {
200 // FmtNumber returns 'num' with digits/precision of 'v' for 'ti' and handles both Whole and Real numbers based on 'v'
201 func (ti *ti) FmtNumber(num float64, v uint64) string {
203 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
204 l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
207 b := make([]byte, 0, l)
209 for i := len(s) - 1; i >= 0; i-- {
212 b = append(b, ti.decimal[0])
219 b = append(b, ti.group[0])
230 b = append(b, ti.minus[0])
234 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
235 b[i], b[j] = b[j], b[i]
241 // FmtPercent returns 'num' with digits/precision of 'v' for 'ti' and handles both Whole and Real numbers based on 'v'
242 // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
243 func (ti *ti) FmtPercent(num float64, v uint64) string {
244 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
246 b := make([]byte, 0, l)
248 for i := len(s) - 1; i >= 0; i-- {
251 b = append(b, ti.decimal[0])
259 b = append(b, ti.minus[0])
263 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
264 b[i], b[j] = b[j], b[i]
267 b = append(b, ti.percent...)
272 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'ti'
273 func (ti *ti) FmtCurrency(num float64, v uint64, currency currency.Type) string {
275 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
276 symbol := ti.currencies[currency]
277 l := len(s) + len(symbol) + 2 + 1*len(s[:len(s)-int(v)-1])/3
280 b := make([]byte, 0, l)
282 for i := len(s) - 1; i >= 0; i-- {
285 b = append(b, ti.decimal[0])
292 b = append(b, ti.group[0])
302 for j := len(symbol) - 1; j >= 0; j-- {
303 b = append(b, symbol[j])
307 b = append(b, ti.minus[0])
311 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
312 b[i], b[j] = b[j], b[i]
318 b = append(b, ti.decimal...)
321 for i := 0; i < 2-int(v); i++ {
329 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'ti'
330 // in accounting notation.
331 func (ti *ti) FmtAccounting(num float64, v uint64, currency currency.Type) string {
333 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
334 symbol := ti.currencies[currency]
335 l := len(s) + len(symbol) + 2 + 1*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, ti.decimal[0])
350 b = append(b, ti.group[0])
362 for j := len(symbol) - 1; j >= 0; j-- {
363 b = append(b, symbol[j])
366 b = append(b, ti.minus[0])
370 for j := len(symbol) - 1; j >= 0; j-- {
371 b = append(b, symbol[j])
377 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
378 b[i], b[j] = b[j], b[i]
384 b = append(b, ti.decimal...)
387 for i := 0; i < 2-int(v); i++ {
395 // FmtDateShort returns the short date representation of 't' for 'ti'
396 func (ti *ti) FmtDateShort(t time.Time) string {
398 b := make([]byte, 0, 32)
404 b = strconv.AppendInt(b, int64(t.Day()), 10)
405 b = append(b, []byte{0x2f}...)
411 b = strconv.AppendInt(b, int64(t.Month()), 10)
413 b = append(b, []byte{0x2f}...)
416 b = append(b, strconv.Itoa(t.Year())[2:]...)
418 b = append(b, strconv.Itoa(t.Year())[1:]...)
424 // FmtDateMedium returns the medium date representation of 't' for 'ti'
425 func (ti *ti) FmtDateMedium(t time.Time) string {
427 b := make([]byte, 0, 32)
433 b = strconv.AppendInt(b, int64(t.Day()), 10)
434 b = append(b, []byte{0x2d}...)
435 b = append(b, ti.monthsAbbreviated[t.Month()]...)
436 b = append(b, []byte{0x2d}...)
439 b = strconv.AppendInt(b, int64(t.Year()), 10)
441 b = strconv.AppendInt(b, int64(-t.Year()), 10)
447 // FmtDateLong returns the long date representation of 't' for 'ti'
448 func (ti *ti) FmtDateLong(t time.Time) string {
450 b := make([]byte, 0, 32)
456 b = strconv.AppendInt(b, int64(t.Day()), 10)
457 b = append(b, []byte{0x20}...)
458 b = append(b, ti.monthsWide[t.Month()]...)
459 b = append(b, []byte{0x20}...)
462 b = strconv.AppendInt(b, int64(t.Year()), 10)
464 b = strconv.AppendInt(b, int64(-t.Year()), 10)
470 // FmtDateFull returns the full date representation of 't' for 'ti'
471 func (ti *ti) FmtDateFull(t time.Time) string {
473 b := make([]byte, 0, 32)
475 b = append(b, ti.daysWide[t.Weekday()]...)
476 b = append(b, []byte{0xe1, 0x8d, 0xa3, 0x20}...)
482 b = strconv.AppendInt(b, int64(t.Day()), 10)
483 b = append(b, []byte{0x20}...)
484 b = append(b, ti.monthsWide[t.Month()]...)
485 b = append(b, []byte{0x20, 0xe1, 0x88, 0x98, 0xe1, 0x8b, 0x93, 0xe1, 0x88, 0x8d, 0xe1, 0x89, 0xb2, 0x20}...)
488 b = strconv.AppendInt(b, int64(t.Year()), 10)
490 b = strconv.AppendInt(b, int64(-t.Year()), 10)
493 b = append(b, []byte{0x20}...)
496 b = append(b, ti.erasWide[0]...)
498 b = append(b, ti.erasWide[1]...)
504 // FmtTimeShort returns the short time representation of 't' for 'ti'
505 func (ti *ti) FmtTimeShort(t time.Time) string {
507 b := make([]byte, 0, 32)
515 b = strconv.AppendInt(b, int64(h), 10)
516 b = append(b, ti.timeSeparator...)
522 b = strconv.AppendInt(b, int64(t.Minute()), 10)
523 b = append(b, []byte{0x20}...)
526 b = append(b, ti.periodsAbbreviated[0]...)
528 b = append(b, ti.periodsAbbreviated[1]...)
534 // FmtTimeMedium returns the medium time representation of 't' for 'ti'
535 func (ti *ti) FmtTimeMedium(t time.Time) string {
537 b := make([]byte, 0, 32)
545 b = strconv.AppendInt(b, int64(h), 10)
546 b = append(b, ti.timeSeparator...)
552 b = strconv.AppendInt(b, int64(t.Minute()), 10)
553 b = append(b, ti.timeSeparator...)
559 b = strconv.AppendInt(b, int64(t.Second()), 10)
560 b = append(b, []byte{0x20}...)
563 b = append(b, ti.periodsAbbreviated[0]...)
565 b = append(b, ti.periodsAbbreviated[1]...)
571 // FmtTimeLong returns the long time representation of 't' for 'ti'
572 func (ti *ti) FmtTimeLong(t time.Time) string {
574 b := make([]byte, 0, 32)
582 b = strconv.AppendInt(b, int64(h), 10)
583 b = append(b, ti.timeSeparator...)
589 b = strconv.AppendInt(b, int64(t.Minute()), 10)
590 b = append(b, ti.timeSeparator...)
596 b = strconv.AppendInt(b, int64(t.Second()), 10)
597 b = append(b, []byte{0x20}...)
600 b = append(b, ti.periodsAbbreviated[0]...)
602 b = append(b, ti.periodsAbbreviated[1]...)
605 b = append(b, []byte{0x20}...)
613 // FmtTimeFull returns the full time representation of 't' for 'ti'
614 func (ti *ti) FmtTimeFull(t time.Time) string {
616 b := make([]byte, 0, 32)
624 b = strconv.AppendInt(b, int64(h), 10)
625 b = append(b, ti.timeSeparator...)
631 b = strconv.AppendInt(b, int64(t.Minute()), 10)
632 b = append(b, ti.timeSeparator...)
638 b = strconv.AppendInt(b, int64(t.Second()), 10)
639 b = append(b, []byte{0x20}...)
642 b = append(b, ti.periodsAbbreviated[0]...)
644 b = append(b, ti.periodsAbbreviated[1]...)
647 b = append(b, []byte{0x20}...)
651 if btz, ok := ti.timezones[tz]; ok {
652 b = append(b, btz...)