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 'agq' locale
43 func New() locales.Translator {
52 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"},
53 monthsAbbreviated: []string{"", "nùm", "kɨz", "tɨd", "taa", "see", "nzu", "dum", "fɔe", "dzu", "lɔm", "kaa", "fwo"},
54 monthsNarrow: []string{"", "n", "k", "t", "t", "s", "z", "k", "f", "d", "l", "c", "f"},
55 monthsWide: []string{"", "ndzɔ̀ŋɔ̀nùm", "ndzɔ̀ŋɔ̀kƗ̀zùʔ", "ndzɔ̀ŋɔ̀tƗ̀dʉ̀ghà", "ndzɔ̀ŋɔ̀tǎafʉ̄ghā", "ndzɔ̀ŋèsèe", "ndzɔ̀ŋɔ̀nzùghò", "ndzɔ̀ŋɔ̀dùmlo", "ndzɔ̀ŋɔ̀kwîfɔ̀e", "ndzɔ̀ŋɔ̀tƗ̀fʉ̀ghàdzughù", "ndzɔ̀ŋɔ̀ghǔuwelɔ̀m", "ndzɔ̀ŋɔ̀chwaʔàkaa wo", "ndzɔ̀ŋèfwòo"},
56 daysAbbreviated: []string{"nts", "kpa", "ghɔ", "tɔm", "ume", "ghɨ", "dzk"},
57 daysNarrow: []string{"n", "k", "g", "t", "u", "g", "d"},
58 daysWide: []string{"tsuʔntsɨ", "tsuʔukpà", "tsuʔughɔe", "tsuʔutɔ̀mlò", "tsuʔumè", "tsuʔughɨ̂m", "tsuʔndzɨkɔʔɔ"},
59 periodsAbbreviated: []string{"a.g", "a.k"},
60 periodsWide: []string{"a.g", "a.k"},
61 erasAbbreviated: []string{"SK", "BK"},
62 erasNarrow: []string{"", ""},
63 erasWide: []string{"Sěe Kɨ̀lesto", "Bǎa Kɨ̀lesto"},
64 timezones: map[string]string{"SAST": "SAST", "HNEG": "HNEG", "NZST": "NZST", "VET": "VET", "HNCU": "HNCU", "BT": "BT", "TMT": "TMT", "HENOMX": "HENOMX", "AST": "AST", "HNT": "HNT", "CLT": "CLT", "HNPMX": "HNPMX", "HECU": "HECU", "AEDT": "AEDT", "ART": "ART", "GYT": "GYT", "ACST": "ACST", "UYT": "UYT", "WIT": "WIT", "WITA": "WITA", "JDT": "JDT", "LHDT": "LHDT", "HEEG": "HEEG", "EDT": "EDT", "PDT": "PDT", "MESZ": "MESZ", "HADT": "HADT", "JST": "JST", "SGT": "SGT", "CDT": "CDT", "ARST": "ARST", "HNOG": "HNOG", "AKDT": "AKDT", "WARST": "WARST", "CHADT": "CHADT", "MYT": "MYT", "WAST": "WAST", "HAT": "HAT", "GFT": "GFT", "AWST": "AWST", "SRT": "SRT", "WIB": "WIB", "MST": "MST", "ADT": "ADT", "CAT": "CAT", "ACWDT": "ACWDT", "HNPM": "HNPM", "BOT": "BOT", "UYST": "UYST", "HAST": "HAST", "OEZ": "OEZ", "HNNOMX": "HNNOMX", "HKT": "HKT", "COST": "COST", "IST": "IST", "EAT": "EAT", "WAT": "WAT", "WESZ": "WESZ", "WART": "WART", "TMST": "TMST", "HEOG": "HEOG", "ACWST": "ACWST", "NZDT": "NZDT", "ChST": "ChST", "LHST": "LHST", "WEZ": "WEZ", "GMT": "GMT", "EST": "EST", "ACDT": "ACDT", "ECT": "ECT", "∅∅∅": "∅∅∅", "HEPMX": "HEPMX", "AWDT": "AWDT", "HKST": "HKST", "CLST": "CLST", "OESZ": "OESZ", "AEST": "AEST", "PST": "PST", "CHAST": "CHAST", "HEPM": "HEPM", "CST": "CST", "MDT": "MDT", "MEZ": "MEZ", "COT": "COT", "AKST": "AKST"},
68 // Locale returns the current translators string locale
69 func (agq *agq) Locale() string {
73 // PluralsCardinal returns the list of cardinal plural rules associated with 'agq'
74 func (agq *agq) PluralsCardinal() []locales.PluralRule {
75 return agq.pluralsCardinal
78 // PluralsOrdinal returns the list of ordinal plural rules associated with 'agq'
79 func (agq *agq) PluralsOrdinal() []locales.PluralRule {
80 return agq.pluralsOrdinal
83 // PluralsRange returns the list of range plural rules associated with 'agq'
84 func (agq *agq) PluralsRange() []locales.PluralRule {
85 return agq.pluralsRange
88 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'agq'
89 func (agq *agq) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
90 return locales.PluralRuleUnknown
93 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'agq'
94 func (agq *agq) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
95 return locales.PluralRuleUnknown
98 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'agq'
99 func (agq *agq) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
100 return locales.PluralRuleUnknown
103 // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
104 func (agq *agq) MonthAbbreviated(month time.Month) string {
105 return agq.monthsAbbreviated[month]
108 // MonthsAbbreviated returns the locales abbreviated months
109 func (agq *agq) MonthsAbbreviated() []string {
110 return agq.monthsAbbreviated[1:]
113 // MonthNarrow returns the locales narrow month given the 'month' provided
114 func (agq *agq) MonthNarrow(month time.Month) string {
115 return agq.monthsNarrow[month]
118 // MonthsNarrow returns the locales narrow months
119 func (agq *agq) MonthsNarrow() []string {
120 return agq.monthsNarrow[1:]
123 // MonthWide returns the locales wide month given the 'month' provided
124 func (agq *agq) MonthWide(month time.Month) string {
125 return agq.monthsWide[month]
128 // MonthsWide returns the locales wide months
129 func (agq *agq) MonthsWide() []string {
130 return agq.monthsWide[1:]
133 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
134 func (agq *agq) WeekdayAbbreviated(weekday time.Weekday) string {
135 return agq.daysAbbreviated[weekday]
138 // WeekdaysAbbreviated returns the locales abbreviated weekdays
139 func (agq *agq) WeekdaysAbbreviated() []string {
140 return agq.daysAbbreviated
143 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
144 func (agq *agq) WeekdayNarrow(weekday time.Weekday) string {
145 return agq.daysNarrow[weekday]
148 // WeekdaysNarrow returns the locales narrow weekdays
149 func (agq *agq) WeekdaysNarrow() []string {
150 return agq.daysNarrow
153 // WeekdayShort returns the locales short weekday given the 'weekday' provided
154 func (agq *agq) WeekdayShort(weekday time.Weekday) string {
155 return agq.daysShort[weekday]
158 // WeekdaysShort returns the locales short weekdays
159 func (agq *agq) WeekdaysShort() []string {
163 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
164 func (agq *agq) WeekdayWide(weekday time.Weekday) string {
165 return agq.daysWide[weekday]
168 // WeekdaysWide returns the locales wide weekdays
169 func (agq *agq) WeekdaysWide() []string {
173 // Decimal returns the decimal point of number
174 func (agq *agq) Decimal() string {
178 // Group returns the group of number
179 func (agq *agq) Group() string {
183 // Group returns the minus sign of number
184 func (agq *agq) Minus() string {
188 // FmtNumber returns 'num' with digits/precision of 'v' for 'agq' and handles both Whole and Real numbers based on 'v'
189 func (agq *agq) FmtNumber(num float64, v uint64) string {
191 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
192 l := len(s) + 1 + 2*len(s[:len(s)-int(v)-1])/3
195 b := make([]byte, 0, l)
197 for i := len(s) - 1; i >= 0; i-- {
200 b = append(b, agq.decimal[0])
207 for j := len(agq.group) - 1; j >= 0; j-- {
208 b = append(b, agq.group[j])
220 b = append(b, agq.minus[0])
224 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
225 b[i], b[j] = b[j], b[i]
231 // FmtPercent returns 'num' with digits/precision of 'v' for 'agq' and handles both Whole and Real numbers based on 'v'
232 // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
233 func (agq *agq) FmtPercent(num float64, v uint64) string {
234 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
236 b := make([]byte, 0, l)
238 for i := len(s) - 1; i >= 0; i-- {
241 b = append(b, agq.decimal[0])
249 b = append(b, agq.minus[0])
253 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
254 b[i], b[j] = b[j], b[i]
257 b = append(b, agq.percent...)
262 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'agq'
263 func (agq *agq) FmtCurrency(num float64, v uint64, currency currency.Type) string {
265 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
266 symbol := agq.currencies[currency]
267 l := len(s) + len(symbol) + 1 + 2*len(s[:len(s)-int(v)-1])/3
270 b := make([]byte, 0, l)
272 for i := len(s) - 1; i >= 0; i-- {
275 b = append(b, agq.decimal[0])
282 for j := len(agq.group) - 1; j >= 0; j-- {
283 b = append(b, agq.group[j])
295 b = append(b, agq.minus[0])
299 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
300 b[i], b[j] = b[j], b[i]
306 b = append(b, agq.decimal...)
309 for i := 0; i < 2-int(v); i++ {
314 b = append(b, symbol...)
319 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'agq'
320 // in accounting notation.
321 func (agq *agq) FmtAccounting(num float64, v uint64, currency currency.Type) string {
323 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
324 symbol := agq.currencies[currency]
325 l := len(s) + len(symbol) + 1 + 2*len(s[:len(s)-int(v)-1])/3
328 b := make([]byte, 0, l)
330 for i := len(s) - 1; i >= 0; i-- {
333 b = append(b, agq.decimal[0])
340 for j := len(agq.group) - 1; j >= 0; j-- {
341 b = append(b, agq.group[j])
354 b = append(b, agq.minus[0])
359 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
360 b[i], b[j] = b[j], b[i]
366 b = append(b, agq.decimal...)
369 for i := 0; i < 2-int(v); i++ {
375 b = append(b, symbol...)
378 b = append(b, symbol...)
384 // FmtDateShort returns the short date representation of 't' for 'agq'
385 func (agq *agq) FmtDateShort(t time.Time) string {
387 b := make([]byte, 0, 32)
389 b = strconv.AppendInt(b, int64(t.Day()), 10)
390 b = append(b, []byte{0x2f}...)
391 b = strconv.AppendInt(b, int64(t.Month()), 10)
392 b = append(b, []byte{0x2f}...)
395 b = strconv.AppendInt(b, int64(t.Year()), 10)
397 b = strconv.AppendInt(b, int64(-t.Year()), 10)
403 // FmtDateMedium returns the medium date representation of 't' for 'agq'
404 func (agq *agq) FmtDateMedium(t time.Time) string {
406 b := make([]byte, 0, 32)
408 b = strconv.AppendInt(b, int64(t.Day()), 10)
409 b = append(b, []byte{0x20}...)
410 b = append(b, agq.monthsAbbreviated[t.Month()]...)
411 b = append(b, []byte{0x2c, 0x20}...)
414 b = strconv.AppendInt(b, int64(t.Year()), 10)
416 b = strconv.AppendInt(b, int64(-t.Year()), 10)
422 // FmtDateLong returns the long date representation of 't' for 'agq'
423 func (agq *agq) FmtDateLong(t time.Time) string {
425 b := make([]byte, 0, 32)
427 b = strconv.AppendInt(b, int64(t.Day()), 10)
428 b = append(b, []byte{0x20}...)
429 b = append(b, agq.monthsWide[t.Month()]...)
430 b = append(b, []byte{0x20}...)
433 b = strconv.AppendInt(b, int64(t.Year()), 10)
435 b = strconv.AppendInt(b, int64(-t.Year()), 10)
441 // FmtDateFull returns the full date representation of 't' for 'agq'
442 func (agq *agq) FmtDateFull(t time.Time) string {
444 b := make([]byte, 0, 32)
446 b = append(b, agq.daysWide[t.Weekday()]...)
447 b = append(b, []byte{0x20}...)
448 b = strconv.AppendInt(b, int64(t.Day()), 10)
449 b = append(b, []byte{0x20}...)
450 b = append(b, agq.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 // FmtTimeShort returns the short time representation of 't' for 'agq'
463 func (agq *agq) FmtTimeShort(t time.Time) string {
465 b := make([]byte, 0, 32)
471 b = strconv.AppendInt(b, int64(t.Hour()), 10)
472 b = append(b, agq.timeSeparator...)
478 b = strconv.AppendInt(b, int64(t.Minute()), 10)
483 // FmtTimeMedium returns the medium time representation of 't' for 'agq'
484 func (agq *agq) FmtTimeMedium(t time.Time) string {
486 b := make([]byte, 0, 32)
492 b = strconv.AppendInt(b, int64(t.Hour()), 10)
493 b = append(b, agq.timeSeparator...)
499 b = strconv.AppendInt(b, int64(t.Minute()), 10)
500 b = append(b, agq.timeSeparator...)
506 b = strconv.AppendInt(b, int64(t.Second()), 10)
511 // FmtTimeLong returns the long time representation of 't' for 'agq'
512 func (agq *agq) FmtTimeLong(t time.Time) string {
514 b := make([]byte, 0, 32)
520 b = strconv.AppendInt(b, int64(t.Hour()), 10)
521 b = append(b, agq.timeSeparator...)
527 b = strconv.AppendInt(b, int64(t.Minute()), 10)
528 b = append(b, agq.timeSeparator...)
534 b = strconv.AppendInt(b, int64(t.Second()), 10)
535 b = append(b, []byte{0x20}...)
543 // FmtTimeFull returns the full time representation of 't' for 'agq'
544 func (agq *agq) FmtTimeFull(t time.Time) string {
546 b := make([]byte, 0, 32)
552 b = strconv.AppendInt(b, int64(t.Hour()), 10)
553 b = append(b, agq.timeSeparator...)
559 b = strconv.AppendInt(b, int64(t.Minute()), 10)
560 b = append(b, agq.timeSeparator...)
566 b = strconv.AppendInt(b, int64(t.Second()), 10)
567 b = append(b, []byte{0x20}...)
571 if btz, ok := agq.timezones[tz]; ok {
572 b = append(b, btz...)