1package wae
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 wae 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	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// New returns a new instance of translator for the 'wae' locale
47func New() locales.Translator {
48	return &wae{
49		locale:                 "wae",
50		pluralsCardinal:        []locales.PluralRule{2, 6},
51		pluralsOrdinal:         nil,
52		pluralsRange:           nil,
53		decimal:                ",",
54		group:                  "’",
55		timeSeparator:          ":",
56		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", "¥", "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", "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", "$", "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"},
57		currencyPositivePrefix: " ",
58		currencyPositiveSuffix: "K",
59		currencyNegativePrefix: " ",
60		currencyNegativeSuffix: "K",
61		monthsAbbreviated:      []string{"", "Jen", "Hor", "Mär", "Abr", "Mei", "Brá", "Hei", "Öig", "Her", "Wím", "Win", "Chr"},
62		monthsNarrow:           []string{"", "J", "H", "M", "A", "M", "B", "H", "Ö", "H", "W", "W", "C"},
63		monthsWide:             []string{"", "Jenner", "Hornig", "Märze", "Abrille", "Meije", "Bráčet", "Heiwet", "Öigšte", "Herbštmánet", "Wímánet", "Wintermánet", "Chrištmánet"},
64		daysAbbreviated:        []string{"Sun", "Män", "Ziš", "Mit", "Fró", "Fri", "Sam"},
65		daysNarrow:             []string{"S", "M", "Z", "M", "F", "F", "S"},
66		daysWide:               []string{"Sunntag", "Mäntag", "Zištag", "Mittwuč", "Fróntag", "Fritag", "Samštag"},
67		erasAbbreviated:        []string{"v. Chr.", "n. Chr"},
68		erasNarrow:             []string{"", ""},
69		erasWide:               []string{"", ""},
70		timezones:              map[string]string{"AWDT": "AWDT", "AKDT": "AKDT", "ACST": "ACST", "ACWST": "ACWST", "HNOG": "HNOG", "WARST": "WARST", "HNT": "HNT", "WIT": "WIT", "TMST": "TMST", "ART": "ART", "WIB": "WIB", "IST": "IST", "LHST": "LHST", "HAT": "HAT", "HEPM": "HEPM", "TMT": "TMT", "ChST": "ChST", "AEST": "AEST", "AEDT": "AEDT", "WAT": "WAT", "HNPM": "HNPM", "COT": "COT", "VET": "VET", "ARST": "ARST", "CHAST": "CHAST", "HNCU": "HNCU", "NZDT": "NZDT", "HKT": "HKT", "WART": "WART", "GMT": "GMT", "AWST": "AWST", "MDT": "MDT", "HNEG": "HNEG", "HEEG": "HEEG", "HADT": "HADT", "AST": "Atlantiši Standardzit", "HKST": "HKST", "EAT": "EAT", "CLST": "CLST", "OEZ": "Ošteuropäiši Standardzit", "GFT": "GFT", "ACWDT": "ACWDT", "MEZ": "Mitteleuropäiši Standardzit", "BOT": "BOT", "SGT": "SGT", "NZST": "NZST", "JDT": "JDT", "ACDT": "ACDT", "CLT": "CLT", "PST": "PST", "MYT": "MYT", "EST": "EST", "GYT": "GYT", "UYT": "UYT", "PDT": "PDT", "JST": "JST", "HENOMX": "HENOMX", "CAT": "CAT", "OESZ": "Ošteuropäiši Summerzit", "HECU": "HECU", "HEPMX": "HEPMX", "ADT": "Atlantiši Summerzit", "HEOG": "HEOG", "WITA": "WITA", "HAST": "HAST", "∅∅∅": "∅∅∅", "UYST": "UYST", "CHADT": "CHADT", "SAST": "SAST", "EDT": "EDT", "CDT": "CDT", "WEZ": "Wešteuropäiši Standardzit", "WESZ": "Wešteuropäiši Summerzit", "LHDT": "LHDT", "SRT": "SRT", "AKST": "AKST", "ECT": "ECT", "COST": "COST", "CST": "CST", "HNPMX": "HNPMX", "MST": "MST", "WAST": "WAST", "BT": "BT", "MESZ": "Mitteleuropäiši Summerzit", "HNNOMX": "HNNOMX"},
71	}
72}
73
74// Locale returns the current translators string locale
75func (wae *wae) Locale() string {
76	return wae.locale
77}
78
79// PluralsCardinal returns the list of cardinal plural rules associated with 'wae'
80func (wae *wae) PluralsCardinal() []locales.PluralRule {
81	return wae.pluralsCardinal
82}
83
84// PluralsOrdinal returns the list of ordinal plural rules associated with 'wae'
85func (wae *wae) PluralsOrdinal() []locales.PluralRule {
86	return wae.pluralsOrdinal
87}
88
89// PluralsRange returns the list of range plural rules associated with 'wae'
90func (wae *wae) PluralsRange() []locales.PluralRule {
91	return wae.pluralsRange
92}
93
94// CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'wae'
95func (wae *wae) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
96
97	n := math.Abs(num)
98
99	if n == 1 {
100		return locales.PluralRuleOne
101	}
102
103	return locales.PluralRuleOther
104}
105
106// OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'wae'
107func (wae *wae) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
108	return locales.PluralRuleUnknown
109}
110
111// RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'wae'
112func (wae *wae) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
113	return locales.PluralRuleUnknown
114}
115
116// MonthAbbreviated returns the locales abbreviated month given the 'month' provided
117func (wae *wae) MonthAbbreviated(month time.Month) string {
118	return wae.monthsAbbreviated[month]
119}
120
121// MonthsAbbreviated returns the locales abbreviated months
122func (wae *wae) MonthsAbbreviated() []string {
123	return wae.monthsAbbreviated[1:]
124}
125
126// MonthNarrow returns the locales narrow month given the 'month' provided
127func (wae *wae) MonthNarrow(month time.Month) string {
128	return wae.monthsNarrow[month]
129}
130
131// MonthsNarrow returns the locales narrow months
132func (wae *wae) MonthsNarrow() []string {
133	return wae.monthsNarrow[1:]
134}
135
136// MonthWide returns the locales wide month given the 'month' provided
137func (wae *wae) MonthWide(month time.Month) string {
138	return wae.monthsWide[month]
139}
140
141// MonthsWide returns the locales wide months
142func (wae *wae) MonthsWide() []string {
143	return wae.monthsWide[1:]
144}
145
146// WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
147func (wae *wae) WeekdayAbbreviated(weekday time.Weekday) string {
148	return wae.daysAbbreviated[weekday]
149}
150
151// WeekdaysAbbreviated returns the locales abbreviated weekdays
152func (wae *wae) WeekdaysAbbreviated() []string {
153	return wae.daysAbbreviated
154}
155
156// WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
157func (wae *wae) WeekdayNarrow(weekday time.Weekday) string {
158	return wae.daysNarrow[weekday]
159}
160
161// WeekdaysNarrow returns the locales narrow weekdays
162func (wae *wae) WeekdaysNarrow() []string {
163	return wae.daysNarrow
164}
165
166// WeekdayShort returns the locales short weekday given the 'weekday' provided
167func (wae *wae) WeekdayShort(weekday time.Weekday) string {
168	return wae.daysShort[weekday]
169}
170
171// WeekdaysShort returns the locales short weekdays
172func (wae *wae) WeekdaysShort() []string {
173	return wae.daysShort
174}
175
176// WeekdayWide returns the locales wide weekday given the 'weekday' provided
177func (wae *wae) WeekdayWide(weekday time.Weekday) string {
178	return wae.daysWide[weekday]
179}
180
181// WeekdaysWide returns the locales wide weekdays
182func (wae *wae) WeekdaysWide() []string {
183	return wae.daysWide
184}
185
186// Decimal returns the decimal point of number
187func (wae *wae) Decimal() string {
188	return wae.decimal
189}
190
191// Group returns the group of number
192func (wae *wae) Group() string {
193	return wae.group
194}
195
196// Group returns the minus sign of number
197func (wae *wae) Minus() string {
198	return wae.minus
199}
200
201// FmtNumber returns 'num' with digits/precision of 'v' for 'wae' and handles both Whole and Real numbers based on 'v'
202func (wae *wae) FmtNumber(num float64, v uint64) string {
203
204	return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
205}
206
207// FmtPercent returns 'num' with digits/precision of 'v' for 'wae' and handles both Whole and Real numbers based on 'v'
208// NOTE: 'num' passed into FmtPercent is assumed to be in percent already
209func (wae *wae) FmtPercent(num float64, v uint64) string {
210	return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
211}
212
213// FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'wae'
214func (wae *wae) FmtCurrency(num float64, v uint64, currency currency.Type) string {
215
216	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
217	symbol := wae.currencies[currency]
218	l := len(s) + len(symbol) + 4
219
220	b := make([]byte, 0, l)
221
222	for i := len(s) - 1; i >= 0; i-- {
223
224		if s[i] == '.' {
225			b = append(b, wae.decimal[0])
226			continue
227		}
228
229		b = append(b, s[i])
230	}
231
232	for j := len(symbol) - 1; j >= 0; j-- {
233		b = append(b, symbol[j])
234	}
235
236	for j := len(wae.currencyPositivePrefix) - 1; j >= 0; j-- {
237		b = append(b, wae.currencyPositivePrefix[j])
238	}
239
240	if num < 0 {
241		b = append(b, wae.minus[0])
242	}
243
244	// reverse
245	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
246		b[i], b[j] = b[j], b[i]
247	}
248
249	b = append(b, wae.currencyPositiveSuffix...)
250
251	return string(b)
252}
253
254// FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'wae'
255// in accounting notation.
256func (wae *wae) FmtAccounting(num float64, v uint64, currency currency.Type) string {
257
258	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
259	symbol := wae.currencies[currency]
260	l := len(s) + len(symbol) + 4
261
262	b := make([]byte, 0, l)
263
264	for i := len(s) - 1; i >= 0; i-- {
265
266		if s[i] == '.' {
267			b = append(b, wae.decimal[0])
268			continue
269		}
270
271		b = append(b, s[i])
272	}
273
274	if num < 0 {
275
276		for j := len(symbol) - 1; j >= 0; j-- {
277			b = append(b, symbol[j])
278		}
279
280		for j := len(wae.currencyNegativePrefix) - 1; j >= 0; j-- {
281			b = append(b, wae.currencyNegativePrefix[j])
282		}
283
284		b = append(b, wae.minus[0])
285
286	} else {
287
288		for j := len(symbol) - 1; j >= 0; j-- {
289			b = append(b, symbol[j])
290		}
291
292		for j := len(wae.currencyPositivePrefix) - 1; j >= 0; j-- {
293			b = append(b, wae.currencyPositivePrefix[j])
294		}
295
296	}
297
298	// reverse
299	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
300		b[i], b[j] = b[j], b[i]
301	}
302
303	if num < 0 {
304		b = append(b, wae.currencyNegativeSuffix...)
305	} else {
306
307		b = append(b, wae.currencyPositiveSuffix...)
308	}
309
310	return string(b)
311}
312
313// FmtDateShort returns the short date representation of 't' for 'wae'
314func (wae *wae) FmtDateShort(t time.Time) string {
315
316	b := make([]byte, 0, 32)
317
318	return string(b)
319}
320
321// FmtDateMedium returns the medium date representation of 't' for 'wae'
322func (wae *wae) FmtDateMedium(t time.Time) string {
323
324	b := make([]byte, 0, 32)
325
326	b = strconv.AppendInt(b, int64(t.Day()), 10)
327	b = append(b, []byte{0x2e, 0x20}...)
328	b = append(b, wae.monthsAbbreviated[t.Month()]...)
329	b = append(b, []byte{0x20}...)
330
331	if t.Year() > 0 {
332		b = strconv.AppendInt(b, int64(t.Year()), 10)
333	} else {
334		b = strconv.AppendInt(b, int64(-t.Year()), 10)
335	}
336
337	return string(b)
338}
339
340// FmtDateLong returns the long date representation of 't' for 'wae'
341func (wae *wae) FmtDateLong(t time.Time) string {
342
343	b := make([]byte, 0, 32)
344
345	b = strconv.AppendInt(b, int64(t.Day()), 10)
346	b = append(b, []byte{0x2e, 0x20}...)
347	b = append(b, wae.monthsWide[t.Month()]...)
348	b = append(b, []byte{0x20}...)
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// FmtDateFull returns the full date representation of 't' for 'wae'
360func (wae *wae) FmtDateFull(t time.Time) string {
361
362	b := make([]byte, 0, 32)
363
364	b = append(b, wae.daysWide[t.Weekday()]...)
365	b = append(b, []byte{0x2c, 0x20}...)
366	b = strconv.AppendInt(b, int64(t.Day()), 10)
367	b = append(b, []byte{0x2e, 0x20}...)
368	b = append(b, wae.monthsWide[t.Month()]...)
369	b = append(b, []byte{0x20}...)
370
371	if t.Year() > 0 {
372		b = strconv.AppendInt(b, int64(t.Year()), 10)
373	} else {
374		b = strconv.AppendInt(b, int64(-t.Year()), 10)
375	}
376
377	return string(b)
378}
379
380// FmtTimeShort returns the short time representation of 't' for 'wae'
381func (wae *wae) FmtTimeShort(t time.Time) string {
382
383	b := make([]byte, 0, 32)
384
385	return string(b)
386}
387
388// FmtTimeMedium returns the medium time representation of 't' for 'wae'
389func (wae *wae) FmtTimeMedium(t time.Time) string {
390
391	b := make([]byte, 0, 32)
392
393	return string(b)
394}
395
396// FmtTimeLong returns the long time representation of 't' for 'wae'
397func (wae *wae) FmtTimeLong(t time.Time) string {
398
399	b := make([]byte, 0, 32)
400
401	return string(b)
402}
403
404// FmtTimeFull returns the full time representation of 't' for 'wae'
405func (wae *wae) FmtTimeFull(t time.Time) string {
406
407	b := make([]byte, 0, 32)
408
409	return string(b)
410}
411