8 "github.com/go-playground/locales"
9 "github.com/go-playground/locales/currency"
14 pluralsCardinal []locales.PluralRule
15 pluralsOrdinal []locales.PluralRule
16 pluralsRange []locales.PluralRule
24 currencies []string // idx = enum of currency code
25 currencyPositiveSuffix string
26 currencyNegativePrefix string
27 currencyNegativeSuffix string
28 monthsAbbreviated []string
31 daysAbbreviated []string
35 periodsAbbreviated []string
36 periodsNarrow []string
39 erasAbbreviated []string
42 timezones map[string]string
45 // New returns a new instance of translator for the 'sq' locale
46 func New() locales.Translator {
49 pluralsCardinal: []locales.PluralRule{2, 6},
50 pluralsOrdinal: []locales.PluralRule{2, 5, 6},
51 pluralsRange: []locales.PluralRule{2, 6},
59 currencies: []string{"ADP", "AED", "AFA", "AFN", "ALK", "Lekë", "AMD", "ANG", "AOA", "AOK", "AON", "AOR", "ARA", "ARL", "ARM", "ARP", "ARS", "ATS", "A$", "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", "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", "₪", "₹", "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", "MTL", "MTP", "MUR", "MVP", "MVR", "MWK", "MX$", "MXP", "MXV", "MYR", "MZE", "MZM", "MZN", "NAD", "NGN", "NIC", "NIO", "NLG", "NOK", "NPR", "NZ$", "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", "SUR", "SVC", "SYP", "SZL", "฿", "TJR", "TJS", "TMM", "TMT", "TND", "TOP", "TPE", "TRL", "TRY", "TTD", "NT$", "TZS", "UAH", "UAK", "UGS", "UGX", "US$", "USN", "USS", "UYI", "UYP", "$", "UZS", "VEB", "VEF", "₫", "VNN", "VUV", "WST", "FCFA", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "EC$", "XDR", "XEU", "XFO", "XFU", "CFA", "XPD", "CFPF", "XPT", "XRE", "XSU", "XTS", "XUA", "XXX", "YDD", "YER", "YUD", "YUM", "YUN", "YUR", "ZAL", "ZAR", "ZMK", "ZMW", "ZRN", "ZRZ", "ZWD", "ZWL", "ZWR"},
60 currencyPositiveSuffix: " ",
61 currencyNegativePrefix: "(",
62 currencyNegativeSuffix: " )",
63 monthsAbbreviated: []string{"", "jan", "shk", "mar", "pri", "maj", "qer", "kor", "gsh", "sht", "tet", "nën", "dhj"},
64 monthsNarrow: []string{"", "j", "s", "m", "p", "m", "q", "k", "g", "s", "t", "n", "d"},
65 monthsWide: []string{"", "janar", "shkurt", "mars", "prill", "maj", "qershor", "korrik", "gusht", "shtator", "tetor", "nëntor", "dhjetor"},
66 daysAbbreviated: []string{"Die", "Hën", "Mar", "Mër", "Enj", "Pre", "Sht"},
67 daysNarrow: []string{"D", "H", "M", "M", "E", "P", "S"},
68 daysShort: []string{"Die", "Hën", "Mar", "Mër", "Enj", "Pre", "Sht"},
69 daysWide: []string{"e diel", "e hënë", "e martë", "e mërkurë", "e enjte", "e premte", "e shtunë"},
70 periodsAbbreviated: []string{"e paradites", "e pasdites"},
71 periodsNarrow: []string{"e paradites", "e pasdites"},
72 periodsWide: []string{"e paradites", "e pasdites"},
73 erasAbbreviated: []string{"p.K.", "mb.K."},
74 erasNarrow: []string{"p.K.", "mb.K."},
75 erasWide: []string{"para Krishtit", "mbas Krishtit"},
76 timezones: map[string]string{"HAST": "Ora standarde e Ishujve Hauai-Aleutian", "NZDT": "Ora verore e Zelandës së Re", "WART": "Ora standarde e Argjentinës Perëndimore", "SAST": "Ora standarde e Afrikës Jugore", "EST": "Ora standarde e SHBA-së Lindore", "GYT": "Ora e Guajanës", "ECT": "Ora e Ekuadorit", "GMT": "Ora e Meridianit të Grinuiçit", "CHADT": "Ora verore e Katamit", "HNCU": "Ora standarde e Kubës", "TMT": "Ora standarde e Turkmenistanit", "MEZ": "Ora standarde e Evropës Qendrore", "OEZ": "Ora standarde e Evropës Lindore", "COST": "Ora verore e Kolumbisë", "HKST": "Ora verore e Hong-Kongut", "BT": "Ora e Butanit", "UYT": "Ora standarde e Uruguait", "HNEG": "Ora standarde e Grenlandës Lindore", "HEEG": "Ora verore e Grenlandës Lindore", "ChST": "Ora e Kamorros", "HNPM": "Ora standarde e Shën-Pier dhe Mikuelon", "PDT": "Ora verore amerikane e Bregut të Paqësorit", "NZST": "Ora standarde e Zelandës së Re", "HENOMX": "Ora verore e Meksikës Veriperëndimore", "WITA": "Ora e Indonezisë Qendrore", "JST": "Ora standarde e Japonisë", "ACDT": "Ora verore e Australisë Qendrore", "SGT": "Ora e Singaporit", "HEPM": "Ora verore e Shën-Pier dhe Mikuelon", "MDT": "Ora verore e Makaos", "ADT": "Ora verore e Atlantikut", "ARST": "Ora verore e Argjentinës", "CLST": "Ora verore e Kilit", "∅∅∅": "Ora verore e Perusë", "UYST": "Ora verore e Uruguait", "MESZ": "Ora verore e Evropës Qendrore", "EAT": "Ora e Afrikës Lindore", "COT": "Ora standarde e Kolumbisë", "HNT": "Ora standarde e Njufaundlendit [Tokës së Re]", "CLT": "Ora standarde e Kilit", "AKDT": "Ora verore e Alsaskës", "HNPMX": "Ora standarde meksikane e Bregut të Paqësorit", "HECU": "Ora verore e Kubës", "BOT": "Ora e Bolivisë", "LHST": "Ora standarde e Lord-Houit", "EDT": "Ora verore e SHBA-së Lindore", "WIB": "Ora e Indonezisë Perëndimore", "ACWST": "Ora standarde e Australisë Qendroro-Perëndimore", "HADT": "Ora verore e Ishujve Hauai-Aleutian", "VET": "Ora e Venezuelës", "JDT": "Ora verore e Japonisë", "HNOG": "Ora standarde e Grenlandës Perëndimore", "AKST": "Ora standarde e Alaskës", "ACST": "Ora standarde e Australisë Qendrore", "OESZ": "Ora verore e Evropës Lindore", "IST": "Ora standarde e Indisë", "CAT": "Ora e Afrikës Qendrore", "CST": "Ora standarde e SHBA-së Qendrore", "AWST": "Ora standarde e Australisë Perëndimore", "HNNOMX": "Ora standarde e Meksikës Veriperëndimore", "ART": "Ora standarde e Argjentinës", "HKT": "Ora standarde e Hong-Kongut", "HEPMX": "Ora verore meksikane e Bregut të Paqësorit", "PST": "Ora standarde amerikane e Bregut të Paqësorit", "WIT": "Ora e Indonezisë Lindore", "MYT": "Ora e Malajzisë", "WARST": "Ora verore e Argjentinës Perëndimore", "WAT": "Ora standarde e Afrikës Perëndimore", "CDT": "Ora verore e SHBA-së Qendrore", "WAST": "Ora verore e Afrikës Perëndimore", "SRT": "Ora e Surinamit", "ACWDT": "Ora verore e Australisë Qendroro-Perëndimore", "AST": "Ora standarde e Atlantikut", "AEST": "Ora standarde e Australisë Lindore", "WEZ": "Ora standarde e Evropës Perëndimore", "WESZ": "Ora verore e Evropës Perëndimore", "LHDT": "Ora verore e Lord-Houit", "HEOG": "Ora verore e Grenlandës Perëndimore", "GFT": "Ora e Guajanës Franceze", "CHAST": "Ora standarde e Katamit", "MST": "Ora standarde e Makaos", "AWDT": "Ora verore e Australisë Perëndimore", "TMST": "Ora verore e Turkmenistanit", "AEDT": "Ora verore e Australisë Lindore", "HAT": "Ora verore e Njufaundlendit [Tokës së Re]"},
80 // Locale returns the current translators string locale
81 func (sq *sq) Locale() string {
85 // PluralsCardinal returns the list of cardinal plural rules associated with 'sq'
86 func (sq *sq) PluralsCardinal() []locales.PluralRule {
87 return sq.pluralsCardinal
90 // PluralsOrdinal returns the list of ordinal plural rules associated with 'sq'
91 func (sq *sq) PluralsOrdinal() []locales.PluralRule {
92 return sq.pluralsOrdinal
95 // PluralsRange returns the list of range plural rules associated with 'sq'
96 func (sq *sq) PluralsRange() []locales.PluralRule {
97 return sq.pluralsRange
100 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'sq'
101 func (sq *sq) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
106 return locales.PluralRuleOne
109 return locales.PluralRuleOther
112 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'sq'
113 func (sq *sq) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
116 nMod100 := math.Mod(n, 100)
117 nMod10 := math.Mod(n, 10)
120 return locales.PluralRuleOne
121 } else if nMod10 == 4 && nMod100 != 14 {
122 return locales.PluralRuleMany
125 return locales.PluralRuleOther
128 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'sq'
129 func (sq *sq) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
131 start := sq.CardinalPluralRule(num1, v1)
132 end := sq.CardinalPluralRule(num2, v2)
134 if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
135 return locales.PluralRuleOther
136 } else if start == locales.PluralRuleOther && end == locales.PluralRuleOne {
137 return locales.PluralRuleOne
140 return locales.PluralRuleOther
144 // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
145 func (sq *sq) MonthAbbreviated(month time.Month) string {
146 return sq.monthsAbbreviated[month]
149 // MonthsAbbreviated returns the locales abbreviated months
150 func (sq *sq) MonthsAbbreviated() []string {
151 return sq.monthsAbbreviated[1:]
154 // MonthNarrow returns the locales narrow month given the 'month' provided
155 func (sq *sq) MonthNarrow(month time.Month) string {
156 return sq.monthsNarrow[month]
159 // MonthsNarrow returns the locales narrow months
160 func (sq *sq) MonthsNarrow() []string {
161 return sq.monthsNarrow[1:]
164 // MonthWide returns the locales wide month given the 'month' provided
165 func (sq *sq) MonthWide(month time.Month) string {
166 return sq.monthsWide[month]
169 // MonthsWide returns the locales wide months
170 func (sq *sq) MonthsWide() []string {
171 return sq.monthsWide[1:]
174 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
175 func (sq *sq) WeekdayAbbreviated(weekday time.Weekday) string {
176 return sq.daysAbbreviated[weekday]
179 // WeekdaysAbbreviated returns the locales abbreviated weekdays
180 func (sq *sq) WeekdaysAbbreviated() []string {
181 return sq.daysAbbreviated
184 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
185 func (sq *sq) WeekdayNarrow(weekday time.Weekday) string {
186 return sq.daysNarrow[weekday]
189 // WeekdaysNarrow returns the locales narrow weekdays
190 func (sq *sq) WeekdaysNarrow() []string {
194 // WeekdayShort returns the locales short weekday given the 'weekday' provided
195 func (sq *sq) WeekdayShort(weekday time.Weekday) string {
196 return sq.daysShort[weekday]
199 // WeekdaysShort returns the locales short weekdays
200 func (sq *sq) WeekdaysShort() []string {
204 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
205 func (sq *sq) WeekdayWide(weekday time.Weekday) string {
206 return sq.daysWide[weekday]
209 // WeekdaysWide returns the locales wide weekdays
210 func (sq *sq) WeekdaysWide() []string {
214 // Decimal returns the decimal point of number
215 func (sq *sq) Decimal() string {
219 // Group returns the group of number
220 func (sq *sq) Group() string {
224 // Group returns the minus sign of number
225 func (sq *sq) Minus() string {
229 // FmtNumber returns 'num' with digits/precision of 'v' for 'sq' and handles both Whole and Real numbers based on 'v'
230 func (sq *sq) FmtNumber(num float64, v uint64) string {
232 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
233 l := len(s) + 2 + 2*len(s[:len(s)-int(v)-1])/3
236 b := make([]byte, 0, l)
238 for i := len(s) - 1; i >= 0; i-- {
241 b = append(b, sq.decimal[0])
248 for j := len(sq.group) - 1; j >= 0; j-- {
249 b = append(b, sq.group[j])
261 b = append(b, sq.minus[0])
265 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
266 b[i], b[j] = b[j], b[i]
272 // FmtPercent returns 'num' with digits/precision of 'v' for 'sq' and handles both Whole and Real numbers based on 'v'
273 // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
274 func (sq *sq) FmtPercent(num float64, v uint64) string {
275 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
277 b := make([]byte, 0, l)
279 for i := len(s) - 1; i >= 0; i-- {
282 b = append(b, sq.decimal[0])
290 b = append(b, sq.minus[0])
294 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
295 b[i], b[j] = b[j], b[i]
298 b = append(b, sq.percent...)
303 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'sq'
304 func (sq *sq) FmtCurrency(num float64, v uint64, currency currency.Type) string {
306 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
307 symbol := sq.currencies[currency]
308 l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
311 b := make([]byte, 0, l)
313 for i := len(s) - 1; i >= 0; i-- {
316 b = append(b, sq.decimal[0])
323 for j := len(sq.group) - 1; j >= 0; j-- {
324 b = append(b, sq.group[j])
336 b = append(b, sq.minus[0])
340 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
341 b[i], b[j] = b[j], b[i]
347 b = append(b, sq.decimal...)
350 for i := 0; i < 2-int(v); i++ {
355 b = append(b, sq.currencyPositiveSuffix...)
357 b = append(b, symbol...)
362 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'sq'
363 // in accounting notation.
364 func (sq *sq) FmtAccounting(num float64, v uint64, currency currency.Type) string {
366 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
367 symbol := sq.currencies[currency]
368 l := len(s) + len(symbol) + 6 + 2*len(s[:len(s)-int(v)-1])/3
371 b := make([]byte, 0, l)
373 for i := len(s) - 1; i >= 0; i-- {
376 b = append(b, sq.decimal[0])
383 for j := len(sq.group) - 1; j >= 0; j-- {
384 b = append(b, sq.group[j])
397 b = append(b, sq.currencyNegativePrefix[0])
402 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
403 b[i], b[j] = b[j], b[i]
409 b = append(b, sq.decimal...)
412 for i := 0; i < 2-int(v); i++ {
418 b = append(b, sq.currencyNegativeSuffix...)
419 b = append(b, symbol...)
422 b = append(b, sq.currencyPositiveSuffix...)
423 b = append(b, symbol...)
429 // FmtDateShort returns the short date representation of 't' for 'sq'
430 func (sq *sq) FmtDateShort(t time.Time) string {
432 b := make([]byte, 0, 32)
434 b = strconv.AppendInt(b, int64(t.Day()), 10)
435 b = append(b, []byte{0x2e}...)
436 b = strconv.AppendInt(b, int64(t.Month()), 10)
437 b = append(b, []byte{0x2e}...)
440 b = append(b, strconv.Itoa(t.Year())[2:]...)
442 b = append(b, strconv.Itoa(t.Year())[1:]...)
448 // FmtDateMedium returns the medium date representation of 't' for 'sq'
449 func (sq *sq) FmtDateMedium(t time.Time) string {
451 b := make([]byte, 0, 32)
453 b = strconv.AppendInt(b, int64(t.Day()), 10)
454 b = append(b, []byte{0x20}...)
455 b = append(b, sq.monthsAbbreviated[t.Month()]...)
456 b = append(b, []byte{0x20}...)
459 b = strconv.AppendInt(b, int64(t.Year()), 10)
461 b = strconv.AppendInt(b, int64(-t.Year()), 10)
467 // FmtDateLong returns the long date representation of 't' for 'sq'
468 func (sq *sq) FmtDateLong(t time.Time) string {
470 b := make([]byte, 0, 32)
472 b = strconv.AppendInt(b, int64(t.Day()), 10)
473 b = append(b, []byte{0x20}...)
474 b = append(b, sq.monthsWide[t.Month()]...)
475 b = append(b, []byte{0x20}...)
478 b = strconv.AppendInt(b, int64(t.Year()), 10)
480 b = strconv.AppendInt(b, int64(-t.Year()), 10)
486 // FmtDateFull returns the full date representation of 't' for 'sq'
487 func (sq *sq) FmtDateFull(t time.Time) string {
489 b := make([]byte, 0, 32)
491 b = append(b, sq.daysWide[t.Weekday()]...)
492 b = append(b, []byte{0x2c, 0x20}...)
493 b = strconv.AppendInt(b, int64(t.Day()), 10)
494 b = append(b, []byte{0x20}...)
495 b = append(b, sq.monthsWide[t.Month()]...)
496 b = append(b, []byte{0x20}...)
499 b = strconv.AppendInt(b, int64(t.Year()), 10)
501 b = strconv.AppendInt(b, int64(-t.Year()), 10)
507 // FmtTimeShort returns the short time representation of 't' for 'sq'
508 func (sq *sq) FmtTimeShort(t time.Time) string {
510 b := make([]byte, 0, 32)
518 b = strconv.AppendInt(b, int64(h), 10)
519 b = append(b, sq.timeSeparator...)
525 b = strconv.AppendInt(b, int64(t.Minute()), 10)
526 b = append(b, []byte{0x20}...)
529 b = append(b, sq.periodsAbbreviated[0]...)
531 b = append(b, sq.periodsAbbreviated[1]...)
537 // FmtTimeMedium returns the medium time representation of 't' for 'sq'
538 func (sq *sq) FmtTimeMedium(t time.Time) string {
540 b := make([]byte, 0, 32)
548 b = strconv.AppendInt(b, int64(h), 10)
549 b = append(b, sq.timeSeparator...)
555 b = strconv.AppendInt(b, int64(t.Minute()), 10)
556 b = append(b, sq.timeSeparator...)
562 b = strconv.AppendInt(b, int64(t.Second()), 10)
563 b = append(b, []byte{0x20}...)
566 b = append(b, sq.periodsAbbreviated[0]...)
568 b = append(b, sq.periodsAbbreviated[1]...)
574 // FmtTimeLong returns the long time representation of 't' for 'sq'
575 func (sq *sq) FmtTimeLong(t time.Time) string {
577 b := make([]byte, 0, 32)
585 b = strconv.AppendInt(b, int64(h), 10)
586 b = append(b, sq.timeSeparator...)
592 b = strconv.AppendInt(b, int64(t.Minute()), 10)
593 b = append(b, sq.timeSeparator...)
599 b = strconv.AppendInt(b, int64(t.Second()), 10)
600 b = append(b, []byte{0x20}...)
603 b = append(b, sq.periodsAbbreviated[0]...)
605 b = append(b, sq.periodsAbbreviated[1]...)
608 b = append(b, []byte{0x2c, 0x20}...)
616 // FmtTimeFull returns the full time representation of 't' for 'sq'
617 func (sq *sq) FmtTimeFull(t time.Time) string {
619 b := make([]byte, 0, 32)
627 b = strconv.AppendInt(b, int64(h), 10)
628 b = append(b, sq.timeSeparator...)
634 b = strconv.AppendInt(b, int64(t.Minute()), 10)
635 b = append(b, sq.timeSeparator...)
641 b = strconv.AppendInt(b, int64(t.Second()), 10)
642 b = append(b, []byte{0x20}...)
645 b = append(b, sq.periodsAbbreviated[0]...)
647 b = append(b, sq.periodsAbbreviated[1]...)
650 b = append(b, []byte{0x2c, 0x20}...)
654 if btz, ok := sq.timezones[tz]; ok {
655 b = append(b, btz...)