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 'to_TO' locale
45 func New() locales.Translator {
48 pluralsCardinal: []locales.PluralRule{6},
58 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", "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"},
59 currencyPositivePrefix: " ",
60 currencyNegativePrefix: " ",
61 monthsAbbreviated: []string{"", "Sān", "Fēp", "Maʻa", "ʻEpe", "Mē", "Sun", "Siu", "ʻAok", "Sep", "ʻOka", "Nōv", "Tīs"},
62 monthsNarrow: []string{"", "S", "F", "M", "E", "M", "S", "S", "A", "S", "O", "N", "T"},
63 monthsWide: []string{"", "Sānuali", "Fēpueli", "Maʻasi", "ʻEpeleli", "Mē", "Sune", "Siulai", "ʻAokosi", "Sepitema", "ʻOkatopa", "Nōvema", "Tīsema"},
64 daysAbbreviated: []string{"Sāp", "Mōn", "Tūs", "Pul", "Tuʻa", "Fal", "Tok"},
65 daysNarrow: []string{"S", "M", "T", "P", "T", "F", "T"},
66 daysShort: []string{"Sāp", "Mōn", "Tūs", "Pul", "Tuʻa", "Fal", "Tok"},
67 daysWide: []string{"Sāpate", "Mōnite", "Tūsite", "Pulelulu", "Tuʻapulelulu", "Falaite", "Tokonaki"},
68 periodsAbbreviated: []string{"AM", "PM"},
69 periodsNarrow: []string{"AM", "PM"},
70 periodsWide: []string{"hengihengi", "efiafi"},
71 erasAbbreviated: []string{"KM", "TS"},
72 erasNarrow: []string{"", ""},
73 erasWide: []string{"ki muʻa", "taʻu ʻo Sīsū"},
74 timezones: map[string]string{"VET": "houa fakavenesuela", "EAT": "houa fakaʻafelika-hahake", "HAT": "houa fakafonuaʻilofoʻou taimi liliu", "HEPM": "houa fakasā-piea-mo-mikeloni taimi liliu", "OESZ": "houa fakaʻeulope-hahake taimi liliu", "MYT": "houa fakamaleisia", "AKDT": "houa fakaʻalasika taimi liliu", "ACST": "houa fakaʻaositelēlia-loto taimi totonu", "ACDT": "houa fakaʻaositelēlia-loto taimi liliu", "HECU": "houa fakakiupa taimi liliu", "BOT": "houa fakapolīvia", "AWDT": "houa fakaʻaositelēlia-hihifo taimi liliu", "HADT": "houa fakahauaʻi taimi liliu", "NZDT": "houa fakanuʻusila taimi liliu", "WARST": "houa fakaʻasenitina-hihifo taimi liliu", "ADT": "houa fakaʻamelika-tokelau ʻatalanitiki taimi liliu", "CLT": "houa fakasili taimi totonu", "GFT": "houa fakakuiana-fakafalanisē", "AKST": "houa fakaʻalasika taimi totonu", "MEZ": "houa fakaʻeulope-loto taimi totonu", "HNOG": "houa fakafonuamata-hihifo taimi totonu", "HNEG": "houa fakafonuamata-hahake taimi totonu", "GYT": "houa fakakuiana", "PDT": "houa fakaʻamelika-tokelau pasifika taimi liliu", "HNCU": "houa fakakiupa taimi totonu", "JST": "houa fakasiapani taimi totonu", "COT": "houa fakakolomipia taimi totonu", "EST": "houa fakaʻamelika-tokelau hahake taimi totonu", "TMT": "houa fakatūkimenisitani taimi totonu", "AST": "houa fakaʻamelika-tokelau ʻatalanitiki taimi totonu", "HAST": "houa fakahauaʻi taimi totonu", "TMST": "houa fakatūkimenisitani taimi liliu", "LHST": "houa fakamotuʻeikihoue taimi totonu", "AEDT": "houa fakaʻaositelēlia-hahake taimi liliu", "ChST": "houa fakakamolo", "HNPMX": "houa fakamekisikou-pasifika taimi totonu", "ACWDT": "houa fakaʻaositelēlia-loto-hihifo taimi liliu", "MESZ": "houa fakaʻeulope-loto taimi liliu", "NZST": "houa fakanuʻusila taimi totonu", "WART": "houa fakaʻasenitina-hihifo taimi totonu", "JDT": "houa fakasiapani taimi liliu", "SAST": "houa fakaʻafelika-tonga", "EDT": "houa fakaʻamelika-tokelau hahake taimi liliu", "HEPMX": "houa fakamekisikou-pasifika taimi liliu", "CST": "houa fakaʻamelika-tokelau loto taimi totonu", "ARST": "houa fakaʻasenitina taimi liliu", "CHADT": "houa fakasatihami taimi liliu", "AWST": "houa fakaʻaositelēlia-hihifo taimi totonu", "MST": "houa fakamakau taimi totonu", "∅∅∅": "houa fakaʻakelī taimi liliu", "UYT": "houa fakaʻulukuai taimi totonu", "WAST": "houa fakaʻafelika-hihifo taimi liliu", "GMT": "houa fakakiliniuisi mālie", "BT": "houa fakapūtani", "CDT": "houa fakaʻamelika-tokelau loto taimi liliu", "ART": "houa fakaʻasenitina taimi totonu", "WAT": "houa fakaʻafelika-hihifo taimi totonu", "HNT": "houa fakafonuaʻilofoʻou taimi totonu", "CHAST": "houa fakasatihami taimi totonu", "SRT": "houa fakasuliname", "SGT": "houa fakasingapoa", "PST": "houa fakaʻamelika-tokelau pasifika taimi totonu", "HENOMX": "houa fakamekisikou-tokelauhihifo taimi liliu", "UYST": "houa fakaʻulukuai taimi liliu", "WIT": "houa fakaʻinitonisia-hahake", "LHDT": "houa fakamotuʻeikihoue taimi liliu", "IST": "houa fakaʻinitia", "AEST": "houa fakaʻaositelēlia-hahake taimi totonu", "HEOG": "houa fakafonuamata-hihifo taimi liliu", "HKT": "houa fakahongi-kongi taimi totonu", "MDT": "houa fakamakau taimi liliu", "ECT": "houa fakaʻekuetoa", "CLST": "houa fakasili taimi liliu", "HKST": "houa fakahongi-kongi taimi liliu", "COST": "houa fakakolomipia taimi liliu", "WESZ": "houa fakaʻeulope-hihifo taimi liliu", "HNPM": "houa fakasā-piea-mo-mikeloni taimi totonu", "HNNOMX": "houa fakamekisikou-tokelauhihifo taimi totonu", "WIB": "houa fakaʻinitonisia-hihifo", "WEZ": "houa fakaʻeulope-hihifo taimi totonu", "OEZ": "houa fakaʻeulope-hahake taimi totonu", "WITA": "houa fakaʻinitonisia-loto", "HEEG": "houa fakafonuamata-hahake taimi liliu", "CAT": "houa fakaʻafelika-loto", "ACWST": "houa fakaʻaositelēlia-loto-hihifo taimi totonu"},
78 // Locale returns the current translators string locale
79 func (to *to_TO) Locale() string {
83 // PluralsCardinal returns the list of cardinal plural rules associated with 'to_TO'
84 func (to *to_TO) PluralsCardinal() []locales.PluralRule {
85 return to.pluralsCardinal
88 // PluralsOrdinal returns the list of ordinal plural rules associated with 'to_TO'
89 func (to *to_TO) PluralsOrdinal() []locales.PluralRule {
90 return to.pluralsOrdinal
93 // PluralsRange returns the list of range plural rules associated with 'to_TO'
94 func (to *to_TO) PluralsRange() []locales.PluralRule {
95 return to.pluralsRange
98 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'to_TO'
99 func (to *to_TO) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
100 return locales.PluralRuleOther
103 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'to_TO'
104 func (to *to_TO) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
105 return locales.PluralRuleUnknown
108 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'to_TO'
109 func (to *to_TO) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
110 return locales.PluralRuleUnknown
113 // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
114 func (to *to_TO) MonthAbbreviated(month time.Month) string {
115 return to.monthsAbbreviated[month]
118 // MonthsAbbreviated returns the locales abbreviated months
119 func (to *to_TO) MonthsAbbreviated() []string {
120 return to.monthsAbbreviated[1:]
123 // MonthNarrow returns the locales narrow month given the 'month' provided
124 func (to *to_TO) MonthNarrow(month time.Month) string {
125 return to.monthsNarrow[month]
128 // MonthsNarrow returns the locales narrow months
129 func (to *to_TO) MonthsNarrow() []string {
130 return to.monthsNarrow[1:]
133 // MonthWide returns the locales wide month given the 'month' provided
134 func (to *to_TO) MonthWide(month time.Month) string {
135 return to.monthsWide[month]
138 // MonthsWide returns the locales wide months
139 func (to *to_TO) MonthsWide() []string {
140 return to.monthsWide[1:]
143 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
144 func (to *to_TO) WeekdayAbbreviated(weekday time.Weekday) string {
145 return to.daysAbbreviated[weekday]
148 // WeekdaysAbbreviated returns the locales abbreviated weekdays
149 func (to *to_TO) WeekdaysAbbreviated() []string {
150 return to.daysAbbreviated
153 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
154 func (to *to_TO) WeekdayNarrow(weekday time.Weekday) string {
155 return to.daysNarrow[weekday]
158 // WeekdaysNarrow returns the locales narrow weekdays
159 func (to *to_TO) WeekdaysNarrow() []string {
163 // WeekdayShort returns the locales short weekday given the 'weekday' provided
164 func (to *to_TO) WeekdayShort(weekday time.Weekday) string {
165 return to.daysShort[weekday]
168 // WeekdaysShort returns the locales short weekdays
169 func (to *to_TO) WeekdaysShort() []string {
173 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
174 func (to *to_TO) WeekdayWide(weekday time.Weekday) string {
175 return to.daysWide[weekday]
178 // WeekdaysWide returns the locales wide weekdays
179 func (to *to_TO) WeekdaysWide() []string {
183 // Decimal returns the decimal point of number
184 func (to *to_TO) Decimal() string {
188 // Group returns the group of number
189 func (to *to_TO) Group() string {
193 // Group returns the minus sign of number
194 func (to *to_TO) Minus() string {
198 // FmtNumber returns 'num' with digits/precision of 'v' for 'to_TO' and handles both Whole and Real numbers based on 'v'
199 func (to *to_TO) FmtNumber(num float64, v uint64) string {
201 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
202 l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
205 b := make([]byte, 0, l)
207 for i := len(s) - 1; i >= 0; i-- {
210 b = append(b, to.decimal[0])
217 b = append(b, to.group[0])
228 b = append(b, to.minus[0])
232 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
233 b[i], b[j] = b[j], b[i]
239 // FmtPercent returns 'num' with digits/precision of 'v' for 'to_TO' and handles both Whole and Real numbers based on 'v'
240 // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
241 func (to *to_TO) FmtPercent(num float64, v uint64) string {
242 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
244 b := make([]byte, 0, l)
246 for i := len(s) - 1; i >= 0; i-- {
249 b = append(b, to.decimal[0])
257 b = append(b, to.minus[0])
261 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
262 b[i], b[j] = b[j], b[i]
265 b = append(b, to.percent...)
270 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'to_TO'
271 func (to *to_TO) FmtCurrency(num float64, v uint64, currency currency.Type) string {
273 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
274 symbol := to.currencies[currency]
275 l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
278 b := make([]byte, 0, l)
280 for i := len(s) - 1; i >= 0; i-- {
283 b = append(b, to.decimal[0])
290 b = append(b, to.group[0])
300 for j := len(symbol) - 1; j >= 0; j-- {
301 b = append(b, symbol[j])
304 for j := len(to.currencyPositivePrefix) - 1; j >= 0; j-- {
305 b = append(b, to.currencyPositivePrefix[j])
309 b = append(b, to.minus[0])
313 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
314 b[i], b[j] = b[j], b[i]
320 b = append(b, to.decimal...)
323 for i := 0; i < 2-int(v); i++ {
331 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'to_TO'
332 // in accounting notation.
333 func (to *to_TO) FmtAccounting(num float64, v uint64, currency currency.Type) string {
335 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
336 symbol := to.currencies[currency]
337 l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
340 b := make([]byte, 0, l)
342 for i := len(s) - 1; i >= 0; i-- {
345 b = append(b, to.decimal[0])
352 b = append(b, to.group[0])
364 for j := len(symbol) - 1; j >= 0; j-- {
365 b = append(b, symbol[j])
368 for j := len(to.currencyNegativePrefix) - 1; j >= 0; j-- {
369 b = append(b, to.currencyNegativePrefix[j])
372 b = append(b, to.minus[0])
376 for j := len(symbol) - 1; j >= 0; j-- {
377 b = append(b, symbol[j])
380 for j := len(to.currencyPositivePrefix) - 1; j >= 0; j-- {
381 b = append(b, to.currencyPositivePrefix[j])
387 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
388 b[i], b[j] = b[j], b[i]
394 b = append(b, to.decimal...)
397 for i := 0; i < 2-int(v); i++ {
405 // FmtDateShort returns the short date representation of 't' for 'to_TO'
406 func (to *to_TO) FmtDateShort(t time.Time) string {
408 b := make([]byte, 0, 32)
410 b = strconv.AppendInt(b, int64(t.Day()), 10)
411 b = append(b, []byte{0x2f}...)
412 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 'to_TO'
425 func (to *to_TO) FmtDateMedium(t time.Time) string {
427 b := make([]byte, 0, 32)
429 b = strconv.AppendInt(b, int64(t.Day()), 10)
430 b = append(b, []byte{0x20}...)
431 b = append(b, to.monthsAbbreviated[t.Month()]...)
432 b = append(b, []byte{0x20}...)
435 b = strconv.AppendInt(b, int64(t.Year()), 10)
437 b = strconv.AppendInt(b, int64(-t.Year()), 10)
443 // FmtDateLong returns the long date representation of 't' for 'to_TO'
444 func (to *to_TO) FmtDateLong(t time.Time) string {
446 b := make([]byte, 0, 32)
448 b = strconv.AppendInt(b, int64(t.Day()), 10)
449 b = append(b, []byte{0x20}...)
450 b = append(b, to.monthsWide[t.Month()]...)
451 b = append(b, []byte{0x20}...)
454 b = strconv.AppendInt(b, int64(t.Year()), 10)
456 b = strconv.AppendInt(b, int64(-t.Year()), 10)
462 // FmtDateFull returns the full date representation of 't' for 'to_TO'
463 func (to *to_TO) FmtDateFull(t time.Time) string {
465 b := make([]byte, 0, 32)
467 b = append(b, to.daysWide[t.Weekday()]...)
468 b = append(b, []byte{0x20}...)
469 b = strconv.AppendInt(b, int64(t.Day()), 10)
470 b = append(b, []byte{0x20}...)
471 b = append(b, to.monthsWide[t.Month()]...)
472 b = append(b, []byte{0x20}...)
475 b = strconv.AppendInt(b, int64(t.Year()), 10)
477 b = strconv.AppendInt(b, int64(-t.Year()), 10)
483 // FmtTimeShort returns the short time representation of 't' for 'to_TO'
484 func (to *to_TO) FmtTimeShort(t time.Time) string {
486 b := make([]byte, 0, 32)
494 b = strconv.AppendInt(b, int64(h), 10)
495 b = append(b, to.timeSeparator...)
501 b = strconv.AppendInt(b, int64(t.Minute()), 10)
502 b = append(b, []byte{0x20}...)
505 b = append(b, to.periodsAbbreviated[0]...)
507 b = append(b, to.periodsAbbreviated[1]...)
513 // FmtTimeMedium returns the medium time representation of 't' for 'to_TO'
514 func (to *to_TO) FmtTimeMedium(t time.Time) string {
516 b := make([]byte, 0, 32)
524 b = strconv.AppendInt(b, int64(h), 10)
525 b = append(b, to.timeSeparator...)
531 b = strconv.AppendInt(b, int64(t.Minute()), 10)
532 b = append(b, to.timeSeparator...)
538 b = strconv.AppendInt(b, int64(t.Second()), 10)
539 b = append(b, []byte{0x20}...)
542 b = append(b, to.periodsAbbreviated[0]...)
544 b = append(b, to.periodsAbbreviated[1]...)
550 // FmtTimeLong returns the long time representation of 't' for 'to_TO'
551 func (to *to_TO) FmtTimeLong(t time.Time) string {
553 b := make([]byte, 0, 32)
561 b = strconv.AppendInt(b, int64(h), 10)
562 b = append(b, to.timeSeparator...)
568 b = strconv.AppendInt(b, int64(t.Minute()), 10)
569 b = append(b, to.timeSeparator...)
575 b = strconv.AppendInt(b, int64(t.Second()), 10)
576 b = append(b, []byte{0x20}...)
579 b = append(b, to.periodsAbbreviated[0]...)
581 b = append(b, to.periodsAbbreviated[1]...)
584 b = append(b, []byte{0x20}...)
592 // FmtTimeFull returns the full time representation of 't' for 'to_TO'
593 func (to *to_TO) FmtTimeFull(t time.Time) string {
595 b := make([]byte, 0, 32)
603 b = strconv.AppendInt(b, int64(h), 10)
604 b = append(b, to.timeSeparator...)
610 b = strconv.AppendInt(b, int64(t.Minute()), 10)
611 b = append(b, to.timeSeparator...)
617 b = strconv.AppendInt(b, int64(t.Second()), 10)
618 b = append(b, []byte{0x20}...)
621 b = append(b, to.periodsAbbreviated[0]...)
623 b = append(b, to.periodsAbbreviated[1]...)
626 b = append(b, []byte{0x20}...)
630 if btz, ok := to.timezones[tz]; ok {
631 b = append(b, btz...)