1 package naq
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 naq 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 &naq{
45 locale: "naq",
46 pluralsCardinal: []locales.PluralRule{2, 3, 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", "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", "$", "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", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"},
52 monthsNarrow: []string{"", "J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"},
53 monthsWide: []string{"", "ǃKhanni", "ǃKhanǀgôab", "ǀKhuuǁkhâb", "ǃHôaǂkhaib", "ǃKhaitsâb", "Gamaǀaeb", "ǂKhoesaob", "Aoǁkhuumûǁkhâb", "Taraǀkhuumûǁkhâb", "ǂNûǁnâiseb", "ǀHooǂgaeb", "Hôasoreǁkhâb"},
54 daysAbbreviated: []string{"Son", "Ma", "De", "Wu", "Do", "Fr", "Sat"},
55 daysNarrow: []string{"S", "M", "E", "W", "D", "F", "A"},
56 daysWide: []string{"Sontaxtsees", "Mantaxtsees", "Denstaxtsees", "Wunstaxtsees", "Dondertaxtsees", "Fraitaxtsees", "Satertaxtsees"},
57 periodsAbbreviated: []string{"ǁgoagas", "ǃuias"},
58 periodsWide: []string{"ǁgoagas", "ǃuias"},
59 erasAbbreviated: []string{"BC", "AD"},
60 erasNarrow: []string{"", ""},
61 erasWide: []string{"Xristub aiǃâ", "Xristub khaoǃgâ"},
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 (naq *naq) Locale() string {
68 return naq.locale
69 }
70
71
72 func (naq *naq) PluralsCardinal() []locales.PluralRule {
73 return naq.pluralsCardinal
74 }
75
76
77 func (naq *naq) PluralsOrdinal() []locales.PluralRule {
78 return naq.pluralsOrdinal
79 }
80
81
82 func (naq *naq) PluralsRange() []locales.PluralRule {
83 return naq.pluralsRange
84 }
85
86
87 func (naq *naq) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
88
89 n := math.Abs(num)
90
91 if n == 1 {
92 return locales.PluralRuleOne
93 } else if n == 2 {
94 return locales.PluralRuleTwo
95 }
96
97 return locales.PluralRuleOther
98 }
99
100
101 func (naq *naq) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
102 return locales.PluralRuleUnknown
103 }
104
105
106 func (naq *naq) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
107 return locales.PluralRuleUnknown
108 }
109
110
111 func (naq *naq) MonthAbbreviated(month time.Month) string {
112 return naq.monthsAbbreviated[month]
113 }
114
115
116 func (naq *naq) MonthsAbbreviated() []string {
117 return naq.monthsAbbreviated[1:]
118 }
119
120
121 func (naq *naq) MonthNarrow(month time.Month) string {
122 return naq.monthsNarrow[month]
123 }
124
125
126 func (naq *naq) MonthsNarrow() []string {
127 return naq.monthsNarrow[1:]
128 }
129
130
131 func (naq *naq) MonthWide(month time.Month) string {
132 return naq.monthsWide[month]
133 }
134
135
136 func (naq *naq) MonthsWide() []string {
137 return naq.monthsWide[1:]
138 }
139
140
141 func (naq *naq) WeekdayAbbreviated(weekday time.Weekday) string {
142 return naq.daysAbbreviated[weekday]
143 }
144
145
146 func (naq *naq) WeekdaysAbbreviated() []string {
147 return naq.daysAbbreviated
148 }
149
150
151 func (naq *naq) WeekdayNarrow(weekday time.Weekday) string {
152 return naq.daysNarrow[weekday]
153 }
154
155
156 func (naq *naq) WeekdaysNarrow() []string {
157 return naq.daysNarrow
158 }
159
160
161 func (naq *naq) WeekdayShort(weekday time.Weekday) string {
162 return naq.daysShort[weekday]
163 }
164
165
166 func (naq *naq) WeekdaysShort() []string {
167 return naq.daysShort
168 }
169
170
171 func (naq *naq) WeekdayWide(weekday time.Weekday) string {
172 return naq.daysWide[weekday]
173 }
174
175
176 func (naq *naq) WeekdaysWide() []string {
177 return naq.daysWide
178 }
179
180
181 func (naq *naq) Decimal() string {
182 return naq.decimal
183 }
184
185
186 func (naq *naq) Group() string {
187 return naq.group
188 }
189
190
191 func (naq *naq) Minus() string {
192 return naq.minus
193 }
194
195
196 func (naq *naq) FmtNumber(num float64, v uint64) string {
197
198 return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
199 }
200
201
202
203 func (naq *naq) FmtPercent(num float64, v uint64) string {
204 return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
205 }
206
207
208 func (naq *naq) FmtCurrency(num float64, v uint64, currency currency.Type) string {
209
210 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
211 symbol := naq.currencies[currency]
212 l := len(s) + len(symbol) + 0
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, naq.decimal[0])
221 inWhole = true
222 continue
223 }
224
225 if inWhole {
226 if count == 3 {
227 b = append(b, naq.group[0])
228 count = 1
229 } else {
230 count++
231 }
232 }
233
234 b = append(b, s[i])
235 }
236
237 for j := len(symbol) - 1; j >= 0; j-- {
238 b = append(b, symbol[j])
239 }
240
241 if num < 0 {
242 b = append(b, naq.minus[0])
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 if int(v) < 2 {
251
252 if v == 0 {
253 b = append(b, naq.decimal...)
254 }
255
256 for i := 0; i < 2-int(v); i++ {
257 b = append(b, '0')
258 }
259 }
260
261 return string(b)
262 }
263
264
265
266 func (naq *naq) FmtAccounting(num float64, v uint64, currency currency.Type) string {
267
268 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
269 symbol := naq.currencies[currency]
270 l := len(s) + len(symbol) + 0
271 count := 0
272 inWhole := v == 0
273 b := make([]byte, 0, l)
274
275 for i := len(s) - 1; i >= 0; i-- {
276
277 if s[i] == '.' {
278 b = append(b, naq.decimal[0])
279 inWhole = true
280 continue
281 }
282
283 if inWhole {
284 if count == 3 {
285 b = append(b, naq.group[0])
286 count = 1
287 } else {
288 count++
289 }
290 }
291
292 b = append(b, s[i])
293 }
294
295 if num < 0 {
296
297 for j := len(symbol) - 1; j >= 0; j-- {
298 b = append(b, symbol[j])
299 }
300
301 b = append(b, naq.minus[0])
302
303 } else {
304
305 for j := len(symbol) - 1; j >= 0; j-- {
306 b = append(b, symbol[j])
307 }
308
309 }
310
311
312 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
313 b[i], b[j] = b[j], b[i]
314 }
315
316 if int(v) < 2 {
317
318 if v == 0 {
319 b = append(b, naq.decimal...)
320 }
321
322 for i := 0; i < 2-int(v); i++ {
323 b = append(b, '0')
324 }
325 }
326
327 return string(b)
328 }
329
330
331 func (naq *naq) FmtDateShort(t time.Time) string {
332
333 b := make([]byte, 0, 32)
334
335 if t.Day() < 10 {
336 b = append(b, '0')
337 }
338
339 b = strconv.AppendInt(b, int64(t.Day()), 10)
340 b = append(b, []byte{0x2f}...)
341
342 if t.Month() < 10 {
343 b = append(b, '0')
344 }
345
346 b = strconv.AppendInt(b, int64(t.Month()), 10)
347
348 b = append(b, []byte{0x2f}...)
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
360 func (naq *naq) FmtDateMedium(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, naq.monthsAbbreviated[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
379 func (naq *naq) FmtDateLong(t time.Time) string {
380
381 b := make([]byte, 0, 32)
382
383 b = strconv.AppendInt(b, int64(t.Day()), 10)
384 b = append(b, []byte{0x20}...)
385 b = append(b, naq.monthsWide[t.Month()]...)
386 b = append(b, []byte{0x20}...)
387
388 if t.Year() > 0 {
389 b = strconv.AppendInt(b, int64(t.Year()), 10)
390 } else {
391 b = strconv.AppendInt(b, int64(-t.Year()), 10)
392 }
393
394 return string(b)
395 }
396
397
398 func (naq *naq) FmtDateFull(t time.Time) string {
399
400 b := make([]byte, 0, 32)
401
402 b = append(b, naq.daysWide[t.Weekday()]...)
403 b = append(b, []byte{0x2c, 0x20}...)
404 b = strconv.AppendInt(b, int64(t.Day()), 10)
405 b = append(b, []byte{0x20}...)
406 b = append(b, naq.monthsWide[t.Month()]...)
407 b = append(b, []byte{0x20}...)
408
409 if t.Year() > 0 {
410 b = strconv.AppendInt(b, int64(t.Year()), 10)
411 } else {
412 b = strconv.AppendInt(b, int64(-t.Year()), 10)
413 }
414
415 return string(b)
416 }
417
418
419 func (naq *naq) FmtTimeShort(t time.Time) string {
420
421 b := make([]byte, 0, 32)
422
423 h := t.Hour()
424
425 if h > 12 {
426 h -= 12
427 }
428
429 b = strconv.AppendInt(b, int64(h), 10)
430 b = append(b, naq.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, []byte{0x20}...)
438
439 if t.Hour() < 12 {
440 b = append(b, naq.periodsAbbreviated[0]...)
441 } else {
442 b = append(b, naq.periodsAbbreviated[1]...)
443 }
444
445 return string(b)
446 }
447
448
449 func (naq *naq) FmtTimeMedium(t time.Time) string {
450
451 b := make([]byte, 0, 32)
452
453 h := t.Hour()
454
455 if h > 12 {
456 h -= 12
457 }
458
459 b = strconv.AppendInt(b, int64(h), 10)
460 b = append(b, naq.timeSeparator...)
461
462 if t.Minute() < 10 {
463 b = append(b, '0')
464 }
465
466 b = strconv.AppendInt(b, int64(t.Minute()), 10)
467 b = append(b, naq.timeSeparator...)
468
469 if t.Second() < 10 {
470 b = append(b, '0')
471 }
472
473 b = strconv.AppendInt(b, int64(t.Second()), 10)
474 b = append(b, []byte{0x20}...)
475
476 if t.Hour() < 12 {
477 b = append(b, naq.periodsAbbreviated[0]...)
478 } else {
479 b = append(b, naq.periodsAbbreviated[1]...)
480 }
481
482 return string(b)
483 }
484
485
486 func (naq *naq) FmtTimeLong(t time.Time) string {
487
488 b := make([]byte, 0, 32)
489
490 h := t.Hour()
491
492 if h > 12 {
493 h -= 12
494 }
495
496 b = strconv.AppendInt(b, int64(h), 10)
497 b = append(b, naq.timeSeparator...)
498
499 if t.Minute() < 10 {
500 b = append(b, '0')
501 }
502
503 b = strconv.AppendInt(b, int64(t.Minute()), 10)
504 b = append(b, naq.timeSeparator...)
505
506 if t.Second() < 10 {
507 b = append(b, '0')
508 }
509
510 b = strconv.AppendInt(b, int64(t.Second()), 10)
511 b = append(b, []byte{0x20}...)
512
513 if t.Hour() < 12 {
514 b = append(b, naq.periodsAbbreviated[0]...)
515 } else {
516 b = append(b, naq.periodsAbbreviated[1]...)
517 }
518
519 b = append(b, []byte{0x20}...)
520
521 tz, _ := t.Zone()
522 b = append(b, tz...)
523
524 return string(b)
525 }
526
527
528 func (naq *naq) FmtTimeFull(t time.Time) string {
529
530 b := make([]byte, 0, 32)
531
532 h := t.Hour()
533
534 if h > 12 {
535 h -= 12
536 }
537
538 b = strconv.AppendInt(b, int64(h), 10)
539 b = append(b, naq.timeSeparator...)
540
541 if t.Minute() < 10 {
542 b = append(b, '0')
543 }
544
545 b = strconv.AppendInt(b, int64(t.Minute()), 10)
546 b = append(b, naq.timeSeparator...)
547
548 if t.Second() < 10 {
549 b = append(b, '0')
550 }
551
552 b = strconv.AppendInt(b, int64(t.Second()), 10)
553 b = append(b, []byte{0x20}...)
554
555 if t.Hour() < 12 {
556 b = append(b, naq.periodsAbbreviated[0]...)
557 } else {
558 b = append(b, naq.periodsAbbreviated[1]...)
559 }
560
561 b = append(b, []byte{0x20}...)
562
563 tz, _ := t.Zone()
564
565 if btz, ok := naq.timezones[tz]; ok {
566 b = append(b, btz...)
567 } else {
568 b = append(b, tz...)
569 }
570
571 return string(b)
572 }
573
View as plain text