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 currencyNegativePrefix string
26 currencyNegativeSuffix string
27 monthsAbbreviated []string
30 daysAbbreviated []string
34 periodsAbbreviated []string
35 periodsNarrow []string
38 erasAbbreviated []string
41 timezones map[string]string
44 // New returns a new instance of translator for the 'ebu' locale
45 func New() locales.Translator {
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", "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", "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", "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 currencyNegativePrefix: "(",
54 currencyNegativeSuffix: ")",
55 monthsAbbreviated: []string{"", "Mbe", "Kai", "Kat", "Kan", "Gat", "Gan", "Mug", "Knn", "Ken", "Iku", "Imw", "Igi"},
56 monthsNarrow: []string{"", "M", "K", "K", "K", "G", "G", "M", "K", "K", "I", "I", "I"},
57 monthsWide: []string{"", "Mweri wa mbere", "Mweri wa kaĩri", "Mweri wa kathatũ", "Mweri wa kana", "Mweri wa gatano", "Mweri wa gatantatũ", "Mweri wa mũgwanja", "Mweri wa kanana", "Mweri wa kenda", "Mweri wa ikũmi", "Mweri wa ikũmi na ũmwe", "Mweri wa ikũmi na Kaĩrĩ"},
58 daysAbbreviated: []string{"Kma", "Tat", "Ine", "Tan", "Arm", "Maa", "NMM"},
59 daysNarrow: []string{"K", "N", "N", "N", "A", "M", "N"},
60 daysWide: []string{"Kiumia", "Njumatatu", "Njumaine", "Njumatano", "Aramithi", "Njumaa", "NJumamothii"},
61 periodsAbbreviated: []string{"KI", "UT"},
62 periodsWide: []string{"KI", "UT"},
63 erasAbbreviated: []string{"MK", "TK"},
64 erasNarrow: []string{"", ""},
65 erasWide: []string{"Mbere ya Kristo", "Thutha wa Kristo"},
66 timezones: map[string]string{"CHADT": "CHADT", "AWST": "AWST", "MYT": "MYT", "AEDT": "AEDT", "GMT": "GMT", "SGT": "SGT", "SRT": "SRT", "NZST": "NZST", "WITA": "WITA", "JST": "JST", "HEEG": "HEEG", "COST": "COST", "WIB": "WIB", "PDT": "PDT", "LHST": "LHST", "LHDT": "LHDT", "AEST": "AEST", "HNOG": "HNOG", "HKST": "HKST", "EST": "EST", "EDT": "EDT", "MESZ": "MESZ", "TMT": "TMT", "VET": "VET", "JDT": "JDT", "WARST": "WARST", "IST": "IST", "HNPM": "HNPM", "UYST": "UYST", "GYT": "GYT", "ECT": "ECT", "CHAST": "CHAST", "HECU": "HECU", "MEZ": "MEZ", "WART": "WART", "CLT": "CLT", "CLST": "CLST", "HNCU": "HNCU", "OESZ": "OESZ", "ART": "ART", "BT": "BT", "CDT": "CDT", "MDT": "MDT", "ACST": "ACST", "HNPMX": "HNPMX", "OEZ": "OEZ", "AST": "AST", "WAT": "WAT", "HNT": "HNT", "AKST": "AKST", "ACWST": "ACWST", "HAST": "HAST", "HADT": "HADT", "HENOMX": "HENOMX", "SAST": "SAST", "WAST": "WAST", "AWDT": "AWDT", "UYT": "UYT", "NZDT": "NZDT", "EAT": "EAT", "AKDT": "AKDT", "ACDT": "ACDT", "PST": "PST", "CST": "CST", "ARST": "ARST", "HNEG": "HNEG", "WESZ": "WESZ", "COT": "COT", "CAT": "CAT", "HEPM": "HEPM", "MST": "MST", "TMST": "TMST", "HNNOMX": "HNNOMX", "ADT": "ADT", "HKT": "HKT", "HEPMX": "HEPMX", "∅∅∅": "∅∅∅", "WIT": "WIT", "HEOG": "HEOG", "GFT": "GFT", "HAT": "HAT", "ChST": "ChST", "BOT": "BOT", "ACWDT": "ACWDT", "WEZ": "WEZ"},
70 // Locale returns the current translators string locale
71 func (ebu *ebu) Locale() string {
75 // PluralsCardinal returns the list of cardinal plural rules associated with 'ebu'
76 func (ebu *ebu) PluralsCardinal() []locales.PluralRule {
77 return ebu.pluralsCardinal
80 // PluralsOrdinal returns the list of ordinal plural rules associated with 'ebu'
81 func (ebu *ebu) PluralsOrdinal() []locales.PluralRule {
82 return ebu.pluralsOrdinal
85 // PluralsRange returns the list of range plural rules associated with 'ebu'
86 func (ebu *ebu) PluralsRange() []locales.PluralRule {
87 return ebu.pluralsRange
90 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'ebu'
91 func (ebu *ebu) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
92 return locales.PluralRuleUnknown
95 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'ebu'
96 func (ebu *ebu) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
97 return locales.PluralRuleUnknown
100 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'ebu'
101 func (ebu *ebu) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
102 return locales.PluralRuleUnknown
105 // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
106 func (ebu *ebu) MonthAbbreviated(month time.Month) string {
107 return ebu.monthsAbbreviated[month]
110 // MonthsAbbreviated returns the locales abbreviated months
111 func (ebu *ebu) MonthsAbbreviated() []string {
112 return ebu.monthsAbbreviated[1:]
115 // MonthNarrow returns the locales narrow month given the 'month' provided
116 func (ebu *ebu) MonthNarrow(month time.Month) string {
117 return ebu.monthsNarrow[month]
120 // MonthsNarrow returns the locales narrow months
121 func (ebu *ebu) MonthsNarrow() []string {
122 return ebu.monthsNarrow[1:]
125 // MonthWide returns the locales wide month given the 'month' provided
126 func (ebu *ebu) MonthWide(month time.Month) string {
127 return ebu.monthsWide[month]
130 // MonthsWide returns the locales wide months
131 func (ebu *ebu) MonthsWide() []string {
132 return ebu.monthsWide[1:]
135 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
136 func (ebu *ebu) WeekdayAbbreviated(weekday time.Weekday) string {
137 return ebu.daysAbbreviated[weekday]
140 // WeekdaysAbbreviated returns the locales abbreviated weekdays
141 func (ebu *ebu) WeekdaysAbbreviated() []string {
142 return ebu.daysAbbreviated
145 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
146 func (ebu *ebu) WeekdayNarrow(weekday time.Weekday) string {
147 return ebu.daysNarrow[weekday]
150 // WeekdaysNarrow returns the locales narrow weekdays
151 func (ebu *ebu) WeekdaysNarrow() []string {
152 return ebu.daysNarrow
155 // WeekdayShort returns the locales short weekday given the 'weekday' provided
156 func (ebu *ebu) WeekdayShort(weekday time.Weekday) string {
157 return ebu.daysShort[weekday]
160 // WeekdaysShort returns the locales short weekdays
161 func (ebu *ebu) WeekdaysShort() []string {
165 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
166 func (ebu *ebu) WeekdayWide(weekday time.Weekday) string {
167 return ebu.daysWide[weekday]
170 // WeekdaysWide returns the locales wide weekdays
171 func (ebu *ebu) WeekdaysWide() []string {
175 // Decimal returns the decimal point of number
176 func (ebu *ebu) Decimal() string {
180 // Group returns the group of number
181 func (ebu *ebu) Group() string {
185 // Group returns the minus sign of number
186 func (ebu *ebu) Minus() string {
190 // FmtNumber returns 'num' with digits/precision of 'v' for 'ebu' and handles both Whole and Real numbers based on 'v'
191 func (ebu *ebu) FmtNumber(num float64, v uint64) string {
193 return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
196 // FmtPercent returns 'num' with digits/precision of 'v' for 'ebu' and handles both Whole and Real numbers based on 'v'
197 // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
198 func (ebu *ebu) FmtPercent(num float64, v uint64) string {
199 return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
202 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'ebu'
203 func (ebu *ebu) FmtCurrency(num float64, v uint64, currency currency.Type) string {
205 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
206 symbol := ebu.currencies[currency]
207 l := len(s) + len(symbol) + 0
210 b := make([]byte, 0, l)
212 for i := len(s) - 1; i >= 0; i-- {
215 b = append(b, ebu.decimal[0])
222 b = append(b, ebu.group[0])
232 for j := len(symbol) - 1; j >= 0; j-- {
233 b = append(b, symbol[j])
237 b = append(b, ebu.minus[0])
241 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
242 b[i], b[j] = b[j], b[i]
248 b = append(b, ebu.decimal...)
251 for i := 0; i < 2-int(v); i++ {
259 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'ebu'
260 // in accounting notation.
261 func (ebu *ebu) FmtAccounting(num float64, v uint64, currency currency.Type) string {
263 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
264 symbol := ebu.currencies[currency]
265 l := len(s) + len(symbol) + 2
268 b := make([]byte, 0, l)
270 for i := len(s) - 1; i >= 0; i-- {
273 b = append(b, ebu.decimal[0])
280 b = append(b, ebu.group[0])
292 for j := len(symbol) - 1; j >= 0; j-- {
293 b = append(b, symbol[j])
296 b = append(b, ebu.currencyNegativePrefix[0])
300 for j := len(symbol) - 1; j >= 0; j-- {
301 b = append(b, symbol[j])
307 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
308 b[i], b[j] = b[j], b[i]
314 b = append(b, ebu.decimal...)
317 for i := 0; i < 2-int(v); i++ {
323 b = append(b, ebu.currencyNegativeSuffix...)
329 // FmtDateShort returns the short date representation of 't' for 'ebu'
330 func (ebu *ebu) FmtDateShort(t time.Time) string {
332 b := make([]byte, 0, 32)
338 b = strconv.AppendInt(b, int64(t.Day()), 10)
339 b = append(b, []byte{0x2f}...)
345 b = strconv.AppendInt(b, int64(t.Month()), 10)
347 b = append(b, []byte{0x2f}...)
350 b = strconv.AppendInt(b, int64(t.Year()), 10)
352 b = strconv.AppendInt(b, int64(-t.Year()), 10)
358 // FmtDateMedium returns the medium date representation of 't' for 'ebu'
359 func (ebu *ebu) FmtDateMedium(t time.Time) string {
361 b := make([]byte, 0, 32)
363 b = strconv.AppendInt(b, int64(t.Day()), 10)
364 b = append(b, []byte{0x20}...)
365 b = append(b, ebu.monthsAbbreviated[t.Month()]...)
366 b = append(b, []byte{0x20}...)
369 b = strconv.AppendInt(b, int64(t.Year()), 10)
371 b = strconv.AppendInt(b, int64(-t.Year()), 10)
377 // FmtDateLong returns the long date representation of 't' for 'ebu'
378 func (ebu *ebu) FmtDateLong(t time.Time) string {
380 b := make([]byte, 0, 32)
382 b = strconv.AppendInt(b, int64(t.Day()), 10)
383 b = append(b, []byte{0x20}...)
384 b = append(b, ebu.monthsWide[t.Month()]...)
385 b = append(b, []byte{0x20}...)
388 b = strconv.AppendInt(b, int64(t.Year()), 10)
390 b = strconv.AppendInt(b, int64(-t.Year()), 10)
396 // FmtDateFull returns the full date representation of 't' for 'ebu'
397 func (ebu *ebu) FmtDateFull(t time.Time) string {
399 b := make([]byte, 0, 32)
401 b = append(b, ebu.daysWide[t.Weekday()]...)
402 b = append(b, []byte{0x2c, 0x20}...)
403 b = strconv.AppendInt(b, int64(t.Day()), 10)
404 b = append(b, []byte{0x20}...)
405 b = append(b, ebu.monthsWide[t.Month()]...)
406 b = append(b, []byte{0x20}...)
409 b = strconv.AppendInt(b, int64(t.Year()), 10)
411 b = strconv.AppendInt(b, int64(-t.Year()), 10)
417 // FmtTimeShort returns the short time representation of 't' for 'ebu'
418 func (ebu *ebu) FmtTimeShort(t time.Time) string {
420 b := make([]byte, 0, 32)
426 b = strconv.AppendInt(b, int64(t.Hour()), 10)
427 b = append(b, ebu.timeSeparator...)
433 b = strconv.AppendInt(b, int64(t.Minute()), 10)
438 // FmtTimeMedium returns the medium time representation of 't' for 'ebu'
439 func (ebu *ebu) FmtTimeMedium(t time.Time) string {
441 b := make([]byte, 0, 32)
447 b = strconv.AppendInt(b, int64(t.Hour()), 10)
448 b = append(b, ebu.timeSeparator...)
454 b = strconv.AppendInt(b, int64(t.Minute()), 10)
455 b = append(b, ebu.timeSeparator...)
461 b = strconv.AppendInt(b, int64(t.Second()), 10)
466 // FmtTimeLong returns the long time representation of 't' for 'ebu'
467 func (ebu *ebu) FmtTimeLong(t time.Time) string {
469 b := make([]byte, 0, 32)
475 b = strconv.AppendInt(b, int64(t.Hour()), 10)
476 b = append(b, ebu.timeSeparator...)
482 b = strconv.AppendInt(b, int64(t.Minute()), 10)
483 b = append(b, ebu.timeSeparator...)
489 b = strconv.AppendInt(b, int64(t.Second()), 10)
490 b = append(b, []byte{0x20}...)
498 // FmtTimeFull returns the full time representation of 't' for 'ebu'
499 func (ebu *ebu) FmtTimeFull(t time.Time) string {
501 b := make([]byte, 0, 32)
507 b = strconv.AppendInt(b, int64(t.Hour()), 10)
508 b = append(b, ebu.timeSeparator...)
514 b = strconv.AppendInt(b, int64(t.Minute()), 10)
515 b = append(b, ebu.timeSeparator...)
521 b = strconv.AppendInt(b, int64(t.Second()), 10)
522 b = append(b, []byte{0x20}...)
526 if btz, ok := ebu.timezones[tz]; ok {
527 b = append(b, btz...)