1 package eo
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 eo 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 currencyPositivePrefix string
26 currencyPositiveSuffix string
27 currencyNegativePrefix string
28 currencyNegativeSuffix string
29 monthsAbbreviated []string
30 monthsNarrow []string
31 monthsWide []string
32 daysAbbreviated []string
33 daysNarrow []string
34 daysShort []string
35 daysWide []string
36 periodsAbbreviated []string
37 periodsNarrow []string
38 periodsShort []string
39 periodsWide []string
40 erasAbbreviated []string
41 erasNarrow []string
42 erasWide []string
43 timezones map[string]string
44 }
45
46
47 func New() locales.Translator {
48 return &eo{
49 locale: "eo",
50 pluralsCardinal: []locales.PluralRule{2, 6},
51 pluralsOrdinal: nil,
52 pluralsRange: nil,
53 decimal: ",",
54 group: " ",
55 minus: "−",
56 percent: "%",
57 perMille: "‰",
58 timeSeparator: ":",
59 inifinity: "∞",
60 currencies: []string{"ADP", "AED", "AFA", "AFN", "ALK", "ALL", "AMD", "ANG", "AOA", "AOK", "AON", "AOR", "ARA", "ARL", "ARM", "ARP", "ARS", "ATS", "AU$", "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", "R$", "BRN", "BRR", "BRZ", "BSD", "BTN", "BUK", "BWP", "BYB", "BYN", "BYR", "BZD", "CA$", "CDF", "CHE", "CHF", "CHW", "CLE", "CLF", "CLP", "CNH", "CNX", "CN¥", "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", "€", "FIM", "FJD", "FKP", "FRF", "£", "GEK", "GEL", "GHC", "GHS", "GIP", "GMD", "GNF", "GNS", "GQE", "GRD", "GTQ", "GWE", "GWP", "GYD", "HK$", "HNL", "HRD", "HRK", "HTG", "HUF", "IDR", "IEP", "ILP", "ILR", "ILS", "₹", "IQD", "IRR", "ISJ", "ISK", "ITL", "JMD", "JOD", "JP¥", "KES", "KGS", "KHR", "KMF", "KPW", "KRH", "KRO", "₩", "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", "MX$", "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", "฿", "TJR", "TJS", "TMM", "TMT", "TND", "TOP", "TPE", "TRL", "₺", "TTD", "NT$", "TZS", "UAH", "UAK", "UGS", "UGX", "US$", "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"},
61 currencyPositivePrefix: " ",
62 currencyPositiveSuffix: "K",
63 currencyNegativePrefix: " ",
64 currencyNegativeSuffix: "K",
65 monthsAbbreviated: []string{"", "jan", "feb", "mar", "apr", "maj", "jun", "jul", "aŭg", "sep", "okt", "nov", "dec"},
66 monthsNarrow: []string{"", "J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"},
67 monthsWide: []string{"", "januaro", "februaro", "marto", "aprilo", "majo", "junio", "julio", "aŭgusto", "septembro", "oktobro", "novembro", "decembro"},
68 daysAbbreviated: []string{"di", "lu", "ma", "me", "ĵa", "ve", "sa"},
69 daysNarrow: []string{"D", "L", "M", "M", "Ĵ", "V", "S"},
70 daysWide: []string{"dimanĉo", "lundo", "mardo", "merkredo", "ĵaŭdo", "vendredo", "sabato"},
71 periodsAbbreviated: []string{"atm", "ptm"},
72 periodsNarrow: []string{"a", "p"},
73 periodsWide: []string{"atm", "ptm"},
74 erasAbbreviated: []string{"aK", "pK"},
75 erasNarrow: []string{"aK", "pK"},
76 erasWide: []string{"aK", "pK"},
77 timezones: map[string]string{"ACDT": "centra aŭstralia somera tempo", "ACST": "centra aŭstralia norma tempo", "ACWDT": "centrokcidenta aŭstralia somera tempo", "ACWST": "centrokcidenta aŭstralia norma tempo", "ADT": "atlantika nord-amerika somera tempo", "AEDT": "orienta aŭstralia somera tempo", "AEST": "orienta aŭstralia norma tempo", "AKDT": "AKDT", "AKST": "AKST", "ARST": "ARST", "ART": "ART", "AST": "atlantika nord-amerika norma tempo", "AWDT": "okcidenta aŭstralia somera tempo", "AWST": "okcidenta aŭstralia norma tempo", "BOT": "BOT", "BT": "BT", "CAT": "centra afrika tempo", "CDT": "centra nord-amerika somera tempo", "CHADT": "CHADT", "CHAST": "CHAST", "CLST": "CLST", "CLT": "CLT", "COST": "COST", "COT": "COT", "CST": "centra nord-amerika norma tempo", "ChST": "ChST", "EAT": "orienta afrika tempo", "ECT": "ECT", "EDT": "orienta nord-amerika somera tempo", "EST": "orienta nord-amerika norma tempo", "GFT": "GFT", "GMT": "universala tempo kunordigita", "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": "barata tempo", "JDT": "japana somera tempo", "JST": "japana norma tempo", "LHDT": "LHDT", "LHST": "LHST", "MDT": "monta nord-amerika somera tempo", "MESZ": "centra eŭropa somera tempo", "MEZ": "centra eŭropa norma tempo", "MST": "monta nord-amerika norma tempo", "MYT": "MYT", "NZDT": "NZDT", "NZST": "NZST", "OESZ": "orienta eŭropa somera tempo", "OEZ": "orienta eŭropa norma tempo", "PDT": "pacifika nord-amerika somera tempo", "PST": "pacifika nord-amerika norma tempo", "SAST": "suda afrika tempo", "SGT": "SGT", "SRT": "SRT", "TMST": "TMST", "TMT": "TMT", "UYST": "UYST", "UYT": "UYT", "VET": "VET", "WARST": "WARST", "WART": "WART", "WAST": "okcidenta afrika somera tempo", "WAT": "okcidenta afrika norma tempo", "WESZ": "okcidenta eŭropa somera tempo", "WEZ": "okcidenta eŭropa norma tempo", "WIB": "okcidenta indonezia tempo", "WIT": "orienta indonezia tempo", "WITA": "centra indonezia tempo", "∅∅∅": "∅∅∅"},
78 }
79 }
80
81
82 func (eo *eo) Locale() string {
83 return eo.locale
84 }
85
86
87 func (eo *eo) PluralsCardinal() []locales.PluralRule {
88 return eo.pluralsCardinal
89 }
90
91
92 func (eo *eo) PluralsOrdinal() []locales.PluralRule {
93 return eo.pluralsOrdinal
94 }
95
96
97 func (eo *eo) PluralsRange() []locales.PluralRule {
98 return eo.pluralsRange
99 }
100
101
102 func (eo *eo) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
103
104 n := math.Abs(num)
105
106 if n == 1 {
107 return locales.PluralRuleOne
108 }
109
110 return locales.PluralRuleOther
111 }
112
113
114 func (eo *eo) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
115 return locales.PluralRuleUnknown
116 }
117
118
119 func (eo *eo) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
120 return locales.PluralRuleUnknown
121 }
122
123
124 func (eo *eo) MonthAbbreviated(month time.Month) string {
125 return eo.monthsAbbreviated[month]
126 }
127
128
129 func (eo *eo) MonthsAbbreviated() []string {
130 return eo.monthsAbbreviated[1:]
131 }
132
133
134 func (eo *eo) MonthNarrow(month time.Month) string {
135 return eo.monthsNarrow[month]
136 }
137
138
139 func (eo *eo) MonthsNarrow() []string {
140 return eo.monthsNarrow[1:]
141 }
142
143
144 func (eo *eo) MonthWide(month time.Month) string {
145 return eo.monthsWide[month]
146 }
147
148
149 func (eo *eo) MonthsWide() []string {
150 return eo.monthsWide[1:]
151 }
152
153
154 func (eo *eo) WeekdayAbbreviated(weekday time.Weekday) string {
155 return eo.daysAbbreviated[weekday]
156 }
157
158
159 func (eo *eo) WeekdaysAbbreviated() []string {
160 return eo.daysAbbreviated
161 }
162
163
164 func (eo *eo) WeekdayNarrow(weekday time.Weekday) string {
165 return eo.daysNarrow[weekday]
166 }
167
168
169 func (eo *eo) WeekdaysNarrow() []string {
170 return eo.daysNarrow
171 }
172
173
174 func (eo *eo) WeekdayShort(weekday time.Weekday) string {
175 return eo.daysShort[weekday]
176 }
177
178
179 func (eo *eo) WeekdaysShort() []string {
180 return eo.daysShort
181 }
182
183
184 func (eo *eo) WeekdayWide(weekday time.Weekday) string {
185 return eo.daysWide[weekday]
186 }
187
188
189 func (eo *eo) WeekdaysWide() []string {
190 return eo.daysWide
191 }
192
193
194 func (eo *eo) Decimal() string {
195 return eo.decimal
196 }
197
198
199 func (eo *eo) Group() string {
200 return eo.group
201 }
202
203
204 func (eo *eo) Minus() string {
205 return eo.minus
206 }
207
208
209 func (eo *eo) FmtNumber(num float64, v uint64) string {
210
211 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
212 l := len(s) + 4 + 2*len(s[:len(s)-int(v)-1])/3
213 count := 0
214 inWhole := v == 0
215 b := make([]byte, 0, l)
216
217 for i := len(s) - 1; i >= 0; i-- {
218
219 if s[i] == '.' {
220 b = append(b, eo.decimal[0])
221 inWhole = true
222 continue
223 }
224
225 if inWhole {
226 if count == 3 {
227 for j := len(eo.group) - 1; j >= 0; j-- {
228 b = append(b, eo.group[j])
229 }
230 count = 1
231 } else {
232 count++
233 }
234 }
235
236 b = append(b, s[i])
237 }
238
239 if num < 0 {
240 for j := len(eo.minus) - 1; j >= 0; j-- {
241 b = append(b, eo.minus[j])
242 }
243 }
244
245
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]
248 }
249
250 return string(b)
251 }
252
253
254
255 func (eo *eo) FmtPercent(num float64, v uint64) string {
256 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
257 l := len(s) + 5
258 b := make([]byte, 0, l)
259
260 for i := len(s) - 1; i >= 0; i-- {
261
262 if s[i] == '.' {
263 b = append(b, eo.decimal[0])
264 continue
265 }
266
267 b = append(b, s[i])
268 }
269
270 if num < 0 {
271 for j := len(eo.minus) - 1; j >= 0; j-- {
272 b = append(b, eo.minus[j])
273 }
274 }
275
276
277 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
278 b[i], b[j] = b[j], b[i]
279 }
280
281 b = append(b, eo.percent...)
282
283 return string(b)
284 }
285
286
287 func (eo *eo) FmtCurrency(num float64, v uint64, currency currency.Type) string {
288
289 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
290 symbol := eo.currencies[currency]
291 l := len(s) + len(symbol) + 7
292
293 b := make([]byte, 0, l)
294
295 for i := len(s) - 1; i >= 0; i-- {
296
297 if s[i] == '.' {
298 b = append(b, eo.decimal[0])
299 continue
300 }
301
302 b = append(b, s[i])
303 }
304
305 for j := len(symbol) - 1; j >= 0; j-- {
306 b = append(b, symbol[j])
307 }
308
309 for j := len(eo.currencyPositivePrefix) - 1; j >= 0; j-- {
310 b = append(b, eo.currencyPositivePrefix[j])
311 }
312
313 if num < 0 {
314 for j := len(eo.minus) - 1; j >= 0; j-- {
315 b = append(b, eo.minus[j])
316 }
317 }
318
319
320 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
321 b[i], b[j] = b[j], b[i]
322 }
323
324 b = append(b, eo.currencyPositiveSuffix...)
325
326 return string(b)
327 }
328
329
330
331 func (eo *eo) FmtAccounting(num float64, v uint64, currency currency.Type) string {
332
333 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
334 symbol := eo.currencies[currency]
335 l := len(s) + len(symbol) + 7
336
337 b := make([]byte, 0, l)
338
339 for i := len(s) - 1; i >= 0; i-- {
340
341 if s[i] == '.' {
342 b = append(b, eo.decimal[0])
343 continue
344 }
345
346 b = append(b, s[i])
347 }
348
349 if num < 0 {
350
351 for j := len(symbol) - 1; j >= 0; j-- {
352 b = append(b, symbol[j])
353 }
354
355 for j := len(eo.currencyNegativePrefix) - 1; j >= 0; j-- {
356 b = append(b, eo.currencyNegativePrefix[j])
357 }
358
359 for j := len(eo.minus) - 1; j >= 0; j-- {
360 b = append(b, eo.minus[j])
361 }
362
363 } else {
364
365 for j := len(symbol) - 1; j >= 0; j-- {
366 b = append(b, symbol[j])
367 }
368
369 for j := len(eo.currencyPositivePrefix) - 1; j >= 0; j-- {
370 b = append(b, eo.currencyPositivePrefix[j])
371 }
372
373 }
374
375
376 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
377 b[i], b[j] = b[j], b[i]
378 }
379
380 if num < 0 {
381 b = append(b, eo.currencyNegativeSuffix...)
382 } else {
383
384 b = append(b, eo.currencyPositiveSuffix...)
385 }
386
387 return string(b)
388 }
389
390
391 func (eo *eo) FmtDateShort(t time.Time) string {
392
393 b := make([]byte, 0, 32)
394
395 if t.Year() > 9 {
396 b = append(b, strconv.Itoa(t.Year())[2:]...)
397 } else {
398 b = append(b, strconv.Itoa(t.Year())[1:]...)
399 }
400
401 b = append(b, []byte{0x2d}...)
402
403 if t.Month() < 10 {
404 b = append(b, '0')
405 }
406
407 b = strconv.AppendInt(b, int64(t.Month()), 10)
408
409 b = append(b, []byte{0x2d}...)
410
411 if t.Day() < 10 {
412 b = append(b, '0')
413 }
414
415 b = strconv.AppendInt(b, int64(t.Day()), 10)
416
417 return string(b)
418 }
419
420
421 func (eo *eo) FmtDateMedium(t time.Time) string {
422
423 b := make([]byte, 0, 32)
424
425 if t.Year() > 0 {
426 b = strconv.AppendInt(b, int64(t.Year()), 10)
427 } else {
428 b = strconv.AppendInt(b, int64(-t.Year()), 10)
429 }
430
431 b = append(b, []byte{0x2d}...)
432 b = append(b, eo.monthsAbbreviated[t.Month()]...)
433 b = append(b, []byte{0x2d}...)
434
435 if t.Day() < 10 {
436 b = append(b, '0')
437 }
438
439 b = strconv.AppendInt(b, int64(t.Day()), 10)
440
441 return string(b)
442 }
443
444
445 func (eo *eo) FmtDateLong(t time.Time) string {
446
447 b := make([]byte, 0, 32)
448
449 if t.Year() > 0 {
450 b = strconv.AppendInt(b, int64(t.Year()), 10)
451 } else {
452 b = strconv.AppendInt(b, int64(-t.Year()), 10)
453 }
454
455 b = append(b, []byte{0x2d}...)
456 b = append(b, eo.monthsWide[t.Month()]...)
457 b = append(b, []byte{0x2d}...)
458
459 if t.Day() < 10 {
460 b = append(b, '0')
461 }
462
463 b = strconv.AppendInt(b, int64(t.Day()), 10)
464
465 return string(b)
466 }
467
468
469 func (eo *eo) FmtDateFull(t time.Time) string {
470
471 b := make([]byte, 0, 32)
472
473 b = append(b, eo.daysWide[t.Weekday()]...)
474 b = append(b, []byte{0x2c, 0x20}...)
475 b = strconv.AppendInt(b, int64(t.Day()), 10)
476 b = append(b, []byte{0x2d, 0x61}...)
477 b = append(b, []byte{0x20, 0x64, 0x65}...)
478 b = append(b, []byte{0x20}...)
479 b = append(b, eo.monthsWide[t.Month()]...)
480 b = append(b, []byte{0x20}...)
481
482 if t.Year() > 0 {
483 b = strconv.AppendInt(b, int64(t.Year()), 10)
484 } else {
485 b = strconv.AppendInt(b, int64(-t.Year()), 10)
486 }
487
488 return string(b)
489 }
490
491
492 func (eo *eo) FmtTimeShort(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, eo.timeSeparator...)
502
503 if t.Minute() < 10 {
504 b = append(b, '0')
505 }
506
507 b = strconv.AppendInt(b, int64(t.Minute()), 10)
508
509 return string(b)
510 }
511
512
513 func (eo *eo) FmtTimeMedium(t time.Time) string {
514
515 b := make([]byte, 0, 32)
516
517 if t.Hour() < 10 {
518 b = append(b, '0')
519 }
520
521 b = strconv.AppendInt(b, int64(t.Hour()), 10)
522 b = append(b, eo.timeSeparator...)
523
524 if t.Minute() < 10 {
525 b = append(b, '0')
526 }
527
528 b = strconv.AppendInt(b, int64(t.Minute()), 10)
529 b = append(b, eo.timeSeparator...)
530
531 if t.Second() < 10 {
532 b = append(b, '0')
533 }
534
535 b = strconv.AppendInt(b, int64(t.Second()), 10)
536
537 return string(b)
538 }
539
540
541 func (eo *eo) FmtTimeLong(t time.Time) string {
542
543 b := make([]byte, 0, 32)
544
545 if t.Hour() < 10 {
546 b = append(b, '0')
547 }
548
549 b = strconv.AppendInt(b, int64(t.Hour()), 10)
550 b = append(b, eo.timeSeparator...)
551
552 if t.Minute() < 10 {
553 b = append(b, '0')
554 }
555
556 b = strconv.AppendInt(b, int64(t.Minute()), 10)
557 b = append(b, eo.timeSeparator...)
558
559 if t.Second() < 10 {
560 b = append(b, '0')
561 }
562
563 b = strconv.AppendInt(b, int64(t.Second()), 10)
564 b = append(b, []byte{0x20}...)
565
566 tz, _ := t.Zone()
567 b = append(b, tz...)
568
569 return string(b)
570 }
571
572
573 func (eo *eo) FmtTimeFull(t time.Time) string {
574
575 b := make([]byte, 0, 32)
576
577 b = strconv.AppendInt(b, int64(t.Hour()), 10)
578 b = append(b, []byte{0x2d, 0x61}...)
579 b = append(b, []byte{0x20, 0x68, 0x6f, 0x72, 0x6f}...)
580 b = append(b, []byte{0x20, 0x6b, 0x61, 0x6a}...)
581 b = append(b, []byte{0x20}...)
582 b = strconv.AppendInt(b, int64(t.Minute()), 10)
583 b = append(b, eo.timeSeparator...)
584
585 if t.Second() < 10 {
586 b = append(b, '0')
587 }
588
589 b = strconv.AppendInt(b, int64(t.Second()), 10)
590 b = append(b, []byte{0x20}...)
591
592 tz, _ := t.Zone()
593
594 if btz, ok := eo.timezones[tz]; ok {
595 b = append(b, btz...)
596 } else {
597 b = append(b, tz...)
598 }
599
600 return string(b)
601 }
602
View as plain text