1package so
2
3import (
4	"math"
5	"strconv"
6	"time"
7
8	"github.com/go-playground/locales"
9	"github.com/go-playground/locales/currency"
10)
11
12type so 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 'so' locale
43func New() locales.Translator {
44	return &so{
45		locale:             "so",
46		pluralsCardinal:    []locales.PluralRule{2, 6},
47		pluralsOrdinal:     nil,
48		pluralsRange:       nil,
49		decimal:            ".",
50		group:              ",",
51		timeSeparator:      ":",
52		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", "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", "S", "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", "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"},
53		monthsAbbreviated:  []string{"", "Kob", "Lab", "Sad", "Afr", "Sha", "Lix", "Tod", "Sid", "Sag", "Tob", "KIT", "LIT"},
54		monthsNarrow:       []string{"", "K", "L", "S", "A", "S", "L", "T", "S", "S", "T", "K", "L"},
55		monthsWide:         []string{"", "Bisha Koobaad", "Bisha Labaad", "Bisha Saddexaad", "Bisha Afraad", "Bisha Shanaad", "Bisha Lixaad", "Bisha Todobaad", "Bisha Sideedaad", "Bisha Sagaalaad", "Bisha Tobnaad", "Bisha Kow iyo Tobnaad", "Bisha Laba iyo Tobnaad"},
56		daysAbbreviated:    []string{"Axd", "Isn", "Tal", "Arb", "Kha", "Jim", "Sab"},
57		daysNarrow:         []string{"A", "I", "T", "A", "Kh", "J", "S"},
58		daysShort:          []string{"Axd", "Isn", "Tal", "Arb", "Kha", "Jim", "Sab"},
59		daysWide:           []string{"Axad", "Isniin", "Talaado", "Arbaco", "Khamiis", "Jimco", "Sabti"},
60		periodsAbbreviated: []string{"sn.", "gn."},
61		periodsNarrow:      []string{"sn.", "gn."},
62		periodsWide:        []string{"sn.", "gn."},
63		erasAbbreviated:    []string{"CK", "CD"},
64		erasNarrow:         []string{"", ""},
65		erasWide:           []string{"CK", "CD"},
66		timezones:          map[string]string{"HNOG": "HNOG", "HKT": "HKT", "HNPMX": "HNPMX", "JDT": "JDT", "AKDT": "AKDT", "ACWST": "ACWST", "HAT": "HAT", "UYST": "UYST", "ChST": "ChST", "PDT": "PDT", "HEEG": "HEEG", "MESZ": "MESZ", "SRT": "SRT", "AEDT": "AEDT", "MST": "MST", "WEZ": "WEZ", "JST": "JST", "MYT": "MYT", "HNEG": "HNEG", "LHDT": "LHDT", "WAST": "WAST", "BT": "BT", "IST": "IST", "WARST": "WARST", "TMST": "TMST", "UYT": "UYT", "CHAST": "CHAST", "PST": "PST", "AST": "AST", "BOT": "BOT", "ECT": "ECT", "MEZ": "MEZ", "HEPM": "HEPM", "HNNOMX": "HNNOMX", "HEPMX": "HEPMX", "AEST": "AEST", "WESZ": "WESZ", "NZDT": "NZDT", "HENOMX": "HENOMX", "ART": "ART", "CDT": "CDT", "CAT": "CAT", "EAT": "EAT", "NZST": "NZST", "ACWDT": "ACWDT", "LHST": "LHST", "AWDT": "AWDT", "HEOG": "HEOG", "WIT": "WIT", "COT": "Waqtiyada Caadiga ah ee kolambiya", "OESZ": "OESZ", "WIB": "WIB", "GFT": "GFT", "ACDT": "ACDT", "HKST": "HKST", "CLT": "CLT", "OEZ": "OEZ", "HAST": "HAST", "EST": "EST", "WART": "WART", "COST": "Waqtiyada Xagaaga Kolambiya", "HECU": "HECU", "CST": "CST", "AWST": "AWST", "WITA": "WITA", "HNT": "HNT", "TMT": "TMT", "GYT": "GYT", "SAST": "SAST", "SGT": "SGT", "ACST": "ACST", "VET": "VET", "ADT": "ADT", "MDT": "MDT", "∅∅∅": "∅∅∅", "AKST": "AKST", "EDT": "EDT", "HNPM": "HNPM", "CLST": "CLST", "HADT": "HADT", "ARST": "ARST", "GMT": "GMT", "CHADT": "CHADT", "HNCU": "HNCU", "WAT": "WAT"},
67	}
68}
69
70// Locale returns the current translators string locale
71func (so *so) Locale() string {
72	return so.locale
73}
74
75// PluralsCardinal returns the list of cardinal plural rules associated with 'so'
76func (so *so) PluralsCardinal() []locales.PluralRule {
77	return so.pluralsCardinal
78}
79
80// PluralsOrdinal returns the list of ordinal plural rules associated with 'so'
81func (so *so) PluralsOrdinal() []locales.PluralRule {
82	return so.pluralsOrdinal
83}
84
85// PluralsRange returns the list of range plural rules associated with 'so'
86func (so *so) PluralsRange() []locales.PluralRule {
87	return so.pluralsRange
88}
89
90// CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'so'
91func (so *so) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
92
93	n := math.Abs(num)
94
95	if n == 1 {
96		return locales.PluralRuleOne
97	}
98
99	return locales.PluralRuleOther
100}
101
102// OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'so'
103func (so *so) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
104	return locales.PluralRuleUnknown
105}
106
107// RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'so'
108func (so *so) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
109	return locales.PluralRuleUnknown
110}
111
112// MonthAbbreviated returns the locales abbreviated month given the 'month' provided
113func (so *so) MonthAbbreviated(month time.Month) string {
114	return so.monthsAbbreviated[month]
115}
116
117// MonthsAbbreviated returns the locales abbreviated months
118func (so *so) MonthsAbbreviated() []string {
119	return so.monthsAbbreviated[1:]
120}
121
122// MonthNarrow returns the locales narrow month given the 'month' provided
123func (so *so) MonthNarrow(month time.Month) string {
124	return so.monthsNarrow[month]
125}
126
127// MonthsNarrow returns the locales narrow months
128func (so *so) MonthsNarrow() []string {
129	return so.monthsNarrow[1:]
130}
131
132// MonthWide returns the locales wide month given the 'month' provided
133func (so *so) MonthWide(month time.Month) string {
134	return so.monthsWide[month]
135}
136
137// MonthsWide returns the locales wide months
138func (so *so) MonthsWide() []string {
139	return so.monthsWide[1:]
140}
141
142// WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
143func (so *so) WeekdayAbbreviated(weekday time.Weekday) string {
144	return so.daysAbbreviated[weekday]
145}
146
147// WeekdaysAbbreviated returns the locales abbreviated weekdays
148func (so *so) WeekdaysAbbreviated() []string {
149	return so.daysAbbreviated
150}
151
152// WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
153func (so *so) WeekdayNarrow(weekday time.Weekday) string {
154	return so.daysNarrow[weekday]
155}
156
157// WeekdaysNarrow returns the locales narrow weekdays
158func (so *so) WeekdaysNarrow() []string {
159	return so.daysNarrow
160}
161
162// WeekdayShort returns the locales short weekday given the 'weekday' provided
163func (so *so) WeekdayShort(weekday time.Weekday) string {
164	return so.daysShort[weekday]
165}
166
167// WeekdaysShort returns the locales short weekdays
168func (so *so) WeekdaysShort() []string {
169	return so.daysShort
170}
171
172// WeekdayWide returns the locales wide weekday given the 'weekday' provided
173func (so *so) WeekdayWide(weekday time.Weekday) string {
174	return so.daysWide[weekday]
175}
176
177// WeekdaysWide returns the locales wide weekdays
178func (so *so) WeekdaysWide() []string {
179	return so.daysWide
180}
181
182// Decimal returns the decimal point of number
183func (so *so) Decimal() string {
184	return so.decimal
185}
186
187// Group returns the group of number
188func (so *so) Group() string {
189	return so.group
190}
191
192// Group returns the minus sign of number
193func (so *so) Minus() string {
194	return so.minus
195}
196
197// FmtNumber returns 'num' with digits/precision of 'v' for 'so' and handles both Whole and Real numbers based on 'v'
198func (so *so) FmtNumber(num float64, v uint64) string {
199
200	return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
201}
202
203// FmtPercent returns 'num' with digits/precision of 'v' for 'so' and handles both Whole and Real numbers based on 'v'
204// NOTE: 'num' passed into FmtPercent is assumed to be in percent already
205func (so *so) FmtPercent(num float64, v uint64) string {
206	return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
207}
208
209// FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'so'
210func (so *so) FmtCurrency(num float64, v uint64, currency currency.Type) string {
211
212	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
213	symbol := so.currencies[currency]
214	l := len(s) + len(symbol) + 1 + 1*len(s[:len(s)-int(v)-1])/3
215	count := 0
216	inWhole := v == 0
217	b := make([]byte, 0, l)
218
219	for i := len(s) - 1; i >= 0; i-- {
220
221		if s[i] == '.' {
222			b = append(b, so.decimal[0])
223			inWhole = true
224			continue
225		}
226
227		if inWhole {
228			if count == 3 {
229				b = append(b, so.group[0])
230				count = 1
231			} else {
232				count++
233			}
234		}
235
236		b = append(b, s[i])
237	}
238
239	for j := len(symbol) - 1; j >= 0; j-- {
240		b = append(b, symbol[j])
241	}
242
243	if num < 0 {
244		b = append(b, so.minus[0])
245	}
246
247	// reverse
248	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
249		b[i], b[j] = b[j], b[i]
250	}
251
252	if int(v) < 2 {
253
254		if v == 0 {
255			b = append(b, so.decimal...)
256		}
257
258		for i := 0; i < 2-int(v); i++ {
259			b = append(b, '0')
260		}
261	}
262
263	return string(b)
264}
265
266// FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'so'
267// in accounting notation.
268func (so *so) FmtAccounting(num float64, v uint64, currency currency.Type) string {
269
270	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
271	symbol := so.currencies[currency]
272	l := len(s) + len(symbol) + 1 + 1*len(s[:len(s)-int(v)-1])/3
273	count := 0
274	inWhole := v == 0
275	b := make([]byte, 0, l)
276
277	for i := len(s) - 1; i >= 0; i-- {
278
279		if s[i] == '.' {
280			b = append(b, so.decimal[0])
281			inWhole = true
282			continue
283		}
284
285		if inWhole {
286			if count == 3 {
287				b = append(b, so.group[0])
288				count = 1
289			} else {
290				count++
291			}
292		}
293
294		b = append(b, s[i])
295	}
296
297	if num < 0 {
298
299		for j := len(symbol) - 1; j >= 0; j-- {
300			b = append(b, symbol[j])
301		}
302
303		b = append(b, so.minus[0])
304
305	} else {
306
307		for j := len(symbol) - 1; j >= 0; j-- {
308			b = append(b, symbol[j])
309		}
310
311	}
312
313	// reverse
314	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
315		b[i], b[j] = b[j], b[i]
316	}
317
318	if int(v) < 2 {
319
320		if v == 0 {
321			b = append(b, so.decimal...)
322		}
323
324		for i := 0; i < 2-int(v); i++ {
325			b = append(b, '0')
326		}
327	}
328
329	return string(b)
330}
331
332// FmtDateShort returns the short date representation of 't' for 'so'
333func (so *so) FmtDateShort(t time.Time) string {
334
335	b := make([]byte, 0, 32)
336
337	if t.Day() < 10 {
338		b = append(b, '0')
339	}
340
341	b = strconv.AppendInt(b, int64(t.Day()), 10)
342	b = append(b, []byte{0x2f}...)
343
344	if t.Month() < 10 {
345		b = append(b, '0')
346	}
347
348	b = strconv.AppendInt(b, int64(t.Month()), 10)
349
350	b = append(b, []byte{0x2f}...)
351
352	if t.Year() > 9 {
353		b = append(b, strconv.Itoa(t.Year())[2:]...)
354	} else {
355		b = append(b, strconv.Itoa(t.Year())[1:]...)
356	}
357
358	return string(b)
359}
360
361// FmtDateMedium returns the medium date representation of 't' for 'so'
362func (so *so) FmtDateMedium(t time.Time) string {
363
364	b := make([]byte, 0, 32)
365
366	if t.Day() < 10 {
367		b = append(b, '0')
368	}
369
370	b = strconv.AppendInt(b, int64(t.Day()), 10)
371	b = append(b, []byte{0x2d}...)
372	b = append(b, so.monthsAbbreviated[t.Month()]...)
373	b = append(b, []byte{0x2d}...)
374
375	if t.Year() > 0 {
376		b = strconv.AppendInt(b, int64(t.Year()), 10)
377	} else {
378		b = strconv.AppendInt(b, int64(-t.Year()), 10)
379	}
380
381	return string(b)
382}
383
384// FmtDateLong returns the long date representation of 't' for 'so'
385func (so *so) FmtDateLong(t time.Time) string {
386
387	b := make([]byte, 0, 32)
388
389	if t.Day() < 10 {
390		b = append(b, '0')
391	}
392
393	b = strconv.AppendInt(b, int64(t.Day()), 10)
394	b = append(b, []byte{0x20}...)
395	b = append(b, so.monthsWide[t.Month()]...)
396	b = append(b, []byte{0x20}...)
397
398	if t.Year() > 0 {
399		b = strconv.AppendInt(b, int64(t.Year()), 10)
400	} else {
401		b = strconv.AppendInt(b, int64(-t.Year()), 10)
402	}
403
404	return string(b)
405}
406
407// FmtDateFull returns the full date representation of 't' for 'so'
408func (so *so) FmtDateFull(t time.Time) string {
409
410	b := make([]byte, 0, 32)
411
412	b = append(b, so.daysWide[t.Weekday()]...)
413	b = append(b, []byte{0x2c, 0x20}...)
414	b = append(b, so.monthsWide[t.Month()]...)
415	b = append(b, []byte{0x20}...)
416
417	if t.Day() < 10 {
418		b = append(b, '0')
419	}
420
421	b = strconv.AppendInt(b, int64(t.Day()), 10)
422	b = append(b, []byte{0x2c, 0x20}...)
423
424	if t.Year() > 0 {
425		b = strconv.AppendInt(b, int64(t.Year()), 10)
426	} else {
427		b = strconv.AppendInt(b, int64(-t.Year()), 10)
428	}
429
430	return string(b)
431}
432
433// FmtTimeShort returns the short time representation of 't' for 'so'
434func (so *so) FmtTimeShort(t time.Time) string {
435
436	b := make([]byte, 0, 32)
437
438	h := t.Hour()
439
440	if h > 12 {
441		h -= 12
442	}
443
444	b = strconv.AppendInt(b, int64(h), 10)
445	b = append(b, so.timeSeparator...)
446
447	if t.Minute() < 10 {
448		b = append(b, '0')
449	}
450
451	b = strconv.AppendInt(b, int64(t.Minute()), 10)
452	b = append(b, []byte{0x20}...)
453
454	if t.Hour() < 12 {
455		b = append(b, so.periodsAbbreviated[0]...)
456	} else {
457		b = append(b, so.periodsAbbreviated[1]...)
458	}
459
460	return string(b)
461}
462
463// FmtTimeMedium returns the medium time representation of 't' for 'so'
464func (so *so) FmtTimeMedium(t time.Time) string {
465
466	b := make([]byte, 0, 32)
467
468	h := t.Hour()
469
470	if h > 12 {
471		h -= 12
472	}
473
474	b = strconv.AppendInt(b, int64(h), 10)
475	b = append(b, so.timeSeparator...)
476
477	if t.Minute() < 10 {
478		b = append(b, '0')
479	}
480
481	b = strconv.AppendInt(b, int64(t.Minute()), 10)
482	b = append(b, so.timeSeparator...)
483
484	if t.Second() < 10 {
485		b = append(b, '0')
486	}
487
488	b = strconv.AppendInt(b, int64(t.Second()), 10)
489	b = append(b, []byte{0x20}...)
490
491	if t.Hour() < 12 {
492		b = append(b, so.periodsAbbreviated[0]...)
493	} else {
494		b = append(b, so.periodsAbbreviated[1]...)
495	}
496
497	return string(b)
498}
499
500// FmtTimeLong returns the long time representation of 't' for 'so'
501func (so *so) FmtTimeLong(t time.Time) string {
502
503	b := make([]byte, 0, 32)
504
505	h := t.Hour()
506
507	if h > 12 {
508		h -= 12
509	}
510
511	b = strconv.AppendInt(b, int64(h), 10)
512	b = append(b, so.timeSeparator...)
513
514	if t.Minute() < 10 {
515		b = append(b, '0')
516	}
517
518	b = strconv.AppendInt(b, int64(t.Minute()), 10)
519	b = append(b, so.timeSeparator...)
520
521	if t.Second() < 10 {
522		b = append(b, '0')
523	}
524
525	b = strconv.AppendInt(b, int64(t.Second()), 10)
526	b = append(b, []byte{0x20}...)
527
528	if t.Hour() < 12 {
529		b = append(b, so.periodsAbbreviated[0]...)
530	} else {
531		b = append(b, so.periodsAbbreviated[1]...)
532	}
533
534	b = append(b, []byte{0x20}...)
535
536	tz, _ := t.Zone()
537	b = append(b, tz...)
538
539	return string(b)
540}
541
542// FmtTimeFull returns the full time representation of 't' for 'so'
543func (so *so) FmtTimeFull(t time.Time) string {
544
545	b := make([]byte, 0, 32)
546
547	h := t.Hour()
548
549	if h > 12 {
550		h -= 12
551	}
552
553	b = strconv.AppendInt(b, int64(h), 10)
554	b = append(b, so.timeSeparator...)
555
556	if t.Minute() < 10 {
557		b = append(b, '0')
558	}
559
560	b = strconv.AppendInt(b, int64(t.Minute()), 10)
561	b = append(b, so.timeSeparator...)
562
563	if t.Second() < 10 {
564		b = append(b, '0')
565	}
566
567	b = strconv.AppendInt(b, int64(t.Second()), 10)
568	b = append(b, []byte{0x20}...)
569
570	if t.Hour() < 12 {
571		b = append(b, so.periodsAbbreviated[0]...)
572	} else {
573		b = append(b, so.periodsAbbreviated[1]...)
574	}
575
576	b = append(b, []byte{0x20}...)
577
578	tz, _ := t.Zone()
579
580	if btz, ok := so.timezones[tz]; ok {
581		b = append(b, btz...)
582	} else {
583		b = append(b, tz...)
584	}
585
586	return string(b)
587}
588