OSDN Git Service

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