OSDN Git Service

delete miner
[bytom/vapor.git] / vendor / github.com / go-playground / locales / ksb / ksb.go
1 package ksb
2
3 import (
4         "math"
5         "strconv"
6         "time"
7
8         "github.com/go-playground/locales"
9         "github.com/go-playground/locales/currency"
10 )
11
12 type ksb struct {
13         locale             string
14         pluralsCardinal    []locales.PluralRule
15         pluralsOrdinal     []locales.PluralRule
16         pluralsRange       []locales.PluralRule
17         decimal            string
18         group              string
19         minus              string
20         percent            string
21         perMille           string
22         timeSeparator      string
23         inifinity          string
24         currencies         []string // idx = enum of currency code
25         monthsAbbreviated  []string
26         monthsNarrow       []string
27         monthsWide         []string
28         daysAbbreviated    []string
29         daysNarrow         []string
30         daysShort          []string
31         daysWide           []string
32         periodsAbbreviated []string
33         periodsNarrow      []string
34         periodsShort       []string
35         periodsWide        []string
36         erasAbbreviated    []string
37         erasNarrow         []string
38         erasWide           []string
39         timezones          map[string]string
40 }
41
42 // New returns a new instance of translator for the 'ksb' locale
43 func New() locales.Translator {
44         return &ksb{
45                 locale:             "ksb",
46                 pluralsCardinal:    []locales.PluralRule{2, 6},
47                 pluralsOrdinal:     nil,
48                 pluralsRange:       nil,
49                 timeSeparator:      ":",
50                 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", "TSh", "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"},
51                 monthsAbbreviated:  []string{"", "Jan", "Feb", "Mac", "Apr", "Mei", "Jun", "Jul", "Ago", "Sep", "Okt", "Nov", "Des"},
52                 monthsNarrow:       []string{"", "J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"},
53                 monthsWide:         []string{"", "Januali", "Febluali", "Machi", "Aplili", "Mei", "Juni", "Julai", "Agosti", "Septemba", "Oktoba", "Novemba", "Desemba"},
54                 daysAbbreviated:    []string{"Jpi", "Jtt", "Jmn", "Jtn", "Alh", "Iju", "Jmo"},
55                 daysNarrow:         []string{"2", "3", "4", "5", "A", "I", "1"},
56                 daysWide:           []string{"Jumaapii", "Jumaatatu", "Jumaane", "Jumaatano", "Alhamisi", "Ijumaa", "Jumaamosi"},
57                 periodsAbbreviated: []string{"makeo", "nyiaghuo"},
58                 periodsWide:        []string{"makeo", "nyiaghuo"},
59                 erasAbbreviated:    []string{"KK", "BK"},
60                 erasNarrow:         []string{"", ""},
61                 erasWide:           []string{"Kabla ya Klisto", "Baada ya Klisto"},
62                 timezones:          map[string]string{"COST": "COST", "BT": "BT", "WIT": "WIT", "IST": "IST", "ART": "ART", "HAT": "HAT", "HNCU": "HNCU", "AWST": "AWST", "SRT": "SRT", "HKST": "HKST", "ACST": "ACST", "ECT": "ECT", "HAST": "HAST", "TMT": "TMT", "WAT": "WAT", "HEEG": "HEEG", "COT": "COT", "∅∅∅": "∅∅∅", "ARST": "ARST", "HEOG": "HEOG", "HNPM": "HNPM", "HECU": "HECU", "AEDT": "AEDT", "EAT": "EAT", "WAST": "WAST", "GFT": "GFT", "SGT": "SGT", "MESZ": "MESZ", "WESZ": "WESZ", "HKT": "HKT", "CLT": "CLT", "GYT": "GYT", "CDT": "CDT", "WITA": "WITA", "OESZ": "OESZ", "WART": "WART", "AST": "AST", "HNPMX": "HNPMX", "PDT": "PDT", "AWDT": "AWDT", "TMST": "TMST", "WIB": "WIB", "MST": "MST", "MDT": "MDT", "ACWST": "ACWST", "AEST": "AEST", "HNOG": "HNOG", "AKST": "AKST", "ACDT": "ACDT", "BOT": "BOT", "CST": "CST", "MYT": "MYT", "UYST": "UYST", "OEZ": "OEZ", "WEZ": "WEZ", "GMT": "GMT", "ChST": "ChST", "JDT": "JDT", "CLST": "CLST", "EST": "EST", "AKDT": "AKDT", "MEZ": "MEZ", "NZST": "NZST", "SAST": "SAST", "HEPM": "HEPM", "UYT": "UYT", "HADT": "HADT", "CAT": "CAT", "VET": "VET", "ADT": "ADT", "HEPMX": "HEPMX", "ACWDT": "ACWDT", "HENOMX": "HENOMX", "JST": "JST", "LHST": "LHST", "LHDT": "LHDT", "CHAST": "CHAST", "CHADT": "CHADT", "EDT": "EDT", "PST": "PST", "NZDT": "NZDT", "HNNOMX": "HNNOMX", "WARST": "WARST", "HNEG": "HNEG", "HNT": "HNT"},
63         }
64 }
65
66 // Locale returns the current translators string locale
67 func (ksb *ksb) Locale() string {
68         return ksb.locale
69 }
70
71 // PluralsCardinal returns the list of cardinal plural rules associated with 'ksb'
72 func (ksb *ksb) PluralsCardinal() []locales.PluralRule {
73         return ksb.pluralsCardinal
74 }
75
76 // PluralsOrdinal returns the list of ordinal plural rules associated with 'ksb'
77 func (ksb *ksb) PluralsOrdinal() []locales.PluralRule {
78         return ksb.pluralsOrdinal
79 }
80
81 // PluralsRange returns the list of range plural rules associated with 'ksb'
82 func (ksb *ksb) PluralsRange() []locales.PluralRule {
83         return ksb.pluralsRange
84 }
85
86 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'ksb'
87 func (ksb *ksb) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
88
89         n := math.Abs(num)
90
91         if n == 1 {
92                 return locales.PluralRuleOne
93         }
94
95         return locales.PluralRuleOther
96 }
97
98 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'ksb'
99 func (ksb *ksb) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
100         return locales.PluralRuleUnknown
101 }
102
103 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'ksb'
104 func (ksb *ksb) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
105         return locales.PluralRuleUnknown
106 }
107
108 // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
109 func (ksb *ksb) MonthAbbreviated(month time.Month) string {
110         return ksb.monthsAbbreviated[month]
111 }
112
113 // MonthsAbbreviated returns the locales abbreviated months
114 func (ksb *ksb) MonthsAbbreviated() []string {
115         return ksb.monthsAbbreviated[1:]
116 }
117
118 // MonthNarrow returns the locales narrow month given the 'month' provided
119 func (ksb *ksb) MonthNarrow(month time.Month) string {
120         return ksb.monthsNarrow[month]
121 }
122
123 // MonthsNarrow returns the locales narrow months
124 func (ksb *ksb) MonthsNarrow() []string {
125         return ksb.monthsNarrow[1:]
126 }
127
128 // MonthWide returns the locales wide month given the 'month' provided
129 func (ksb *ksb) MonthWide(month time.Month) string {
130         return ksb.monthsWide[month]
131 }
132
133 // MonthsWide returns the locales wide months
134 func (ksb *ksb) MonthsWide() []string {
135         return ksb.monthsWide[1:]
136 }
137
138 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
139 func (ksb *ksb) WeekdayAbbreviated(weekday time.Weekday) string {
140         return ksb.daysAbbreviated[weekday]
141 }
142
143 // WeekdaysAbbreviated returns the locales abbreviated weekdays
144 func (ksb *ksb) WeekdaysAbbreviated() []string {
145         return ksb.daysAbbreviated
146 }
147
148 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
149 func (ksb *ksb) WeekdayNarrow(weekday time.Weekday) string {
150         return ksb.daysNarrow[weekday]
151 }
152
153 // WeekdaysNarrow returns the locales narrow weekdays
154 func (ksb *ksb) WeekdaysNarrow() []string {
155         return ksb.daysNarrow
156 }
157
158 // WeekdayShort returns the locales short weekday given the 'weekday' provided
159 func (ksb *ksb) WeekdayShort(weekday time.Weekday) string {
160         return ksb.daysShort[weekday]
161 }
162
163 // WeekdaysShort returns the locales short weekdays
164 func (ksb *ksb) WeekdaysShort() []string {
165         return ksb.daysShort
166 }
167
168 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
169 func (ksb *ksb) WeekdayWide(weekday time.Weekday) string {
170         return ksb.daysWide[weekday]
171 }
172
173 // WeekdaysWide returns the locales wide weekdays
174 func (ksb *ksb) WeekdaysWide() []string {
175         return ksb.daysWide
176 }
177
178 // Decimal returns the decimal point of number
179 func (ksb *ksb) Decimal() string {
180         return ksb.decimal
181 }
182
183 // Group returns the group of number
184 func (ksb *ksb) Group() string {
185         return ksb.group
186 }
187
188 // Group returns the minus sign of number
189 func (ksb *ksb) Minus() string {
190         return ksb.minus
191 }
192
193 // FmtNumber returns 'num' with digits/precision of 'v' for 'ksb' and handles both Whole and Real numbers based on 'v'
194 func (ksb *ksb) FmtNumber(num float64, v uint64) string {
195
196         return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
197 }
198
199 // FmtPercent returns 'num' with digits/precision of 'v' for 'ksb' and handles both Whole and Real numbers based on 'v'
200 // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
201 func (ksb *ksb) FmtPercent(num float64, v uint64) string {
202         return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
203 }
204
205 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'ksb'
206 func (ksb *ksb) FmtCurrency(num float64, v uint64, currency currency.Type) string {
207
208         s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
209         symbol := ksb.currencies[currency]
210         l := len(s) + len(symbol) + 0
211         count := 0
212         inWhole := v == 0
213         b := make([]byte, 0, l)
214
215         for i := len(s) - 1; i >= 0; i-- {
216
217                 if s[i] == '.' {
218                         b = append(b, ksb.decimal[0])
219                         inWhole = true
220                         continue
221                 }
222
223                 if inWhole {
224                         if count == 3 {
225                                 b = append(b, ksb.group[0])
226                                 count = 1
227                         } else {
228                                 count++
229                         }
230                 }
231
232                 b = append(b, s[i])
233         }
234
235         if num < 0 {
236                 b = append(b, ksb.minus[0])
237         }
238
239         // reverse
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]
242         }
243
244         if int(v) < 2 {
245
246                 if v == 0 {
247                         b = append(b, ksb.decimal...)
248                 }
249
250                 for i := 0; i < 2-int(v); i++ {
251                         b = append(b, '0')
252                 }
253         }
254
255         b = append(b, symbol...)
256
257         return string(b)
258 }
259
260 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'ksb'
261 // in accounting notation.
262 func (ksb *ksb) FmtAccounting(num float64, v uint64, currency currency.Type) string {
263
264         s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
265         symbol := ksb.currencies[currency]
266         l := len(s) + len(symbol) + 0
267         count := 0
268         inWhole := v == 0
269         b := make([]byte, 0, l)
270
271         for i := len(s) - 1; i >= 0; i-- {
272
273                 if s[i] == '.' {
274                         b = append(b, ksb.decimal[0])
275                         inWhole = true
276                         continue
277                 }
278
279                 if inWhole {
280                         if count == 3 {
281                                 b = append(b, ksb.group[0])
282                                 count = 1
283                         } else {
284                                 count++
285                         }
286                 }
287
288                 b = append(b, s[i])
289         }
290
291         if num < 0 {
292
293                 b = append(b, ksb.minus[0])
294
295         }
296
297         // reverse
298         for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
299                 b[i], b[j] = b[j], b[i]
300         }
301
302         if int(v) < 2 {
303
304                 if v == 0 {
305                         b = append(b, ksb.decimal...)
306                 }
307
308                 for i := 0; i < 2-int(v); i++ {
309                         b = append(b, '0')
310                 }
311         }
312
313         if num < 0 {
314                 b = append(b, symbol...)
315         } else {
316
317                 b = append(b, symbol...)
318         }
319
320         return string(b)
321 }
322
323 // FmtDateShort returns the short date representation of 't' for 'ksb'
324 func (ksb *ksb) FmtDateShort(t time.Time) string {
325
326         b := make([]byte, 0, 32)
327
328         if t.Day() < 10 {
329                 b = append(b, '0')
330         }
331
332         b = strconv.AppendInt(b, int64(t.Day()), 10)
333         b = append(b, []byte{0x2f}...)
334
335         if t.Month() < 10 {
336                 b = append(b, '0')
337         }
338
339         b = strconv.AppendInt(b, int64(t.Month()), 10)
340
341         b = append(b, []byte{0x2f}...)
342
343         if t.Year() > 0 {
344                 b = strconv.AppendInt(b, int64(t.Year()), 10)
345         } else {
346                 b = strconv.AppendInt(b, int64(-t.Year()), 10)
347         }
348
349         return string(b)
350 }
351
352 // FmtDateMedium returns the medium date representation of 't' for 'ksb'
353 func (ksb *ksb) FmtDateMedium(t time.Time) string {
354
355         b := make([]byte, 0, 32)
356
357         b = strconv.AppendInt(b, int64(t.Day()), 10)
358         b = append(b, []byte{0x20}...)
359         b = append(b, ksb.monthsAbbreviated[t.Month()]...)
360         b = append(b, []byte{0x20}...)
361
362         if t.Year() > 0 {
363                 b = strconv.AppendInt(b, int64(t.Year()), 10)
364         } else {
365                 b = strconv.AppendInt(b, int64(-t.Year()), 10)
366         }
367
368         return string(b)
369 }
370
371 // FmtDateLong returns the long date representation of 't' for 'ksb'
372 func (ksb *ksb) FmtDateLong(t time.Time) string {
373
374         b := make([]byte, 0, 32)
375
376         b = strconv.AppendInt(b, int64(t.Day()), 10)
377         b = append(b, []byte{0x20}...)
378         b = append(b, ksb.monthsWide[t.Month()]...)
379         b = append(b, []byte{0x20}...)
380
381         if t.Year() > 0 {
382                 b = strconv.AppendInt(b, int64(t.Year()), 10)
383         } else {
384                 b = strconv.AppendInt(b, int64(-t.Year()), 10)
385         }
386
387         return string(b)
388 }
389
390 // FmtDateFull returns the full date representation of 't' for 'ksb'
391 func (ksb *ksb) FmtDateFull(t time.Time) string {
392
393         b := make([]byte, 0, 32)
394
395         b = append(b, ksb.daysWide[t.Weekday()]...)
396         b = append(b, []byte{0x2c, 0x20}...)
397         b = strconv.AppendInt(b, int64(t.Day()), 10)
398         b = append(b, []byte{0x20}...)
399         b = append(b, ksb.monthsWide[t.Month()]...)
400         b = append(b, []byte{0x20}...)
401
402         if t.Year() > 0 {
403                 b = strconv.AppendInt(b, int64(t.Year()), 10)
404         } else {
405                 b = strconv.AppendInt(b, int64(-t.Year()), 10)
406         }
407
408         return string(b)
409 }
410
411 // FmtTimeShort returns the short time representation of 't' for 'ksb'
412 func (ksb *ksb) FmtTimeShort(t time.Time) string {
413
414         b := make([]byte, 0, 32)
415
416         if t.Hour() < 10 {
417                 b = append(b, '0')
418         }
419
420         b = strconv.AppendInt(b, int64(t.Hour()), 10)
421         b = append(b, ksb.timeSeparator...)
422
423         if t.Minute() < 10 {
424                 b = append(b, '0')
425         }
426
427         b = strconv.AppendInt(b, int64(t.Minute()), 10)
428
429         return string(b)
430 }
431
432 // FmtTimeMedium returns the medium time representation of 't' for 'ksb'
433 func (ksb *ksb) FmtTimeMedium(t time.Time) string {
434
435         b := make([]byte, 0, 32)
436
437         if t.Hour() < 10 {
438                 b = append(b, '0')
439         }
440
441         b = strconv.AppendInt(b, int64(t.Hour()), 10)
442         b = append(b, ksb.timeSeparator...)
443
444         if t.Minute() < 10 {
445                 b = append(b, '0')
446         }
447
448         b = strconv.AppendInt(b, int64(t.Minute()), 10)
449         b = append(b, ksb.timeSeparator...)
450
451         if t.Second() < 10 {
452                 b = append(b, '0')
453         }
454
455         b = strconv.AppendInt(b, int64(t.Second()), 10)
456
457         return string(b)
458 }
459
460 // FmtTimeLong returns the long time representation of 't' for 'ksb'
461 func (ksb *ksb) FmtTimeLong(t time.Time) string {
462
463         b := make([]byte, 0, 32)
464
465         if t.Hour() < 10 {
466                 b = append(b, '0')
467         }
468
469         b = strconv.AppendInt(b, int64(t.Hour()), 10)
470         b = append(b, ksb.timeSeparator...)
471
472         if t.Minute() < 10 {
473                 b = append(b, '0')
474         }
475
476         b = strconv.AppendInt(b, int64(t.Minute()), 10)
477         b = append(b, ksb.timeSeparator...)
478
479         if t.Second() < 10 {
480                 b = append(b, '0')
481         }
482
483         b = strconv.AppendInt(b, int64(t.Second()), 10)
484         b = append(b, []byte{0x20}...)
485
486         tz, _ := t.Zone()
487         b = append(b, tz...)
488
489         return string(b)
490 }
491
492 // FmtTimeFull returns the full time representation of 't' for 'ksb'
493 func (ksb *ksb) FmtTimeFull(t time.Time) string {
494
495         b := make([]byte, 0, 32)
496
497         if t.Hour() < 10 {
498                 b = append(b, '0')
499         }
500
501         b = strconv.AppendInt(b, int64(t.Hour()), 10)
502         b = append(b, ksb.timeSeparator...)
503
504         if t.Minute() < 10 {
505                 b = append(b, '0')
506         }
507
508         b = strconv.AppendInt(b, int64(t.Minute()), 10)
509         b = append(b, ksb.timeSeparator...)
510
511         if t.Second() < 10 {
512                 b = append(b, '0')
513         }
514
515         b = strconv.AppendInt(b, int64(t.Second()), 10)
516         b = append(b, []byte{0x20}...)
517
518         tz, _ := t.Zone()
519
520         if btz, ok := ksb.timezones[tz]; ok {
521                 b = append(b, btz...)
522         } else {
523                 b = append(b, tz...)
524         }
525
526         return string(b)
527 }