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
25 currencies []string // idx = enum of currency code
26 monthsAbbreviated []string
29 daysAbbreviated []string
33 periodsAbbreviated []string
34 periodsNarrow []string
37 erasAbbreviated []string
40 timezones map[string]string
43 // New returns a new instance of translator for the 'zgh' locale
44 func New() locales.Translator {
57 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 monthsAbbreviated: []string{"", "ⵉⵏⵏ", "ⴱⵕⴰ", "ⵎⴰⵕ", "ⵉⴱⵔ", "ⵎⴰⵢ", "ⵢⵓⵏ", "ⵢⵓⵍ", "ⵖⵓⵛ", "ⵛⵓⵜ", "ⴽⵜⵓ", "ⵏⵓⵡ", "ⴷⵓⵊ"},
60 monthsNarrow: []string{"", "ⵉ", "ⴱ", "ⵎ", "ⵉ", "ⵎ", "ⵢ", "ⵢ", "ⵖ", "ⵛ", "ⴽ", "ⵏ", "ⴷ"},
61 monthsWide: []string{"", "ⵉⵏⵏⴰⵢⵔ", "ⴱⵕⴰⵢⵕ", "ⵎⴰⵕⵚ", "ⵉⴱⵔⵉⵔ", "ⵎⴰⵢⵢⵓ", "ⵢⵓⵏⵢⵓ", "ⵢⵓⵍⵢⵓⵣ", "ⵖⵓⵛⵜ", "ⵛⵓⵜⴰⵏⴱⵉⵔ", "ⴽⵜⵓⴱⵔ", "ⵏⵓⵡⴰⵏⴱⵉⵔ", "ⴷⵓⵊⴰⵏⴱⵉⵔ"},
62 daysAbbreviated: []string{"ⴰⵙⴰ", "ⴰⵢⵏ", "ⴰⵙⵉ", "ⴰⴽⵕ", "ⴰⴽⵡ", "ⴰⵙⵉⵎ", "ⴰⵙⵉⴹ"},
63 daysNarrow: []string{"S", "M", "T", "W", "T", "F", "S"},
64 daysShort: []string{"ⴰⵙⴰ", "ⴰⵢⵏ", "ⴰⵙⵉ", "ⴰⴽⵕ", "ⴰⴽⵡ", "ⴰⵙⵉⵎ", "ⴰⵙⵉⴹ"},
65 daysWide: []string{"ⴰⵙⴰⵎⴰⵙ", "ⴰⵢⵏⴰⵙ", "ⴰⵙⵉⵏⴰⵙ", "ⴰⴽⵕⴰⵙ", "ⴰⴽⵡⴰⵙ", "ⴰⵙⵉⵎⵡⴰⵙ", "ⴰⵙⵉⴹⵢⴰⵙ"},
66 periodsAbbreviated: []string{"ⵜⵉⴼⴰⵡⵜ", "ⵜⴰⴷⴳⴳⵯⴰⵜ"},
67 periodsNarrow: []string{"ⵜⵉⴼⴰⵡⵜ", "ⵜⴰⴷⴳⴳⵯⴰⵜ"},
68 periodsWide: []string{"ⵜⵉⴼⴰⵡⵜ", "ⵜⴰⴷⴳⴳⵯⴰⵜ"},
69 erasAbbreviated: []string{"ⴷⴰⵄ", "ⴷⴼⵄ"},
70 erasNarrow: []string{"", ""},
71 erasWide: []string{"ⴷⴰⵜ ⵏ ⵄⵉⵙⴰ", "ⴷⴼⴼⵉⵔ ⵏ ⵄⵉⵙⴰ"},
72 timezones: map[string]string{"AEDT": "AEDT", "WAST": "WAST", "ACDT": "ACDT", "HNPM": "HNPM", "CHAST": "CHAST", "HNCU": "HNCU", "UYT": "UYT", "HENOMX": "HENOMX", "MDT": "MDT", "HKT": "HKT", "HKST": "HKST", "CAT": "CAT", "TMT": "TMT", "AWDT": "AWDT", "OESZ": "OESZ", "VET": "VET", "SAST": "SAST", "EST": "EST", "ECT": "ECT", "AEST": "AEST", "AKST": "AKST", "ChST": "ChST", "HEPMX": "HEPMX", "WIB": "WIB", "NZST": "NZST", "MST": "MST", "WARST": "WARST", "ADT": "ADT", "CLST": "CLST", "HNPMX": "HNPMX", "HECU": "HECU", "OEZ": "OEZ", "HNOG": "HNOG", "EAT": "EAT", "HEEG": "HEEG", "HAT": "HAT", "JST": "JST", "BT": "BT", "WIT": "WIT", "JDT": "JDT", "COST": "COST", "GFT": "GFT", "NZDT": "NZDT", "GMT": "GMT", "PST": "PST", "ACWST": "ACWST", "HAST": "HAST", "HADT": "HADT", "LHST": "LHST", "IST": "IST", "ARST": "ARST", "BOT": "BOT", "AWST": "AWST", "WESZ": "WESZ", "HEPM": "HEPM", "MESZ": "MESZ", "AST": "AST", "HEOG": "HEOG", "CLT": "CLT", "GYT": "GYT", "ACST": "ACST", "SRT": "SRT", "WART": "WART", "HNEG": "HNEG", "HNT": "HNT", "AKDT": "AKDT", "CST": "CST", "MYT": "MYT", "MEZ": "MEZ", "TMST": "TMST", "HNNOMX": "HNNOMX", "ART": "ART", "EDT": "EDT", "PDT": "PDT", "ACWDT": "ACWDT", "WITA": "WITA", "UYST": "UYST", "∅∅∅": "∅∅∅", "SGT": "SGT", "CDT": "CDT", "LHDT": "LHDT", "WAT": "WAT", "COT": "COT", "WEZ": "WEZ", "CHADT": "CHADT"},
76 // Locale returns the current translators string locale
77 func (zgh *zgh) Locale() string {
81 // PluralsCardinal returns the list of cardinal plural rules associated with 'zgh'
82 func (zgh *zgh) PluralsCardinal() []locales.PluralRule {
83 return zgh.pluralsCardinal
86 // PluralsOrdinal returns the list of ordinal plural rules associated with 'zgh'
87 func (zgh *zgh) PluralsOrdinal() []locales.PluralRule {
88 return zgh.pluralsOrdinal
91 // PluralsRange returns the list of range plural rules associated with 'zgh'
92 func (zgh *zgh) PluralsRange() []locales.PluralRule {
93 return zgh.pluralsRange
96 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'zgh'
97 func (zgh *zgh) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
98 return locales.PluralRuleUnknown
101 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'zgh'
102 func (zgh *zgh) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
103 return locales.PluralRuleUnknown
106 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'zgh'
107 func (zgh *zgh) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
108 return locales.PluralRuleUnknown
111 // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
112 func (zgh *zgh) MonthAbbreviated(month time.Month) string {
113 return zgh.monthsAbbreviated[month]
116 // MonthsAbbreviated returns the locales abbreviated months
117 func (zgh *zgh) MonthsAbbreviated() []string {
118 return zgh.monthsAbbreviated[1:]
121 // MonthNarrow returns the locales narrow month given the 'month' provided
122 func (zgh *zgh) MonthNarrow(month time.Month) string {
123 return zgh.monthsNarrow[month]
126 // MonthsNarrow returns the locales narrow months
127 func (zgh *zgh) MonthsNarrow() []string {
128 return zgh.monthsNarrow[1:]
131 // MonthWide returns the locales wide month given the 'month' provided
132 func (zgh *zgh) MonthWide(month time.Month) string {
133 return zgh.monthsWide[month]
136 // MonthsWide returns the locales wide months
137 func (zgh *zgh) MonthsWide() []string {
138 return zgh.monthsWide[1:]
141 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
142 func (zgh *zgh) WeekdayAbbreviated(weekday time.Weekday) string {
143 return zgh.daysAbbreviated[weekday]
146 // WeekdaysAbbreviated returns the locales abbreviated weekdays
147 func (zgh *zgh) WeekdaysAbbreviated() []string {
148 return zgh.daysAbbreviated
151 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
152 func (zgh *zgh) WeekdayNarrow(weekday time.Weekday) string {
153 return zgh.daysNarrow[weekday]
156 // WeekdaysNarrow returns the locales narrow weekdays
157 func (zgh *zgh) WeekdaysNarrow() []string {
158 return zgh.daysNarrow
161 // WeekdayShort returns the locales short weekday given the 'weekday' provided
162 func (zgh *zgh) WeekdayShort(weekday time.Weekday) string {
163 return zgh.daysShort[weekday]
166 // WeekdaysShort returns the locales short weekdays
167 func (zgh *zgh) WeekdaysShort() []string {
171 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
172 func (zgh *zgh) WeekdayWide(weekday time.Weekday) string {
173 return zgh.daysWide[weekday]
176 // WeekdaysWide returns the locales wide weekdays
177 func (zgh *zgh) WeekdaysWide() []string {
181 // Decimal returns the decimal point of number
182 func (zgh *zgh) Decimal() string {
186 // Group returns the group of number
187 func (zgh *zgh) Group() string {
191 // Group returns the minus sign of number
192 func (zgh *zgh) Minus() string {
196 // FmtNumber returns 'num' with digits/precision of 'v' for 'zgh' and handles both Whole and Real numbers based on 'v'
197 func (zgh *zgh) FmtNumber(num float64, v uint64) string {
199 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
200 l := len(s) + 2 + 2*len(s[:len(s)-int(v)-1])/3
203 b := make([]byte, 0, l)
205 for i := len(s) - 1; i >= 0; i-- {
208 b = append(b, zgh.decimal[0])
215 for j := len(zgh.group) - 1; j >= 0; j-- {
216 b = append(b, zgh.group[j])
228 b = append(b, zgh.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 'zgh' 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 (zgh *zgh) 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, zgh.decimal[0])
257 b = append(b, zgh.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, zgh.percentSuffix...)
267 b = append(b, zgh.percent...)
272 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'zgh'
273 func (zgh *zgh) FmtCurrency(num float64, v uint64, currency currency.Type) string {
275 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
276 symbol := zgh.currencies[currency]
277 l := len(s) + len(symbol) + 2 + 2*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, zgh.decimal[0])
292 for j := len(zgh.group) - 1; j >= 0; j-- {
293 b = append(b, zgh.group[j])
305 b = append(b, zgh.minus[0])
309 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
310 b[i], b[j] = b[j], b[i]
316 b = append(b, zgh.decimal...)
319 for i := 0; i < 2-int(v); i++ {
324 b = append(b, symbol...)
329 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'zgh'
330 // in accounting notation.
331 func (zgh *zgh) FmtAccounting(num float64, v uint64, currency currency.Type) string {
333 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
334 symbol := zgh.currencies[currency]
335 l := len(s) + len(symbol) + 2 + 2*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, zgh.decimal[0])
350 for j := len(zgh.group) - 1; j >= 0; j-- {
351 b = append(b, zgh.group[j])
364 b = append(b, zgh.minus[0])
369 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
370 b[i], b[j] = b[j], b[i]
376 b = append(b, zgh.decimal...)
379 for i := 0; i < 2-int(v); i++ {
385 b = append(b, symbol...)
388 b = append(b, symbol...)
394 // FmtDateShort returns the short date representation of 't' for 'zgh'
395 func (zgh *zgh) FmtDateShort(t time.Time) string {
397 b := make([]byte, 0, 32)
399 b = strconv.AppendInt(b, int64(t.Day()), 10)
400 b = append(b, []byte{0x2f}...)
401 b = strconv.AppendInt(b, int64(t.Month()), 10)
402 b = append(b, []byte{0x2f}...)
405 b = strconv.AppendInt(b, int64(t.Year()), 10)
407 b = strconv.AppendInt(b, int64(-t.Year()), 10)
413 // FmtDateMedium returns the medium date representation of 't' for 'zgh'
414 func (zgh *zgh) FmtDateMedium(t time.Time) string {
416 b := make([]byte, 0, 32)
418 b = strconv.AppendInt(b, int64(t.Day()), 10)
419 b = append(b, []byte{0x20}...)
420 b = append(b, zgh.monthsAbbreviated[t.Month()]...)
421 b = append(b, []byte{0x2c, 0x20}...)
424 b = strconv.AppendInt(b, int64(t.Year()), 10)
426 b = strconv.AppendInt(b, int64(-t.Year()), 10)
432 // FmtDateLong returns the long date representation of 't' for 'zgh'
433 func (zgh *zgh) FmtDateLong(t time.Time) string {
435 b := make([]byte, 0, 32)
437 b = strconv.AppendInt(b, int64(t.Day()), 10)
438 b = append(b, []byte{0x20}...)
439 b = append(b, zgh.monthsWide[t.Month()]...)
440 b = append(b, []byte{0x20}...)
443 b = strconv.AppendInt(b, int64(t.Year()), 10)
445 b = strconv.AppendInt(b, int64(-t.Year()), 10)
451 // FmtDateFull returns the full date representation of 't' for 'zgh'
452 func (zgh *zgh) FmtDateFull(t time.Time) string {
454 b := make([]byte, 0, 32)
456 b = append(b, zgh.daysWide[t.Weekday()]...)
457 b = append(b, []byte{0x20}...)
458 b = strconv.AppendInt(b, int64(t.Day()), 10)
459 b = append(b, []byte{0x20}...)
460 b = append(b, zgh.monthsWide[t.Month()]...)
461 b = append(b, []byte{0x20}...)
464 b = strconv.AppendInt(b, int64(t.Year()), 10)
466 b = strconv.AppendInt(b, int64(-t.Year()), 10)
472 // FmtTimeShort returns the short time representation of 't' for 'zgh'
473 func (zgh *zgh) FmtTimeShort(t time.Time) string {
475 b := make([]byte, 0, 32)
481 b = strconv.AppendInt(b, int64(t.Hour()), 10)
482 b = append(b, zgh.timeSeparator...)
488 b = strconv.AppendInt(b, int64(t.Minute()), 10)
493 // FmtTimeMedium returns the medium time representation of 't' for 'zgh'
494 func (zgh *zgh) FmtTimeMedium(t time.Time) string {
496 b := make([]byte, 0, 32)
502 b = strconv.AppendInt(b, int64(t.Hour()), 10)
503 b = append(b, zgh.timeSeparator...)
509 b = strconv.AppendInt(b, int64(t.Minute()), 10)
510 b = append(b, zgh.timeSeparator...)
516 b = strconv.AppendInt(b, int64(t.Second()), 10)
521 // FmtTimeLong returns the long time representation of 't' for 'zgh'
522 func (zgh *zgh) FmtTimeLong(t time.Time) string {
524 b := make([]byte, 0, 32)
530 b = strconv.AppendInt(b, int64(t.Hour()), 10)
531 b = append(b, zgh.timeSeparator...)
537 b = strconv.AppendInt(b, int64(t.Minute()), 10)
538 b = append(b, zgh.timeSeparator...)
544 b = strconv.AppendInt(b, int64(t.Second()), 10)
545 b = append(b, []byte{0x20}...)
553 // FmtTimeFull returns the full time representation of 't' for 'zgh'
554 func (zgh *zgh) FmtTimeFull(t time.Time) string {
556 b := make([]byte, 0, 32)
562 b = strconv.AppendInt(b, int64(t.Hour()), 10)
563 b = append(b, zgh.timeSeparator...)
569 b = strconv.AppendInt(b, int64(t.Minute()), 10)
570 b = append(b, zgh.timeSeparator...)
576 b = strconv.AppendInt(b, int64(t.Second()), 10)
577 b = append(b, []byte{0x20}...)
581 if btz, ok := zgh.timezones[tz]; ok {
582 b = append(b, btz...)