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 'mt' locale
43 func New() locales.Translator {
46 pluralsCardinal: []locales.PluralRule{2, 4, 5, 6},
56 currencies: []string{"ADP", "AED", "AFA", "AFN", "ALK", "ALL", "AMD", "ANG", "AOA", "AOK", "AON", "AOR", "ARA", "ARL", "ARM", "ARP", "ARS", "ATS", "A$", "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", "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", "€", "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", "₪", "₹", "IQD", "IRR", "ISJ", "ISK", "ITL", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRH", "KRO", "₩", "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", "MX$", "MXP", "MXV", "MYR", "MZE", "MZM", "MZN", "NAD", "NGN", "NIC", "NIO", "NLG", "NOK", "Rs", "NZ$", "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", "NT$", "TZS", "UAH", "UAK", "UGS", "UGX", "US$", "USN", "USS", "UYI", "UYP", "UYU", "UZS", "VEB", "VEF", "₫", "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", "ZAR", "ZMK", "ZMW", "ZRN", "ZRZ", "ZWD", "ZWL", "ZWR"},
57 monthsAbbreviated: []string{"", "Jan", "Fra", "Mar", "Apr", "Mej", "Ġun", "Lul", "Aww", "Set", "Ott", "Nov", "Diċ"},
58 monthsNarrow: []string{"", "J", "F", "M", "A", "M", "Ġ", "L", "A", "S", "O", "N", "D"},
59 monthsWide: []string{"", "Jannar", "Frar", "Marzu", "April", "Mejju", "Ġunju", "Lulju", "Awwissu", "Settembru", "Ottubru", "Novembru", "Diċembru"},
60 daysAbbreviated: []string{"Ħad", "Tne", "Tli", "Erb", "Ħam", "Ġim", "Sib"},
61 daysNarrow: []string{"Ħd", "T", "Tl", "Er", "Ħm", "Ġm", "Sb"},
62 daysShort: []string{"Ħad", "Tne", "Tli", "Erb", "Ħam", "Ġim", "Sib"},
63 daysWide: []string{"Il-Ħadd", "It-Tnejn", "It-Tlieta", "L-Erbgħa", "Il-Ħamis", "Il-Ġimgħa", "Is-Sibt"},
64 periodsAbbreviated: []string{"AM", "PM"},
65 periodsNarrow: []string{"am", "pm"},
66 periodsWide: []string{"AM", "PM"},
67 erasAbbreviated: []string{"QK", "WK"},
68 erasNarrow: []string{"", ""},
69 erasWide: []string{"Qabel Kristu", "Wara Kristu"},
70 timezones: map[string]string{"JST": "JST", "WARST": "WARST", "AST": "AST", "ARST": "ARST", "HEPM": "HEPM", "HAST": "HAST", "HECU": "HECU", "HNNOMX": "HNNOMX", "IST": "IST", "COST": "COST", "∅∅∅": "∅∅∅", "ChST": "ChST", "WAT": "WAT", "MST": "MST", "UYT": "UYT", "AWST": "AWST", "WITA": "WITA", "AEST": "AEST", "HNOG": "HNOG", "EAT": "EAT", "SAST": "SAST", "BT": "BT", "CST": "CST", "ACDT": "ACDT", "OESZ": "OESZ", "HNT": "HNT", "CAT": "CAT", "WIB": "WIB", "MDT": "MDT", "LHST": "LHST", "HAT": "HAT", "AKDT": "AKDT", "SGT": "SGT", "CHAST": "CHAST", "CHADT": "CHADT", "BOT": "BOT", "SRT": "SRT", "UYST": "UYST", "MEZ": "Ħin Ċentrali Ewropew Standard", "NZST": "NZST", "HNPMX": "HNPMX", "HEPMX": "HEPMX", "EDT": "EDT", "HEEG": "HEEG", "GFT": "GFT", "AKST": "AKST", "VET": "VET", "HEOG": "HEOG", "WIT": "WIT", "HKST": "HKST", "EST": "EST", "GYT": "GYT", "ECT": "ECT", "AWDT": "AWDT", "ACWDT": "ACWDT", "JDT": "JDT", "LHDT": "LHDT", "HNPM": "HNPM", "HENOMX": "HENOMX", "HKT": "HKT", "COT": "COT", "ACWST": "ACWST", "MYT": "MYT", "ART": "ART", "ADT": "ADT", "AEDT": "AEDT", "WESZ": "WESZ", "NZDT": "NZDT", "WAST": "WAST", "HNEG": "HNEG", "PST": "PST", "CDT": "CDT", "PDT": "PDT", "HNCU": "HNCU", "MESZ": "Ħin Ċentrali Ewropew tas-Sajf", "HADT": "HADT", "TMT": "TMT", "TMST": "TMST", "WEZ": "WEZ", "GMT": "GMT", "CLT": "CLT", "CLST": "CLST", "ACST": "ACST", "OEZ": "OEZ", "WART": "WART"},
74 // Locale returns the current translators string locale
75 func (mt *mt) Locale() string {
79 // PluralsCardinal returns the list of cardinal plural rules associated with 'mt'
80 func (mt *mt) PluralsCardinal() []locales.PluralRule {
81 return mt.pluralsCardinal
84 // PluralsOrdinal returns the list of ordinal plural rules associated with 'mt'
85 func (mt *mt) PluralsOrdinal() []locales.PluralRule {
86 return mt.pluralsOrdinal
89 // PluralsRange returns the list of range plural rules associated with 'mt'
90 func (mt *mt) PluralsRange() []locales.PluralRule {
91 return mt.pluralsRange
94 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'mt'
95 func (mt *mt) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
98 nMod100 := math.Mod(n, 100)
101 return locales.PluralRuleOne
102 } else if (n == 0) || (nMod100 >= 2 && nMod100 <= 10) {
103 return locales.PluralRuleFew
104 } else if nMod100 >= 11 && nMod100 <= 19 {
105 return locales.PluralRuleMany
108 return locales.PluralRuleOther
111 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'mt'
112 func (mt *mt) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
113 return locales.PluralRuleUnknown
116 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'mt'
117 func (mt *mt) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
118 return locales.PluralRuleUnknown
121 // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
122 func (mt *mt) MonthAbbreviated(month time.Month) string {
123 return mt.monthsAbbreviated[month]
126 // MonthsAbbreviated returns the locales abbreviated months
127 func (mt *mt) MonthsAbbreviated() []string {
128 return mt.monthsAbbreviated[1:]
131 // MonthNarrow returns the locales narrow month given the 'month' provided
132 func (mt *mt) MonthNarrow(month time.Month) string {
133 return mt.monthsNarrow[month]
136 // MonthsNarrow returns the locales narrow months
137 func (mt *mt) MonthsNarrow() []string {
138 return mt.monthsNarrow[1:]
141 // MonthWide returns the locales wide month given the 'month' provided
142 func (mt *mt) MonthWide(month time.Month) string {
143 return mt.monthsWide[month]
146 // MonthsWide returns the locales wide months
147 func (mt *mt) MonthsWide() []string {
148 return mt.monthsWide[1:]
151 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
152 func (mt *mt) WeekdayAbbreviated(weekday time.Weekday) string {
153 return mt.daysAbbreviated[weekday]
156 // WeekdaysAbbreviated returns the locales abbreviated weekdays
157 func (mt *mt) WeekdaysAbbreviated() []string {
158 return mt.daysAbbreviated
161 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
162 func (mt *mt) WeekdayNarrow(weekday time.Weekday) string {
163 return mt.daysNarrow[weekday]
166 // WeekdaysNarrow returns the locales narrow weekdays
167 func (mt *mt) WeekdaysNarrow() []string {
171 // WeekdayShort returns the locales short weekday given the 'weekday' provided
172 func (mt *mt) WeekdayShort(weekday time.Weekday) string {
173 return mt.daysShort[weekday]
176 // WeekdaysShort returns the locales short weekdays
177 func (mt *mt) WeekdaysShort() []string {
181 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
182 func (mt *mt) WeekdayWide(weekday time.Weekday) string {
183 return mt.daysWide[weekday]
186 // WeekdaysWide returns the locales wide weekdays
187 func (mt *mt) WeekdaysWide() []string {
191 // Decimal returns the decimal point of number
192 func (mt *mt) Decimal() string {
196 // Group returns the group of number
197 func (mt *mt) Group() string {
201 // Group returns the minus sign of number
202 func (mt *mt) Minus() string {
206 // FmtNumber returns 'num' with digits/precision of 'v' for 'mt' and handles both Whole and Real numbers based on 'v'
207 func (mt *mt) FmtNumber(num float64, v uint64) string {
209 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
210 l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
213 b := make([]byte, 0, l)
215 for i := len(s) - 1; i >= 0; i-- {
218 b = append(b, mt.decimal[0])
225 b = append(b, mt.group[0])
236 b = append(b, mt.minus[0])
240 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
241 b[i], b[j] = b[j], b[i]
247 // FmtPercent returns 'num' with digits/precision of 'v' for 'mt' and handles both Whole and Real numbers based on 'v'
248 // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
249 func (mt *mt) FmtPercent(num float64, v uint64) string {
250 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
252 b := make([]byte, 0, l)
254 for i := len(s) - 1; i >= 0; i-- {
257 b = append(b, mt.decimal[0])
265 b = append(b, mt.minus[0])
269 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
270 b[i], b[j] = b[j], b[i]
273 b = append(b, mt.percent...)
278 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'mt'
279 func (mt *mt) FmtCurrency(num float64, v uint64, currency currency.Type) string {
281 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
282 symbol := mt.currencies[currency]
283 l := len(s) + len(symbol) + 2 + 1*len(s[:len(s)-int(v)-1])/3
286 b := make([]byte, 0, l)
288 for i := len(s) - 1; i >= 0; i-- {
291 b = append(b, mt.decimal[0])
298 b = append(b, mt.group[0])
308 for j := len(symbol) - 1; j >= 0; j-- {
309 b = append(b, symbol[j])
313 b = append(b, mt.minus[0])
317 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
318 b[i], b[j] = b[j], b[i]
324 b = append(b, mt.decimal...)
327 for i := 0; i < 2-int(v); i++ {
335 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'mt'
336 // in accounting notation.
337 func (mt *mt) FmtAccounting(num float64, v uint64, currency currency.Type) string {
339 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
340 symbol := mt.currencies[currency]
341 l := len(s) + len(symbol) + 2 + 1*len(s[:len(s)-int(v)-1])/3
344 b := make([]byte, 0, l)
346 for i := len(s) - 1; i >= 0; i-- {
349 b = append(b, mt.decimal[0])
356 b = append(b, mt.group[0])
368 for j := len(symbol) - 1; j >= 0; j-- {
369 b = append(b, symbol[j])
372 b = append(b, mt.minus[0])
376 for j := len(symbol) - 1; j >= 0; j-- {
377 b = append(b, symbol[j])
383 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
384 b[i], b[j] = b[j], b[i]
390 b = append(b, mt.decimal...)
393 for i := 0; i < 2-int(v); i++ {
401 // FmtDateShort returns the short date representation of 't' for 'mt'
402 func (mt *mt) FmtDateShort(t time.Time) string {
404 b := make([]byte, 0, 32)
410 b = strconv.AppendInt(b, int64(t.Day()), 10)
411 b = append(b, []byte{0x2f}...)
417 b = strconv.AppendInt(b, int64(t.Month()), 10)
419 b = append(b, []byte{0x2f}...)
422 b = strconv.AppendInt(b, int64(t.Year()), 10)
424 b = strconv.AppendInt(b, int64(-t.Year()), 10)
430 // FmtDateMedium returns the medium date representation of 't' for 'mt'
431 func (mt *mt) FmtDateMedium(t time.Time) string {
433 b := make([]byte, 0, 32)
439 b = strconv.AppendInt(b, int64(t.Day()), 10)
440 b = append(b, []byte{0x20}...)
441 b = append(b, mt.monthsAbbreviated[t.Month()]...)
442 b = append(b, []byte{0x20}...)
445 b = strconv.AppendInt(b, int64(t.Year()), 10)
447 b = strconv.AppendInt(b, int64(-t.Year()), 10)
453 // FmtDateLong returns the long date representation of 't' for 'mt'
454 func (mt *mt) FmtDateLong(t time.Time) string {
456 b := make([]byte, 0, 32)
458 b = strconv.AppendInt(b, int64(t.Day()), 10)
459 b = append(b, []byte{0x20, 0x74, 0x61}...)
460 b = append(b, []byte{0xe2, 0x80, 0x99, 0x20}...)
461 b = append(b, mt.monthsWide[t.Month()]...)
462 b = append(b, []byte{0x20}...)
465 b = strconv.AppendInt(b, int64(t.Year()), 10)
467 b = strconv.AppendInt(b, int64(-t.Year()), 10)
473 // FmtDateFull returns the full date representation of 't' for 'mt'
474 func (mt *mt) FmtDateFull(t time.Time) string {
476 b := make([]byte, 0, 32)
478 b = append(b, mt.daysWide[t.Weekday()]...)
479 b = append(b, []byte{0x2c, 0x20}...)
480 b = strconv.AppendInt(b, int64(t.Day()), 10)
481 b = append(b, []byte{0x20, 0x74, 0x61}...)
482 b = append(b, []byte{0xe2, 0x80, 0x99, 0x20}...)
483 b = append(b, mt.monthsWide[t.Month()]...)
484 b = append(b, []byte{0x20}...)
487 b = strconv.AppendInt(b, int64(t.Year()), 10)
489 b = strconv.AppendInt(b, int64(-t.Year()), 10)
495 // FmtTimeShort returns the short time representation of 't' for 'mt'
496 func (mt *mt) FmtTimeShort(t time.Time) string {
498 b := make([]byte, 0, 32)
504 b = strconv.AppendInt(b, int64(t.Hour()), 10)
505 b = append(b, mt.timeSeparator...)
511 b = strconv.AppendInt(b, int64(t.Minute()), 10)
516 // FmtTimeMedium returns the medium time representation of 't' for 'mt'
517 func (mt *mt) FmtTimeMedium(t time.Time) string {
519 b := make([]byte, 0, 32)
525 b = strconv.AppendInt(b, int64(t.Hour()), 10)
526 b = append(b, mt.timeSeparator...)
532 b = strconv.AppendInt(b, int64(t.Minute()), 10)
533 b = append(b, mt.timeSeparator...)
539 b = strconv.AppendInt(b, int64(t.Second()), 10)
544 // FmtTimeLong returns the long time representation of 't' for 'mt'
545 func (mt *mt) FmtTimeLong(t time.Time) string {
547 b := make([]byte, 0, 32)
553 b = strconv.AppendInt(b, int64(t.Hour()), 10)
554 b = append(b, mt.timeSeparator...)
560 b = strconv.AppendInt(b, int64(t.Minute()), 10)
561 b = append(b, mt.timeSeparator...)
567 b = strconv.AppendInt(b, int64(t.Second()), 10)
568 b = append(b, []byte{0x20}...)
576 // FmtTimeFull returns the full time representation of 't' for 'mt'
577 func (mt *mt) FmtTimeFull(t time.Time) string {
579 b := make([]byte, 0, 32)
585 b = strconv.AppendInt(b, int64(t.Hour()), 10)
586 b = append(b, mt.timeSeparator...)
592 b = strconv.AppendInt(b, int64(t.Minute()), 10)
593 b = append(b, mt.timeSeparator...)
599 b = strconv.AppendInt(b, int64(t.Second()), 10)
600 b = append(b, []byte{0x20}...)
604 if btz, ok := mt.timezones[tz]; ok {
605 b = append(b, btz...)