1 package luy
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 luy 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 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
43 func New() locales.Translator {
44 return &luy{
45 locale: "luy",
46 pluralsCardinal: nil,
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", "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", "Ksh", "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"},
51 monthsAbbreviated: []string{"", "Jan", "Feb", "Mar", "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{"", "Januari", "Februari", "Machi", "Aprili", "Mei", "Juni", "Julai", "Agosti", "Septemba", "Oktoba", "Novemba", "Desemba"},
54 daysAbbreviated: []string{"J2", "J3", "J4", "J5", "Al", "Ij", "J1"},
55 daysNarrow: []string{"S", "M", "T", "W", "T", "F", "S"},
56 daysWide: []string{"Jumapiri", "Jumatatu", "Jumanne", "Jumatano", "Murwa wa Kanne", "Murwa wa Katano", "Jumamosi"},
57 periodsAbbreviated: []string{"a.m.", "p.m."},
58 periodsWide: []string{"a.m.", "p.m."},
59 erasAbbreviated: []string{"BC", "AD"},
60 erasNarrow: []string{"", ""},
61 erasWide: []string{"Imberi ya Kuuza Kwa", "Muhiga Kuvita Kuuza"},
62 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", "∅∅∅": "∅∅∅"},
63 }
64 }
65
66
67 func (luy *luy) Locale() string {
68 return luy.locale
69 }
70
71
72 func (luy *luy) PluralsCardinal() []locales.PluralRule {
73 return luy.pluralsCardinal
74 }
75
76
77 func (luy *luy) PluralsOrdinal() []locales.PluralRule {
78 return luy.pluralsOrdinal
79 }
80
81
82 func (luy *luy) PluralsRange() []locales.PluralRule {
83 return luy.pluralsRange
84 }
85
86
87 func (luy *luy) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
88 return locales.PluralRuleUnknown
89 }
90
91
92 func (luy *luy) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
93 return locales.PluralRuleUnknown
94 }
95
96
97 func (luy *luy) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
98 return locales.PluralRuleUnknown
99 }
100
101
102 func (luy *luy) MonthAbbreviated(month time.Month) string {
103 return luy.monthsAbbreviated[month]
104 }
105
106
107 func (luy *luy) MonthsAbbreviated() []string {
108 return luy.monthsAbbreviated[1:]
109 }
110
111
112 func (luy *luy) MonthNarrow(month time.Month) string {
113 return luy.monthsNarrow[month]
114 }
115
116
117 func (luy *luy) MonthsNarrow() []string {
118 return luy.monthsNarrow[1:]
119 }
120
121
122 func (luy *luy) MonthWide(month time.Month) string {
123 return luy.monthsWide[month]
124 }
125
126
127 func (luy *luy) MonthsWide() []string {
128 return luy.monthsWide[1:]
129 }
130
131
132 func (luy *luy) WeekdayAbbreviated(weekday time.Weekday) string {
133 return luy.daysAbbreviated[weekday]
134 }
135
136
137 func (luy *luy) WeekdaysAbbreviated() []string {
138 return luy.daysAbbreviated
139 }
140
141
142 func (luy *luy) WeekdayNarrow(weekday time.Weekday) string {
143 return luy.daysNarrow[weekday]
144 }
145
146
147 func (luy *luy) WeekdaysNarrow() []string {
148 return luy.daysNarrow
149 }
150
151
152 func (luy *luy) WeekdayShort(weekday time.Weekday) string {
153 return luy.daysShort[weekday]
154 }
155
156
157 func (luy *luy) WeekdaysShort() []string {
158 return luy.daysShort
159 }
160
161
162 func (luy *luy) WeekdayWide(weekday time.Weekday) string {
163 return luy.daysWide[weekday]
164 }
165
166
167 func (luy *luy) WeekdaysWide() []string {
168 return luy.daysWide
169 }
170
171
172 func (luy *luy) Decimal() string {
173 return luy.decimal
174 }
175
176
177 func (luy *luy) Group() string {
178 return luy.group
179 }
180
181
182 func (luy *luy) Minus() string {
183 return luy.minus
184 }
185
186
187 func (luy *luy) FmtNumber(num float64, v uint64) string {
188
189 return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
190 }
191
192
193
194 func (luy *luy) FmtPercent(num float64, v uint64) string {
195 return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
196 }
197
198
199 func (luy *luy) FmtCurrency(num float64, v uint64, currency currency.Type) string {
200
201 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
202 symbol := luy.currencies[currency]
203 l := len(s) + len(symbol) + 0
204 count := 0
205 inWhole := v == 0
206 b := make([]byte, 0, l)
207
208 for i := len(s) - 1; i >= 0; i-- {
209
210 if s[i] == '.' {
211 b = append(b, luy.decimal[0])
212 inWhole = true
213 continue
214 }
215
216 if inWhole {
217 if count == 3 {
218 b = append(b, luy.group[0])
219 count = 1
220 } else {
221 count++
222 }
223 }
224
225 b = append(b, s[i])
226 }
227
228 for j := len(symbol) - 1; j >= 0; j-- {
229 b = append(b, symbol[j])
230 }
231
232 if num < 0 {
233 b = append(b, luy.minus[0])
234 }
235
236
237 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
238 b[i], b[j] = b[j], b[i]
239 }
240
241 if int(v) < 2 {
242
243 if v == 0 {
244 b = append(b, luy.decimal...)
245 }
246
247 for i := 0; i < 2-int(v); i++ {
248 b = append(b, '0')
249 }
250 }
251
252 return string(b)
253 }
254
255
256
257 func (luy *luy) FmtAccounting(num float64, v uint64, currency currency.Type) string {
258
259 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
260 symbol := luy.currencies[currency]
261 l := len(s) + len(symbol) + 0
262 count := 0
263 inWhole := v == 0
264 b := make([]byte, 0, l)
265
266 for i := len(s) - 1; i >= 0; i-- {
267
268 if s[i] == '.' {
269 b = append(b, luy.decimal[0])
270 inWhole = true
271 continue
272 }
273
274 if inWhole {
275 if count == 3 {
276 b = append(b, luy.group[0])
277 count = 1
278 } else {
279 count++
280 }
281 }
282
283 b = append(b, s[i])
284 }
285
286 if num < 0 {
287
288 for j := len(symbol) - 1; j >= 0; j-- {
289 b = append(b, symbol[j])
290 }
291
292 b = append(b, luy.minus[0])
293
294 } else {
295
296 for j := len(symbol) - 1; j >= 0; j-- {
297 b = append(b, symbol[j])
298 }
299
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, luy.decimal...)
311 }
312
313 for i := 0; i < 2-int(v); i++ {
314 b = append(b, '0')
315 }
316 }
317
318 return string(b)
319 }
320
321
322 func (luy *luy) FmtDateShort(t time.Time) string {
323
324 b := make([]byte, 0, 32)
325
326 if t.Day() < 10 {
327 b = append(b, '0')
328 }
329
330 b = strconv.AppendInt(b, int64(t.Day()), 10)
331 b = append(b, []byte{0x2f}...)
332
333 if t.Month() < 10 {
334 b = append(b, '0')
335 }
336
337 b = strconv.AppendInt(b, int64(t.Month()), 10)
338
339 b = append(b, []byte{0x2f}...)
340
341 if t.Year() > 0 {
342 b = strconv.AppendInt(b, int64(t.Year()), 10)
343 } else {
344 b = strconv.AppendInt(b, int64(-t.Year()), 10)
345 }
346
347 return string(b)
348 }
349
350
351 func (luy *luy) FmtDateMedium(t time.Time) string {
352
353 b := make([]byte, 0, 32)
354
355 b = strconv.AppendInt(b, int64(t.Day()), 10)
356 b = append(b, []byte{0x20}...)
357 b = append(b, luy.monthsAbbreviated[t.Month()]...)
358 b = append(b, []byte{0x20}...)
359
360 if t.Year() > 0 {
361 b = strconv.AppendInt(b, int64(t.Year()), 10)
362 } else {
363 b = strconv.AppendInt(b, int64(-t.Year()), 10)
364 }
365
366 return string(b)
367 }
368
369
370 func (luy *luy) FmtDateLong(t time.Time) string {
371
372 b := make([]byte, 0, 32)
373
374 b = strconv.AppendInt(b, int64(t.Day()), 10)
375 b = append(b, []byte{0x20}...)
376 b = append(b, luy.monthsWide[t.Month()]...)
377 b = append(b, []byte{0x20}...)
378
379 if t.Year() > 0 {
380 b = strconv.AppendInt(b, int64(t.Year()), 10)
381 } else {
382 b = strconv.AppendInt(b, int64(-t.Year()), 10)
383 }
384
385 return string(b)
386 }
387
388
389 func (luy *luy) FmtDateFull(t time.Time) string {
390
391 b := make([]byte, 0, 32)
392
393 b = append(b, luy.daysWide[t.Weekday()]...)
394 b = append(b, []byte{0x2c, 0x20}...)
395 b = strconv.AppendInt(b, int64(t.Day()), 10)
396 b = append(b, []byte{0x20}...)
397 b = append(b, luy.monthsWide[t.Month()]...)
398 b = append(b, []byte{0x20}...)
399
400 if t.Year() > 0 {
401 b = strconv.AppendInt(b, int64(t.Year()), 10)
402 } else {
403 b = strconv.AppendInt(b, int64(-t.Year()), 10)
404 }
405
406 return string(b)
407 }
408
409
410 func (luy *luy) FmtTimeShort(t time.Time) string {
411
412 b := make([]byte, 0, 32)
413
414 if t.Hour() < 10 {
415 b = append(b, '0')
416 }
417
418 b = strconv.AppendInt(b, int64(t.Hour()), 10)
419 b = append(b, luy.timeSeparator...)
420
421 if t.Minute() < 10 {
422 b = append(b, '0')
423 }
424
425 b = strconv.AppendInt(b, int64(t.Minute()), 10)
426
427 return string(b)
428 }
429
430
431 func (luy *luy) FmtTimeMedium(t time.Time) string {
432
433 b := make([]byte, 0, 32)
434
435 if t.Hour() < 10 {
436 b = append(b, '0')
437 }
438
439 b = strconv.AppendInt(b, int64(t.Hour()), 10)
440 b = append(b, luy.timeSeparator...)
441
442 if t.Minute() < 10 {
443 b = append(b, '0')
444 }
445
446 b = strconv.AppendInt(b, int64(t.Minute()), 10)
447 b = append(b, luy.timeSeparator...)
448
449 if t.Second() < 10 {
450 b = append(b, '0')
451 }
452
453 b = strconv.AppendInt(b, int64(t.Second()), 10)
454
455 return string(b)
456 }
457
458
459 func (luy *luy) FmtTimeLong(t time.Time) string {
460
461 b := make([]byte, 0, 32)
462
463 if t.Hour() < 10 {
464 b = append(b, '0')
465 }
466
467 b = strconv.AppendInt(b, int64(t.Hour()), 10)
468 b = append(b, luy.timeSeparator...)
469
470 if t.Minute() < 10 {
471 b = append(b, '0')
472 }
473
474 b = strconv.AppendInt(b, int64(t.Minute()), 10)
475 b = append(b, luy.timeSeparator...)
476
477 if t.Second() < 10 {
478 b = append(b, '0')
479 }
480
481 b = strconv.AppendInt(b, int64(t.Second()), 10)
482 b = append(b, []byte{0x20}...)
483
484 tz, _ := t.Zone()
485 b = append(b, tz...)
486
487 return string(b)
488 }
489
490
491 func (luy *luy) FmtTimeFull(t time.Time) string {
492
493 b := make([]byte, 0, 32)
494
495 if t.Hour() < 10 {
496 b = append(b, '0')
497 }
498
499 b = strconv.AppendInt(b, int64(t.Hour()), 10)
500 b = append(b, luy.timeSeparator...)
501
502 if t.Minute() < 10 {
503 b = append(b, '0')
504 }
505
506 b = strconv.AppendInt(b, int64(t.Minute()), 10)
507 b = append(b, luy.timeSeparator...)
508
509 if t.Second() < 10 {
510 b = append(b, '0')
511 }
512
513 b = strconv.AppendInt(b, int64(t.Second()), 10)
514 b = append(b, []byte{0x20}...)
515
516 tz, _ := t.Zone()
517
518 if btz, ok := luy.timezones[tz]; ok {
519 b = append(b, btz...)
520 } else {
521 b = append(b, tz...)
522 }
523
524 return string(b)
525 }
526
View as plain text