1 package ewo
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 ewo 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
25 currencyPositiveSuffix string
26 currencyNegativeSuffix string
27 monthsAbbreviated []string
28 monthsNarrow []string
29 monthsWide []string
30 daysAbbreviated []string
31 daysNarrow []string
32 daysShort []string
33 daysWide []string
34 periodsAbbreviated []string
35 periodsNarrow []string
36 periodsShort []string
37 periodsWide []string
38 erasAbbreviated []string
39 erasNarrow []string
40 erasWide []string
41 timezones map[string]string
42 }
43
44
45 func New() locales.Translator {
46 return &ewo{
47 locale: "ewo",
48 pluralsCardinal: nil,
49 pluralsOrdinal: nil,
50 pluralsRange: nil,
51 decimal: ",",
52 group: " ",
53 timeSeparator: ":",
54 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", "CNH", "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", "MRU", "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", "STN", "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", "UYW", "UZS", "VEB", "VEF", "VES", "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"},
55 currencyPositiveSuffix: " ",
56 currencyNegativeSuffix: " ",
57 monthsAbbreviated: []string{"", "ngo", "ngb", "ngl", "ngn", "ngt", "ngs", "ngz", "ngm", "nge", "nga", "ngad", "ngab"},
58 monthsNarrow: []string{"", "o", "b", "l", "n", "t", "s", "z", "m", "e", "a", "d", "b"},
59 monthsWide: []string{"", "ngɔn osú", "ngɔn bɛ̌", "ngɔn lála", "ngɔn nyina", "ngɔn tána", "ngɔn saməna", "ngɔn zamgbála", "ngɔn mwom", "ngɔn ebulú", "ngɔn awóm", "ngɔn awóm ai dziá", "ngɔn awóm ai bɛ̌"},
60 daysAbbreviated: []string{"sɔ́n", "mɔ́n", "smb", "sml", "smn", "fúl", "sér"},
61 daysNarrow: []string{"s", "m", "s", "s", "s", "f", "s"},
62 daysWide: []string{"sɔ́ndɔ", "mɔ́ndi", "sɔ́ndɔ məlú mə́bɛ̌", "sɔ́ndɔ məlú mə́lɛ́", "sɔ́ndɔ məlú mə́nyi", "fúladé", "séradé"},
63 periodsAbbreviated: []string{"kíkíríg", "ngəgógəle"},
64 periodsWide: []string{"kíkíríg", "ngəgógəle"},
65 erasAbbreviated: []string{"oyk", "ayk"},
66 erasNarrow: []string{"", ""},
67 erasWide: []string{"osúsúa Yésus kiri", "ámvus Yésus Kirís"},
68 timezones: map[string]string{"ACDT": "ACDT", "ACST": "ACST", "ACWDT": "ACWDT", "ACWST": "ACWST", "ADT": "ADT", "AEDT": "AEDT", "AEST": "AEST", "AKDT": "AKDT", "AKST": "AKST", "ARST": "ARST", "ART": "ART", "AST": "AST", "AWDT": "AWDT", "AWST": "AWST", "BOT": "BOT", "BT": "BT", "CAT": "CAT", "CDT": "CDT", "CHADT": "CHADT", "CHAST": "CHAST", "CLST": "CLST", "CLT": "CLT", "COST": "COST", "COT": "COT", "CST": "CST", "ChST": "ChST", "EAT": "EAT", "ECT": "ECT", "EDT": "EDT", "EST": "EST", "GFT": "GFT", "GMT": "GMT", "GST": "GST", "GYT": "GYT", "HADT": "HADT", "HAST": "HAST", "HAT": "HAT", "HECU": "HECU", "HEEG": "HEEG", "HENOMX": "HENOMX", "HEOG": "HEOG", "HEPM": "HEPM", "HEPMX": "HEPMX", "HKST": "HKST", "HKT": "HKT", "HNCU": "HNCU", "HNEG": "HNEG", "HNNOMX": "HNNOMX", "HNOG": "HNOG", "HNPM": "HNPM", "HNPMX": "HNPMX", "HNT": "HNT", "IST": "IST", "JDT": "JDT", "JST": "JST", "LHDT": "LHDT", "LHST": "LHST", "MDT": "MDT", "MESZ": "MESZ", "MEZ": "MEZ", "MST": "MST", "MYT": "MYT", "NZDT": "NZDT", "NZST": "NZST", "OESZ": "OESZ", "OEZ": "OEZ", "PDT": "PDT", "PST": "PST", "SAST": "SAST", "SGT": "SGT", "SRT": "SRT", "TMST": "TMST", "TMT": "TMT", "UYST": "UYST", "UYT": "UYT", "VET": "VET", "WARST": "WARST", "WART": "WART", "WAST": "WAST", "WAT": "WAT", "WESZ": "WESZ", "WEZ": "WEZ", "WIB": "WIB", "WIT": "WIT", "WITA": "WITA", "∅∅∅": "∅∅∅"},
69 }
70 }
71
72
73 func (ewo *ewo) Locale() string {
74 return ewo.locale
75 }
76
77
78 func (ewo *ewo) PluralsCardinal() []locales.PluralRule {
79 return ewo.pluralsCardinal
80 }
81
82
83 func (ewo *ewo) PluralsOrdinal() []locales.PluralRule {
84 return ewo.pluralsOrdinal
85 }
86
87
88 func (ewo *ewo) PluralsRange() []locales.PluralRule {
89 return ewo.pluralsRange
90 }
91
92
93 func (ewo *ewo) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
94 return locales.PluralRuleUnknown
95 }
96
97
98 func (ewo *ewo) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
99 return locales.PluralRuleUnknown
100 }
101
102
103 func (ewo *ewo) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
104 return locales.PluralRuleUnknown
105 }
106
107
108 func (ewo *ewo) MonthAbbreviated(month time.Month) string {
109 return ewo.monthsAbbreviated[month]
110 }
111
112
113 func (ewo *ewo) MonthsAbbreviated() []string {
114 return ewo.monthsAbbreviated[1:]
115 }
116
117
118 func (ewo *ewo) MonthNarrow(month time.Month) string {
119 return ewo.monthsNarrow[month]
120 }
121
122
123 func (ewo *ewo) MonthsNarrow() []string {
124 return ewo.monthsNarrow[1:]
125 }
126
127
128 func (ewo *ewo) MonthWide(month time.Month) string {
129 return ewo.monthsWide[month]
130 }
131
132
133 func (ewo *ewo) MonthsWide() []string {
134 return ewo.monthsWide[1:]
135 }
136
137
138 func (ewo *ewo) WeekdayAbbreviated(weekday time.Weekday) string {
139 return ewo.daysAbbreviated[weekday]
140 }
141
142
143 func (ewo *ewo) WeekdaysAbbreviated() []string {
144 return ewo.daysAbbreviated
145 }
146
147
148 func (ewo *ewo) WeekdayNarrow(weekday time.Weekday) string {
149 return ewo.daysNarrow[weekday]
150 }
151
152
153 func (ewo *ewo) WeekdaysNarrow() []string {
154 return ewo.daysNarrow
155 }
156
157
158 func (ewo *ewo) WeekdayShort(weekday time.Weekday) string {
159 return ewo.daysShort[weekday]
160 }
161
162
163 func (ewo *ewo) WeekdaysShort() []string {
164 return ewo.daysShort
165 }
166
167
168 func (ewo *ewo) WeekdayWide(weekday time.Weekday) string {
169 return ewo.daysWide[weekday]
170 }
171
172
173 func (ewo *ewo) WeekdaysWide() []string {
174 return ewo.daysWide
175 }
176
177
178 func (ewo *ewo) Decimal() string {
179 return ewo.decimal
180 }
181
182
183 func (ewo *ewo) Group() string {
184 return ewo.group
185 }
186
187
188 func (ewo *ewo) Minus() string {
189 return ewo.minus
190 }
191
192
193 func (ewo *ewo) FmtNumber(num float64, v uint64) string {
194
195 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
196 l := len(s) + 1 + 2*len(s[:len(s)-int(v)-1])/3
197 count := 0
198 inWhole := v == 0
199 b := make([]byte, 0, l)
200
201 for i := len(s) - 1; i >= 0; i-- {
202
203 if s[i] == '.' {
204 b = append(b, ewo.decimal[0])
205 inWhole = true
206 continue
207 }
208
209 if inWhole {
210 if count == 3 {
211 for j := len(ewo.group) - 1; j >= 0; j-- {
212 b = append(b, ewo.group[j])
213 }
214 count = 1
215 } else {
216 count++
217 }
218 }
219
220 b = append(b, s[i])
221 }
222
223 if num < 0 {
224 b = append(b, ewo.minus[0])
225 }
226
227
228 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
229 b[i], b[j] = b[j], b[i]
230 }
231
232 return string(b)
233 }
234
235
236
237 func (ewo *ewo) FmtPercent(num float64, v uint64) string {
238 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
239 l := len(s) + 1
240 b := make([]byte, 0, l)
241
242 for i := len(s) - 1; i >= 0; i-- {
243
244 if s[i] == '.' {
245 b = append(b, ewo.decimal[0])
246 continue
247 }
248
249 b = append(b, s[i])
250 }
251
252 if num < 0 {
253 b = append(b, ewo.minus[0])
254 }
255
256
257 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
258 b[i], b[j] = b[j], b[i]
259 }
260
261 b = append(b, ewo.percent...)
262
263 return string(b)
264 }
265
266
267 func (ewo *ewo) FmtCurrency(num float64, v uint64, currency currency.Type) string {
268
269 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
270 symbol := ewo.currencies[currency]
271 l := len(s) + len(symbol) + 3 + 2*len(s[:len(s)-int(v)-1])/3
272 count := 0
273 inWhole := v == 0
274 b := make([]byte, 0, l)
275
276 for i := len(s) - 1; i >= 0; i-- {
277
278 if s[i] == '.' {
279 b = append(b, ewo.decimal[0])
280 inWhole = true
281 continue
282 }
283
284 if inWhole {
285 if count == 3 {
286 for j := len(ewo.group) - 1; j >= 0; j-- {
287 b = append(b, ewo.group[j])
288 }
289 count = 1
290 } else {
291 count++
292 }
293 }
294
295 b = append(b, s[i])
296 }
297
298 if num < 0 {
299 b = append(b, ewo.minus[0])
300 }
301
302
303 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
304 b[i], b[j] = b[j], b[i]
305 }
306
307 if int(v) < 2 {
308
309 if v == 0 {
310 b = append(b, ewo.decimal...)
311 }
312
313 for i := 0; i < 2-int(v); i++ {
314 b = append(b, '0')
315 }
316 }
317
318 b = append(b, ewo.currencyPositiveSuffix...)
319
320 b = append(b, symbol...)
321
322 return string(b)
323 }
324
325
326
327 func (ewo *ewo) FmtAccounting(num float64, v uint64, currency currency.Type) string {
328
329 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
330 symbol := ewo.currencies[currency]
331 l := len(s) + len(symbol) + 3 + 2*len(s[:len(s)-int(v)-1])/3
332 count := 0
333 inWhole := v == 0
334 b := make([]byte, 0, l)
335
336 for i := len(s) - 1; i >= 0; i-- {
337
338 if s[i] == '.' {
339 b = append(b, ewo.decimal[0])
340 inWhole = true
341 continue
342 }
343
344 if inWhole {
345 if count == 3 {
346 for j := len(ewo.group) - 1; j >= 0; j-- {
347 b = append(b, ewo.group[j])
348 }
349 count = 1
350 } else {
351 count++
352 }
353 }
354
355 b = append(b, s[i])
356 }
357
358 if num < 0 {
359
360 b = append(b, ewo.minus[0])
361
362 }
363
364
365 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
366 b[i], b[j] = b[j], b[i]
367 }
368
369 if int(v) < 2 {
370
371 if v == 0 {
372 b = append(b, ewo.decimal...)
373 }
374
375 for i := 0; i < 2-int(v); i++ {
376 b = append(b, '0')
377 }
378 }
379
380 if num < 0 {
381 b = append(b, ewo.currencyNegativeSuffix...)
382 b = append(b, symbol...)
383 } else {
384
385 b = append(b, ewo.currencyPositiveSuffix...)
386 b = append(b, symbol...)
387 }
388
389 return string(b)
390 }
391
392
393 func (ewo *ewo) FmtDateShort(t time.Time) string {
394
395 b := make([]byte, 0, 32)
396
397 b = strconv.AppendInt(b, int64(t.Day()), 10)
398 b = append(b, []byte{0x2f}...)
399 b = strconv.AppendInt(b, int64(t.Month()), 10)
400 b = append(b, []byte{0x2f}...)
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
412 func (ewo *ewo) FmtDateMedium(t time.Time) string {
413
414 b := make([]byte, 0, 32)
415
416 b = strconv.AppendInt(b, int64(t.Day()), 10)
417 b = append(b, []byte{0x20}...)
418 b = append(b, ewo.monthsAbbreviated[t.Month()]...)
419 b = append(b, []byte{0x20}...)
420
421 if t.Year() > 0 {
422 b = strconv.AppendInt(b, int64(t.Year()), 10)
423 } else {
424 b = strconv.AppendInt(b, int64(-t.Year()), 10)
425 }
426
427 return string(b)
428 }
429
430
431 func (ewo *ewo) FmtDateLong(t time.Time) string {
432
433 b := make([]byte, 0, 32)
434
435 b = strconv.AppendInt(b, int64(t.Day()), 10)
436 b = append(b, []byte{0x20}...)
437 b = append(b, ewo.monthsWide[t.Month()]...)
438 b = append(b, []byte{0x20}...)
439
440 if t.Year() > 0 {
441 b = strconv.AppendInt(b, int64(t.Year()), 10)
442 } else {
443 b = strconv.AppendInt(b, int64(-t.Year()), 10)
444 }
445
446 return string(b)
447 }
448
449
450 func (ewo *ewo) FmtDateFull(t time.Time) string {
451
452 b := make([]byte, 0, 32)
453
454 b = append(b, ewo.daysWide[t.Weekday()]...)
455 b = append(b, []byte{0x20}...)
456 b = strconv.AppendInt(b, int64(t.Day()), 10)
457 b = append(b, []byte{0x20}...)
458 b = append(b, ewo.monthsWide[t.Month()]...)
459 b = append(b, []byte{0x20}...)
460
461 if t.Year() > 0 {
462 b = strconv.AppendInt(b, int64(t.Year()), 10)
463 } else {
464 b = strconv.AppendInt(b, int64(-t.Year()), 10)
465 }
466
467 return string(b)
468 }
469
470
471 func (ewo *ewo) FmtTimeShort(t time.Time) string {
472
473 b := make([]byte, 0, 32)
474
475 if t.Hour() < 10 {
476 b = append(b, '0')
477 }
478
479 b = strconv.AppendInt(b, int64(t.Hour()), 10)
480 b = append(b, ewo.timeSeparator...)
481
482 if t.Minute() < 10 {
483 b = append(b, '0')
484 }
485
486 b = strconv.AppendInt(b, int64(t.Minute()), 10)
487
488 return string(b)
489 }
490
491
492 func (ewo *ewo) FmtTimeMedium(t time.Time) string {
493
494 b := make([]byte, 0, 32)
495
496 if t.Hour() < 10 {
497 b = append(b, '0')
498 }
499
500 b = strconv.AppendInt(b, int64(t.Hour()), 10)
501 b = append(b, ewo.timeSeparator...)
502
503 if t.Minute() < 10 {
504 b = append(b, '0')
505 }
506
507 b = strconv.AppendInt(b, int64(t.Minute()), 10)
508 b = append(b, ewo.timeSeparator...)
509
510 if t.Second() < 10 {
511 b = append(b, '0')
512 }
513
514 b = strconv.AppendInt(b, int64(t.Second()), 10)
515
516 return string(b)
517 }
518
519
520 func (ewo *ewo) FmtTimeLong(t time.Time) string {
521
522 b := make([]byte, 0, 32)
523
524 if t.Hour() < 10 {
525 b = append(b, '0')
526 }
527
528 b = strconv.AppendInt(b, int64(t.Hour()), 10)
529 b = append(b, ewo.timeSeparator...)
530
531 if t.Minute() < 10 {
532 b = append(b, '0')
533 }
534
535 b = strconv.AppendInt(b, int64(t.Minute()), 10)
536 b = append(b, ewo.timeSeparator...)
537
538 if t.Second() < 10 {
539 b = append(b, '0')
540 }
541
542 b = strconv.AppendInt(b, int64(t.Second()), 10)
543 b = append(b, []byte{0x20}...)
544
545 tz, _ := t.Zone()
546 b = append(b, tz...)
547
548 return string(b)
549 }
550
551
552 func (ewo *ewo) FmtTimeFull(t time.Time) string {
553
554 b := make([]byte, 0, 32)
555
556 if t.Hour() < 10 {
557 b = append(b, '0')
558 }
559
560 b = strconv.AppendInt(b, int64(t.Hour()), 10)
561 b = append(b, ewo.timeSeparator...)
562
563 if t.Minute() < 10 {
564 b = append(b, '0')
565 }
566
567 b = strconv.AppendInt(b, int64(t.Minute()), 10)
568 b = append(b, ewo.timeSeparator...)
569
570 if t.Second() < 10 {
571 b = append(b, '0')
572 }
573
574 b = strconv.AppendInt(b, int64(t.Second()), 10)
575 b = append(b, []byte{0x20}...)
576
577 tz, _ := t.Zone()
578
579 if btz, ok := ewo.timezones[tz]; ok {
580 b = append(b, btz...)
581 } else {
582 b = append(b, tz...)
583 }
584
585 return string(b)
586 }
587
View as plain text