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
25 currencies []string // idx = enum of currency code
26 currencyPositiveSuffix 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 'be' locale
46 func New() locales.Translator {
49 pluralsCardinal: []locales.PluralRule{2, 4, 5, 6},
50 pluralsOrdinal: []locales.PluralRule{4, 6},
51 pluralsRange: []locales.PluralRule{2, 4, 5, 6},
59 currencies: []string{"ADP", "AED", "AFA", "AFN", "ALK", "ALL", "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", "BRL", "BRN", "BRR", "BRZ", "BSD", "BTN", "BUK", "BWP", "BYB", "Br", "BYR", "BZD", "CAD", "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", "¥", "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", "NZD", "OMR", "PAB", "PEI", "PEN", "PES", "PGK", "PHP", "PKR", "PLN", "PLZ", "PTE", "PYG", "QAR", "RHD", "ROL", "RON", "RSD", "₽", "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", "NT$", "TZS", "UAH", "UAK", "UGS", "UGX", "$", "USN", "USS", "UYI", "UYP", "UYU", "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"},
61 currencyPositiveSuffix: " ",
62 currencyNegativeSuffix: " ",
63 monthsAbbreviated: []string{"", "сту", "лют", "сак", "кра", "мая", "чэр", "ліп", "жні", "вер", "кас", "ліс", "сне"},
64 monthsNarrow: []string{"", "с", "л", "с", "к", "м", "ч", "л", "ж", "в", "к", "л", "с"},
65 monthsWide: []string{"", "студзеня", "лютага", "сакавіка", "красавіка", "мая", "чэрвеня", "ліпеня", "жніўня", "верасня", "кастрычніка", "лістапада", "снежня"},
66 daysAbbreviated: []string{"нд", "пн", "аў", "ср", "чц", "пт", "сб"},
67 daysNarrow: []string{"н", "п", "а", "с", "ч", "п", "с"},
68 daysShort: []string{"нд", "пн", "аў", "ср", "чц", "пт", "сб"},
69 daysWide: []string{"нядзеля", "панядзелак", "аўторак", "серада", "чацвер", "пятніца", "субота"},
70 periodsAbbreviated: []string{"AM", "PM"},
71 periodsNarrow: []string{"am", "pm"},
72 periodsWide: []string{"AM", "PM"},
73 erasAbbreviated: []string{"да н.э.", "н.э."},
74 erasNarrow: []string{"", ""},
75 erasWide: []string{"да нараджэння Хрыстова", "ад нараджэння Хрыстова"},
76 timezones: map[string]string{"SGT": "Сінгапурскі час", "EAT": "Усходнеафрыканскі час", "SAST": "Паўднёваафрыканскі час", "HKT": "Стандартны час Ганконга", "WEZ": "Заходнееўрапейскі стандартны час", "HEPMX": "Мексіканскі ціхаакіянскі летні час", "HEOG": "Летні час Заходняй Грэнландыі", "HECU": "Летні час Кубы", "SRT": "Час Сурынама", "AST": "Атлантычны стандартны час", "GFT": "Час Французскай Гвіяны", "AKDT": "Летні час Аляскі", "CDT": "Паўночнаамерыканскі цэнтральны летні час", "ACWDT": "Заходні летні час Цэнтральнай Аўстраліі", "OEZ": "Усходнееўрапейскі стандартны час", "AKST": "Стандартны час Аляскі", "CST": "Паўночнаамерыканскі цэнтральны стандартны час", "ACWST": "Заходні стандартны час Цэнтральнай Аўстраліі", "HADT": "Гавайска-Алеуцкі летні час", "LHDT": "Летні час Лорд-Хау", "HNEG": "Стандартны час Усходняй Грэнландыі", "CLST": "Чылійскі летні час", "PDT": "Ціхаакіянскі летні час", "HEPM": "Стандартны летні час Сен-П’ер і Мікелон", "UYT": "Уругвайскі стандартны час", "MEZ": "Цэнтральнаеўрапейскі стандартны час", "WARST": "Летні час Заходняй Аргенціны", "HKST": "Летні час Ганконга", "CLT": "Чылійскі стандартны час", "COT": "Калумбійскі стандартны час", "EDT": "Паўночнаамерыканскі ўсходні летні час", "∅∅∅": "Амазонскі летні час", "WIB": "Заходнеінданезійскі час", "HNNOMX": "Паўночна-заходні мексіканскі стандартны час", "WAT": "Заходнеафрыканскі стандартны час", "HNPMX": "Мексіканскі ціхаакіянскі стандатны час", "LHST": "Стандартны час Лорд-Хау", "WITA": "Цэнтральнаінданезійскі час", "HAT": "Ньюфаўндлендскі летні час", "WESZ": "Заходнееўрапейскі летні час", "VET": "Венесуэльскі час", "IST": "Час Індыі", "ARST": "Аргенцінскі летні час", "ECT": "Эквадорскі час", "CHAST": "Стандартны час Чатэма", "BT": "Час Бутана", "MYT": "Час Малайзіі", "NZST": "Стандартны час Новай Зеландыі", "NZDT": "Летні час Новай Зеландыі", "TMST": "Летні час Туркменістана", "OESZ": "Усходнееўрапейскі летні час", "ACDT": "Летні час цэнтральнай Аўстраліі", "PST": "Ціхаакіянскі стандартны час", "JST": "Стандартны час Японіі", "HNOG": "Стандартны час Заходняй Грэнландыі", "ACST": "Стандартны час цэнтральнай Аўстраліі", "GMT": "Час па Грынвічы", "HENOMX": "Паўночна-заходні мексіканскі летні час", "AEDT": "Летні час усходняй Аўстраліі", "CHADT": "Летні час Чатэма", "HNPM": "Стандартны час Сен-П’ер і Мікелон", "MDT": "MDT", "UYST": "Уругвайскі летні час", "HAST": "Гавайска-Алеуцкі стандартны час", "WAST": "Заходнеафрыканскі летні час", "HNT": "Ньюфаўндлендскі стандартны час", "EST": "Паўночнаамерыканскі ўсходні стандартны час", "GYT": "Час Гаяны", "ChST": "Час Чамора", "BOT": "Балівійскі час", "AWST": "Стандартны час заходняй Аўстраліі", "AWDT": "Летні час заходняй Аўстраліі", "WIT": "Усходнеінданезійскі час", "MESZ": "Цэнтральнаеўрапейскі летні час", "HEEG": "Летні час Усходняй Грэнландыі", "HNCU": "Стандартны час Кубы", "TMT": "Стандартны час Туркменістана", "ADT": "Атлантычны летні час", "COST": "Калумбійскі летні час", "CAT": "Цэнтральнаафрыканскі час", "MST": "MST", "WART": "Стандартны час Заходняй Аргенціны", "JDT": "Летні час Японіі", "AEST": "Стандартны час усходняй Аўстраліі", "ART": "Аргенцінскі стандартны час"},
80 // Locale returns the current translators string locale
81 func (be *be) Locale() string {
85 // PluralsCardinal returns the list of cardinal plural rules associated with 'be'
86 func (be *be) PluralsCardinal() []locales.PluralRule {
87 return be.pluralsCardinal
90 // PluralsOrdinal returns the list of ordinal plural rules associated with 'be'
91 func (be *be) PluralsOrdinal() []locales.PluralRule {
92 return be.pluralsOrdinal
95 // PluralsRange returns the list of range plural rules associated with 'be'
96 func (be *be) PluralsRange() []locales.PluralRule {
97 return be.pluralsRange
100 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'be'
101 func (be *be) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
104 nMod10 := math.Mod(n, 10)
105 nMod100 := math.Mod(n, 100)
107 if nMod10 == 1 && nMod100 != 11 {
108 return locales.PluralRuleOne
109 } else if nMod10 >= 2 && nMod10 <= 4 && (nMod100 < 12 || nMod100 > 14) {
110 return locales.PluralRuleFew
111 } else if (nMod10 == 0) || (nMod10 >= 5 && nMod10 <= 9) || (nMod100 >= 11 && nMod100 <= 14) {
112 return locales.PluralRuleMany
115 return locales.PluralRuleOther
118 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'be'
119 func (be *be) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
122 nMod10 := math.Mod(n, 10)
123 nMod100 := math.Mod(n, 100)
125 if (nMod10 == 2 || nMod10 == 3) && (nMod100 != 12 && nMod100 != 13) {
126 return locales.PluralRuleFew
129 return locales.PluralRuleOther
132 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'be'
133 func (be *be) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
135 start := be.CardinalPluralRule(num1, v1)
136 end := be.CardinalPluralRule(num2, v2)
138 if start == locales.PluralRuleOne && end == locales.PluralRuleOne {
139 return locales.PluralRuleOne
140 } else if start == locales.PluralRuleOne && end == locales.PluralRuleFew {
141 return locales.PluralRuleFew
142 } else if start == locales.PluralRuleOne && end == locales.PluralRuleMany {
143 return locales.PluralRuleMany
144 } else if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
145 return locales.PluralRuleOther
146 } else if start == locales.PluralRuleFew && end == locales.PluralRuleOne {
147 return locales.PluralRuleOne
148 } else if start == locales.PluralRuleFew && end == locales.PluralRuleFew {
149 return locales.PluralRuleFew
150 } else if start == locales.PluralRuleFew && end == locales.PluralRuleMany {
151 return locales.PluralRuleMany
152 } else if start == locales.PluralRuleFew && end == locales.PluralRuleOther {
153 return locales.PluralRuleOther
154 } else if start == locales.PluralRuleMany && end == locales.PluralRuleOne {
155 return locales.PluralRuleOne
156 } else if start == locales.PluralRuleMany && end == locales.PluralRuleFew {
157 return locales.PluralRuleFew
158 } else if start == locales.PluralRuleMany && end == locales.PluralRuleMany {
159 return locales.PluralRuleMany
160 } else if start == locales.PluralRuleMany && end == locales.PluralRuleOther {
161 return locales.PluralRuleOther
162 } else if start == locales.PluralRuleOther && end == locales.PluralRuleOne {
163 return locales.PluralRuleOne
164 } else if start == locales.PluralRuleOther && end == locales.PluralRuleFew {
165 return locales.PluralRuleFew
166 } else if start == locales.PluralRuleOther && end == locales.PluralRuleMany {
167 return locales.PluralRuleMany
170 return locales.PluralRuleOther
174 // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
175 func (be *be) MonthAbbreviated(month time.Month) string {
176 return be.monthsAbbreviated[month]
179 // MonthsAbbreviated returns the locales abbreviated months
180 func (be *be) MonthsAbbreviated() []string {
181 return be.monthsAbbreviated[1:]
184 // MonthNarrow returns the locales narrow month given the 'month' provided
185 func (be *be) MonthNarrow(month time.Month) string {
186 return be.monthsNarrow[month]
189 // MonthsNarrow returns the locales narrow months
190 func (be *be) MonthsNarrow() []string {
191 return be.monthsNarrow[1:]
194 // MonthWide returns the locales wide month given the 'month' provided
195 func (be *be) MonthWide(month time.Month) string {
196 return be.monthsWide[month]
199 // MonthsWide returns the locales wide months
200 func (be *be) MonthsWide() []string {
201 return be.monthsWide[1:]
204 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
205 func (be *be) WeekdayAbbreviated(weekday time.Weekday) string {
206 return be.daysAbbreviated[weekday]
209 // WeekdaysAbbreviated returns the locales abbreviated weekdays
210 func (be *be) WeekdaysAbbreviated() []string {
211 return be.daysAbbreviated
214 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
215 func (be *be) WeekdayNarrow(weekday time.Weekday) string {
216 return be.daysNarrow[weekday]
219 // WeekdaysNarrow returns the locales narrow weekdays
220 func (be *be) WeekdaysNarrow() []string {
224 // WeekdayShort returns the locales short weekday given the 'weekday' provided
225 func (be *be) WeekdayShort(weekday time.Weekday) string {
226 return be.daysShort[weekday]
229 // WeekdaysShort returns the locales short weekdays
230 func (be *be) WeekdaysShort() []string {
234 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
235 func (be *be) WeekdayWide(weekday time.Weekday) string {
236 return be.daysWide[weekday]
239 // WeekdaysWide returns the locales wide weekdays
240 func (be *be) WeekdaysWide() []string {
244 // Decimal returns the decimal point of number
245 func (be *be) Decimal() string {
249 // Group returns the group of number
250 func (be *be) Group() string {
254 // Group returns the minus sign of number
255 func (be *be) Minus() string {
259 // FmtNumber returns 'num' with digits/precision of 'v' for 'be' and handles both Whole and Real numbers based on 'v'
260 func (be *be) FmtNumber(num float64, v uint64) string {
262 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
263 l := len(s) + 2 + 2*len(s[:len(s)-int(v)-1])/3
266 b := make([]byte, 0, l)
268 for i := len(s) - 1; i >= 0; i-- {
271 b = append(b, be.decimal[0])
278 for j := len(be.group) - 1; j >= 0; j-- {
279 b = append(b, be.group[j])
291 b = append(b, be.minus[0])
295 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
296 b[i], b[j] = b[j], b[i]
302 // FmtPercent returns 'num' with digits/precision of 'v' for 'be' and handles both Whole and Real numbers based on 'v'
303 // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
304 func (be *be) FmtPercent(num float64, v uint64) string {
305 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
307 b := make([]byte, 0, l)
309 for i := len(s) - 1; i >= 0; i-- {
312 b = append(b, be.decimal[0])
320 b = append(b, be.minus[0])
324 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
325 b[i], b[j] = b[j], b[i]
328 b = append(b, be.percentSuffix...)
330 b = append(b, be.percent...)
335 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'be'
336 func (be *be) FmtCurrency(num float64, v uint64, currency currency.Type) string {
338 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
339 symbol := be.currencies[currency]
340 l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
343 b := make([]byte, 0, l)
345 for i := len(s) - 1; i >= 0; i-- {
348 b = append(b, be.decimal[0])
355 for j := len(be.group) - 1; j >= 0; j-- {
356 b = append(b, be.group[j])
368 b = append(b, be.minus[0])
372 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
373 b[i], b[j] = b[j], b[i]
379 b = append(b, be.decimal...)
382 for i := 0; i < 2-int(v); i++ {
387 b = append(b, be.currencyPositiveSuffix...)
389 b = append(b, symbol...)
394 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'be'
395 // in accounting notation.
396 func (be *be) FmtAccounting(num float64, v uint64, currency currency.Type) string {
398 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
399 symbol := be.currencies[currency]
400 l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
403 b := make([]byte, 0, l)
405 for i := len(s) - 1; i >= 0; i-- {
408 b = append(b, be.decimal[0])
415 for j := len(be.group) - 1; j >= 0; j-- {
416 b = append(b, be.group[j])
429 b = append(b, be.minus[0])
434 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
435 b[i], b[j] = b[j], b[i]
441 b = append(b, be.decimal...)
444 for i := 0; i < 2-int(v); i++ {
450 b = append(b, be.currencyNegativeSuffix...)
451 b = append(b, symbol...)
454 b = append(b, be.currencyPositiveSuffix...)
455 b = append(b, symbol...)
461 // FmtDateShort returns the short date representation of 't' for 'be'
462 func (be *be) FmtDateShort(t time.Time) string {
464 b := make([]byte, 0, 32)
466 b = strconv.AppendInt(b, int64(t.Day()), 10)
467 b = append(b, []byte{0x2e}...)
473 b = strconv.AppendInt(b, int64(t.Month()), 10)
475 b = append(b, []byte{0x2e}...)
478 b = append(b, strconv.Itoa(t.Year())[2:]...)
480 b = append(b, strconv.Itoa(t.Year())[1:]...)
486 // FmtDateMedium returns the medium date representation of 't' for 'be'
487 func (be *be) FmtDateMedium(t time.Time) string {
489 b := make([]byte, 0, 32)
491 b = strconv.AppendInt(b, int64(t.Day()), 10)
492 b = append(b, []byte{0x2e}...)
498 b = strconv.AppendInt(b, int64(t.Month()), 10)
500 b = append(b, []byte{0x2e}...)
503 b = strconv.AppendInt(b, int64(t.Year()), 10)
505 b = strconv.AppendInt(b, int64(-t.Year()), 10)
511 // FmtDateLong returns the long date representation of 't' for 'be'
512 func (be *be) FmtDateLong(t time.Time) string {
514 b := make([]byte, 0, 32)
516 b = strconv.AppendInt(b, int64(t.Day()), 10)
517 b = append(b, []byte{0x20}...)
518 b = append(b, be.monthsWide[t.Month()]...)
519 b = append(b, []byte{0x20}...)
522 b = strconv.AppendInt(b, int64(t.Year()), 10)
524 b = strconv.AppendInt(b, int64(-t.Year()), 10)
527 b = append(b, []byte{0x20, 0xd0, 0xb3}...)
528 b = append(b, []byte{0x2e}...)
533 // FmtDateFull returns the full date representation of 't' for 'be'
534 func (be *be) FmtDateFull(t time.Time) string {
536 b := make([]byte, 0, 32)
538 b = append(b, be.daysWide[t.Weekday()]...)
539 b = append(b, []byte{0x2c, 0x20}...)
540 b = strconv.AppendInt(b, int64(t.Day()), 10)
541 b = append(b, []byte{0x20}...)
542 b = append(b, be.monthsWide[t.Month()]...)
543 b = append(b, []byte{0x20}...)
546 b = strconv.AppendInt(b, int64(t.Year()), 10)
548 b = strconv.AppendInt(b, int64(-t.Year()), 10)
551 b = append(b, []byte{0x20, 0xd0, 0xb3}...)
552 b = append(b, []byte{0x2e}...)
557 // FmtTimeShort returns the short time representation of 't' for 'be'
558 func (be *be) FmtTimeShort(t time.Time) string {
560 b := make([]byte, 0, 32)
566 b = strconv.AppendInt(b, int64(t.Hour()), 10)
567 b = append(b, be.timeSeparator...)
573 b = strconv.AppendInt(b, int64(t.Minute()), 10)
578 // FmtTimeMedium returns the medium time representation of 't' for 'be'
579 func (be *be) FmtTimeMedium(t time.Time) string {
581 b := make([]byte, 0, 32)
587 b = strconv.AppendInt(b, int64(t.Hour()), 10)
588 b = append(b, be.timeSeparator...)
594 b = strconv.AppendInt(b, int64(t.Minute()), 10)
595 b = append(b, be.timeSeparator...)
601 b = strconv.AppendInt(b, int64(t.Second()), 10)
606 // FmtTimeLong returns the long time representation of 't' for 'be'
607 func (be *be) FmtTimeLong(t time.Time) string {
609 b := make([]byte, 0, 32)
615 b = strconv.AppendInt(b, int64(t.Hour()), 10)
616 b = append(b, be.timeSeparator...)
622 b = strconv.AppendInt(b, int64(t.Minute()), 10)
623 b = append(b, be.timeSeparator...)
629 b = strconv.AppendInt(b, int64(t.Second()), 10)
630 b = append(b, []byte{0x20}...)
638 // FmtTimeFull returns the full time representation of 't' for 'be'
639 func (be *be) FmtTimeFull(t time.Time) string {
641 b := make([]byte, 0, 32)
647 b = strconv.AppendInt(b, int64(t.Hour()), 10)
648 b = append(b, be.timeSeparator...)
654 b = strconv.AppendInt(b, int64(t.Minute()), 10)
655 b = append(b, be.timeSeparator...)
661 b = strconv.AppendInt(b, int64(t.Second()), 10)
662 b = append(b, []byte{0x2c, 0x20}...)
666 if btz, ok := be.timezones[tz]; ok {
667 b = append(b, btz...)