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 'shi' locale
43 func New() locales.Translator {
46 pluralsCardinal: []locales.PluralRule{2, 4, 6},
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{"", "ⵉⵏⵏ", "ⴱⵕⴰ", "ⵎⴰⵕ", "ⵉⴱⵔ", "ⵎⴰⵢ", "ⵢⵓⵏ", "ⵢⵓⵍ", "ⵖⵓⵛ", "ⵛⵓⵜ", "ⴽⵜⵓ", "ⵏⵓⵡ", "ⴷⵓⵊ"},
54 monthsNarrow: []string{"", "ⵉ", "ⴱ", "ⵎ", "ⵉ", "ⵎ", "ⵢ", "ⵢ", "ⵖ", "ⵛ", "ⴽ", "ⵏ", "ⴷ"},
55 monthsWide: []string{"", "ⵉⵏⵏⴰⵢⵔ", "ⴱⵕⴰⵢⵕ", "ⵎⴰⵕⵚ", "ⵉⴱⵔⵉⵔ", "ⵎⴰⵢⵢⵓ", "ⵢⵓⵏⵢⵓ", "ⵢⵓⵍⵢⵓⵣ", "ⵖⵓⵛⵜ", "ⵛⵓⵜⴰⵏⴱⵉⵔ", "ⴽⵜⵓⴱⵔ", "ⵏⵓⵡⴰⵏⴱⵉⵔ", "ⴷⵓⵊⴰⵏⴱⵉⵔ"},
56 daysAbbreviated: []string{"ⴰⵙⴰ", "ⴰⵢⵏ", "ⴰⵙⵉ", "ⴰⴽⵕ", "ⴰⴽⵡ", "ⴰⵙⵉⵎ", "ⴰⵙⵉⴹ"},
57 daysWide: []string{"ⴰⵙⴰⵎⴰⵙ", "ⴰⵢⵏⴰⵙ", "ⴰⵙⵉⵏⴰⵙ", "ⴰⴽⵕⴰⵙ", "ⴰⴽⵡⴰⵙ", "ⵙⵉⵎⵡⴰⵙ", "ⴰⵙⵉⴹⵢⴰⵙ"},
58 periodsAbbreviated: []string{"ⵜⵉⴼⴰⵡⵜ", "ⵜⴰⴷⴳⴳⵯⴰⵜ"},
59 periodsWide: []string{"ⵜⵉⴼⴰⵡⵜ", "ⵜⴰⴷⴳⴳⵯⴰⵜ"},
60 erasAbbreviated: []string{"ⴷⴰⵄ", "ⴷⴼⵄ"},
61 erasNarrow: []string{"", ""},
62 erasWide: []string{"ⴷⴰⵜ ⵏ ⵄⵉⵙⴰ", "ⴷⴼⴼⵉⵔ ⵏ ⵄⵉⵙⴰ"},
63 timezones: map[string]string{"BT": "BT", "AWDT": "AWDT", "CDT": "CDT", "UYT": "UYT", "WART": "WART", "AKST": "AKST", "HNPM": "HNPM", "MST": "MST", "MDT": "MDT", "ACWST": "ACWST", "TMT": "TMT", "LHST": "LHST", "OESZ": "OESZ", "SGT": "SGT", "HNPMX": "HNPMX", "ADT": "ADT", "UYST": "UYST", "WIT": "WIT", "HADT": "HADT", "MESZ": "MESZ", "LHDT": "LHDT", "HENOMX": "HENOMX", "CAT": "CAT", "CHADT": "CHADT", "CLT": "CLT", "HNT": "HNT", "AEST": "AEST", "SAST": "SAST", "PST": "PST", "PDT": "PDT", "AWST": "AWST", "AEDT": "AEDT", "HNOG": "HNOG", "HKT": "HKT", "ACST": "ACST", "CHAST": "CHAST", "HAT": "HAT", "COT": "COT", "GFT": "GFT", "GYT": "GYT", "GMT": "GMT", "NZST": "NZST", "HNCU": "HNCU", "ChST": "ChST", "WIB": "WIB", "OEZ": "OEZ", "HKST": "HKST", "CLST": "CLST", "EST": "EST", "ACWDT": "ACWDT", "NZDT": "NZDT", "JST": "JST", "HEOG": "HEOG", "AKDT": "AKDT", "HNNOMX": "HNNOMX", "SRT": "SRT", "MYT": "MYT", "TMST": "TMST", "WEZ": "WEZ", "HECU": "HECU", "MEZ": "MEZ", "WITA": "WITA", "JDT": "JDT", "AST": "AST", "EAT": "EAT", "ECT": "ECT", "VET": "VET", "CST": "CST", "COST": "COST", "HAST": "HAST", "ART": "ART", "HEEG": "HEEG", "HEPMX": "HEPMX", "HEPM": "HEPM", "IST": "IST", "EDT": "EDT", "WESZ": "WESZ", "BOT": "BOT", "WARST": "WARST", "ARST": "ARST", "WAT": "WAT", "WAST": "WAST", "HNEG": "HNEG", "ACDT": "ACDT", "∅∅∅": "∅∅∅"},
67 // Locale returns the current translators string locale
68 func (shi *shi) Locale() string {
72 // PluralsCardinal returns the list of cardinal plural rules associated with 'shi'
73 func (shi *shi) PluralsCardinal() []locales.PluralRule {
74 return shi.pluralsCardinal
77 // PluralsOrdinal returns the list of ordinal plural rules associated with 'shi'
78 func (shi *shi) PluralsOrdinal() []locales.PluralRule {
79 return shi.pluralsOrdinal
82 // PluralsRange returns the list of range plural rules associated with 'shi'
83 func (shi *shi) PluralsRange() []locales.PluralRule {
84 return shi.pluralsRange
87 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'shi'
88 func (shi *shi) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
93 if (i == 0) || (n == 1) {
94 return locales.PluralRuleOne
95 } else if n >= 2 && n <= 10 {
96 return locales.PluralRuleFew
99 return locales.PluralRuleOther
102 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'shi'
103 func (shi *shi) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
104 return locales.PluralRuleUnknown
107 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'shi'
108 func (shi *shi) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
109 return locales.PluralRuleUnknown
112 // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
113 func (shi *shi) MonthAbbreviated(month time.Month) string {
114 return shi.monthsAbbreviated[month]
117 // MonthsAbbreviated returns the locales abbreviated months
118 func (shi *shi) MonthsAbbreviated() []string {
119 return shi.monthsAbbreviated[1:]
122 // MonthNarrow returns the locales narrow month given the 'month' provided
123 func (shi *shi) MonthNarrow(month time.Month) string {
124 return shi.monthsNarrow[month]
127 // MonthsNarrow returns the locales narrow months
128 func (shi *shi) MonthsNarrow() []string {
129 return shi.monthsNarrow[1:]
132 // MonthWide returns the locales wide month given the 'month' provided
133 func (shi *shi) MonthWide(month time.Month) string {
134 return shi.monthsWide[month]
137 // MonthsWide returns the locales wide months
138 func (shi *shi) MonthsWide() []string {
139 return shi.monthsWide[1:]
142 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
143 func (shi *shi) WeekdayAbbreviated(weekday time.Weekday) string {
144 return shi.daysAbbreviated[weekday]
147 // WeekdaysAbbreviated returns the locales abbreviated weekdays
148 func (shi *shi) WeekdaysAbbreviated() []string {
149 return shi.daysAbbreviated
152 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
153 func (shi *shi) WeekdayNarrow(weekday time.Weekday) string {
154 return shi.daysNarrow[weekday]
157 // WeekdaysNarrow returns the locales narrow weekdays
158 func (shi *shi) WeekdaysNarrow() []string {
159 return shi.daysNarrow
162 // WeekdayShort returns the locales short weekday given the 'weekday' provided
163 func (shi *shi) WeekdayShort(weekday time.Weekday) string {
164 return shi.daysShort[weekday]
167 // WeekdaysShort returns the locales short weekdays
168 func (shi *shi) WeekdaysShort() []string {
172 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
173 func (shi *shi) WeekdayWide(weekday time.Weekday) string {
174 return shi.daysWide[weekday]
177 // WeekdaysWide returns the locales wide weekdays
178 func (shi *shi) WeekdaysWide() []string {
182 // Decimal returns the decimal point of number
183 func (shi *shi) Decimal() string {
187 // Group returns the group of number
188 func (shi *shi) Group() string {
192 // Group returns the minus sign of number
193 func (shi *shi) Minus() string {
197 // FmtNumber returns 'num' with digits/precision of 'v' for 'shi' and handles both Whole and Real numbers based on 'v'
198 func (shi *shi) FmtNumber(num float64, v uint64) string {
200 return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
203 // FmtPercent returns 'num' with digits/precision of 'v' for 'shi' and handles both Whole and Real numbers based on 'v'
204 // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
205 func (shi *shi) FmtPercent(num float64, v uint64) string {
206 return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
209 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'shi'
210 func (shi *shi) FmtCurrency(num float64, v uint64, currency currency.Type) string {
212 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
213 symbol := shi.currencies[currency]
214 l := len(s) + len(symbol) + 1 + 2*len(s[:len(s)-int(v)-1])/3
217 b := make([]byte, 0, l)
219 for i := len(s) - 1; i >= 0; i-- {
222 b = append(b, shi.decimal[0])
229 for j := len(shi.group) - 1; j >= 0; j-- {
230 b = append(b, shi.group[j])
242 b = append(b, shi.minus[0])
246 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
247 b[i], b[j] = b[j], b[i]
253 b = append(b, shi.decimal...)
256 for i := 0; i < 2-int(v); i++ {
261 b = append(b, symbol...)
266 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'shi'
267 // in accounting notation.
268 func (shi *shi) FmtAccounting(num float64, v uint64, currency currency.Type) string {
270 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
271 symbol := shi.currencies[currency]
272 l := len(s) + len(symbol) + 1 + 2*len(s[:len(s)-int(v)-1])/3
275 b := make([]byte, 0, l)
277 for i := len(s) - 1; i >= 0; i-- {
280 b = append(b, shi.decimal[0])
287 for j := len(shi.group) - 1; j >= 0; j-- {
288 b = append(b, shi.group[j])
301 b = append(b, shi.minus[0])
306 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
307 b[i], b[j] = b[j], b[i]
313 b = append(b, shi.decimal...)
316 for i := 0; i < 2-int(v); i++ {
322 b = append(b, symbol...)
325 b = append(b, symbol...)
331 // FmtDateShort returns the short date representation of 't' for 'shi'
332 func (shi *shi) FmtDateShort(t time.Time) string {
334 b := make([]byte, 0, 32)
336 b = strconv.AppendInt(b, int64(t.Day()), 10)
337 b = append(b, []byte{0x2f}...)
338 b = strconv.AppendInt(b, int64(t.Month()), 10)
339 b = append(b, []byte{0x2f}...)
342 b = strconv.AppendInt(b, int64(t.Year()), 10)
344 b = strconv.AppendInt(b, int64(-t.Year()), 10)
350 // FmtDateMedium returns the medium date representation of 't' for 'shi'
351 func (shi *shi) FmtDateMedium(t time.Time) string {
353 b := make([]byte, 0, 32)
355 b = strconv.AppendInt(b, int64(t.Day()), 10)
356 b = append(b, []byte{0x20}...)
357 b = append(b, shi.monthsAbbreviated[t.Month()]...)
358 b = append(b, []byte{0x2c, 0x20}...)
361 b = strconv.AppendInt(b, int64(t.Year()), 10)
363 b = strconv.AppendInt(b, int64(-t.Year()), 10)
369 // FmtDateLong returns the long date representation of 't' for 'shi'
370 func (shi *shi) FmtDateLong(t time.Time) string {
372 b := make([]byte, 0, 32)
374 b = strconv.AppendInt(b, int64(t.Day()), 10)
375 b = append(b, []byte{0x20}...)
376 b = append(b, shi.monthsWide[t.Month()]...)
377 b = append(b, []byte{0x20}...)
380 b = strconv.AppendInt(b, int64(t.Year()), 10)
382 b = strconv.AppendInt(b, int64(-t.Year()), 10)
388 // FmtDateFull returns the full date representation of 't' for 'shi'
389 func (shi *shi) FmtDateFull(t time.Time) string {
391 b := make([]byte, 0, 32)
393 b = append(b, shi.daysWide[t.Weekday()]...)
394 b = append(b, []byte{0x20}...)
395 b = strconv.AppendInt(b, int64(t.Day()), 10)
396 b = append(b, []byte{0x20}...)
397 b = append(b, shi.monthsWide[t.Month()]...)
398 b = append(b, []byte{0x20}...)
401 b = strconv.AppendInt(b, int64(t.Year()), 10)
403 b = strconv.AppendInt(b, int64(-t.Year()), 10)
409 // FmtTimeShort returns the short time representation of 't' for 'shi'
410 func (shi *shi) FmtTimeShort(t time.Time) string {
412 b := make([]byte, 0, 32)
417 // FmtTimeMedium returns the medium time representation of 't' for 'shi'
418 func (shi *shi) FmtTimeMedium(t time.Time) string {
420 b := make([]byte, 0, 32)
425 // FmtTimeLong returns the long time representation of 't' for 'shi'
426 func (shi *shi) FmtTimeLong(t time.Time) string {
428 b := make([]byte, 0, 32)
433 // FmtTimeFull returns the full time representation of 't' for 'shi'
434 func (shi *shi) FmtTimeFull(t time.Time) string {
436 b := make([]byte, 0, 32)