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 currencyPositivePrefix string
26 currencyNegativePrefix 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 'mn' locale
45 func New() locales.Translator {
48 pluralsCardinal: []locales.PluralRule{2, 6},
49 pluralsOrdinal: []locales.PluralRule{6},
50 pluralsRange: []locales.PluralRule{2, 6},
58 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", "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", "₮", "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", "$", "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"},
59 currencyPositivePrefix: " ",
60 currencyNegativePrefix: " ",
61 monthsAbbreviated: []string{"", "1-р сар", "2-р сар", "3-р сар", "4-р сар", "5-р сар", "6-р сар", "7-р сар", "8-р сар", "9-р сар", "10-р сар", "11-р сар", "12-р сар"},
62 monthsNarrow: []string{"", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"},
63 monthsWide: []string{"", "Нэгдүгээр сар", "Хоёрдугаар сар", "Гуравдугаар сар", "Дөрөвдүгээр сар", "Тавдугаар сар", "Зургадугаар сар", "Долдугаар сар", "Наймдугаар сар", "Есдүгээр сар", "Аравдугаар сар", "Арван нэгдүгээр сар", "Арван хоёрдугаар сар"},
64 daysAbbreviated: []string{"Ня", "Да", "Мя", "Лх", "Пү", "Ба", "Бя"},
65 daysNarrow: []string{"Ня", "Да", "Мя", "Лх", "Пү", "Ба", "Бя"},
66 daysShort: []string{"Ня", "Да", "Мя", "Лх", "Пү", "Ба", "Бя"},
67 daysWide: []string{"ням", "даваа", "мягмар", "лхагва", "пүрэв", "баасан", "бямба"},
68 periodsAbbreviated: []string{"ҮӨ", "ҮХ"},
69 periodsNarrow: []string{"үө", "үх"},
70 periodsWide: []string{"ү.ө", "ү.х"},
71 erasAbbreviated: []string{"м.э.ө", "м.э."},
72 erasNarrow: []string{"МЭӨ", "МЭ"},
73 erasWide: []string{"манай эриний өмнөх", "манай эриний"},
74 timezones: map[string]string{"NZDT": "Шинэ Зеландын зуны цаг", "CHADT": "Чатемын зуны цаг", "HEPM": "Сент-Пьер ба Микелоны зуны цаг", "BT": "Бутаны цаг", "AWST": "Австралийн баруун эргийн стандарт цаг", "AEST": "Австралийн зүүн эргийн стандарт цаг", "AEDT": "Австралийн зүүн эргийн зуны цаг", "AKDT": "Аляскийн зуны цаг", "ACST": "Төв Австралийн стандарт цаг", "CST": "Төв стандарт цаг", "UYST": "Уругвайн зуны цаг", "LHST": "Лорд Хоугийн стандарт цаг", "AST": "Атлантын стандарт цаг", "HAT": "Нью-Фаундлендын зуны цаг", "HKT": "Хонг Конгийн стандарт цаг", "∅∅∅": "Перугийн зуны цаг", "MST": "MST", "AWDT": "Австралийн баруун эргийн зуны цаг", "JST": "Японы стандарт цаг", "SRT": "Суринамын цаг", "ACWST": "Австралийн төв баруун эргийн стандарт цаг", "ECT": "Эквадорын цаг", "EST": "Зүүн эргийн стандарт цаг", "HEPMX": "Мексикийн номхон далайн зуны цаг", "HECU": "Кубын зуны цаг", "NZST": "Шинэ Зеландын стандарт цаг", "OESZ": "Зүүн Европын зуны цаг", "HNPMX": "Мексикийн номхон далайн стандарт цаг", "VET": "Венесуэлийн цаг", "HEOG": "Баруун Гринландын зуны цаг", "HEEG": "Зүүн Гринландын зуны цаг", "WIT": "Зүүн Индонезийн цаг", "TMT": "Туркменистаны стандарт цаг", "HNOG": "Баруун Гринландын стандарт цаг", "WEZ": "Баруун Европын стандарт цаг", "CHAST": "Чатемын стандарт цаг", "HNPM": "Сент-Пьерре ба Микелоны стандарт цаг", "MDT": "MDT", "MYT": "Малайзын цаг", "EDT": "Зүүн эргийн зуны цаг", "AKST": "Аляскийн стандарт цаг", "CLST": "Чилийн зуны цаг", "MESZ": "Төв Европын зуны цаг", "OEZ": "Зүүн Европын стандарт цаг", "LHDT": "Лорд Хоугийн зуны цаг", "CLT": "Чилийн стандарт цаг", "HKST": "Хонг Конгийн зуны цаг", "COT": "Колумбын стандарт цаг", "COST": "Колумбын зуны цаг", "GFT": "Францын Гияанагийн цаг", "GMT": "Гринвичийн үндсэн цаг", "PDT": "Номхон далайн зуны цаг", "UYT": "Уругвайн стандарт цаг", "TMST": "Туркменистаны зуны цаг", "HENOMX": "Баруун хойд Мексикийн зуны цаг", "ART": "Аргентины стандарт цаг", "EAT": "Зүүн Африкийн цаг", "SAST": "Өмнөд Африкийн стандарт цаг", "PST": "Номхон далайн стандарт цаг", "CDT": "Төв зуны цаг", "ACWDT": "Австралийн төв баруун эргийн зуны цаг", "MEZ": "Төв Европын стандарт цаг", "WAST": "Баруун Африкийн зуны цаг", "ACDT": "Төв Австралийн зуны цаг", "ADT": "Атлантын зуны цаг", "ARST": "Аргентины зуны цаг", "WIB": "Баруун Индонезийн цаг", "HNCU": "Кубын стандарт цаг", "HAST": "Хавай-Алеутын стандарт цаг", "IST": "Энэтхэгийн цаг", "WITA": "Төв Индонезийн цаг", "WARST": "Баруун Аргентины зуны цаг", "WAT": "Баруун Африкийн стандарт цаг", "GYT": "Гуяанагийн цаг", "HADT": "Хавай-Алеутын зуны цаг", "JDT": "Японы зуны цаг", "HNT": "Нью-Фаундлендын стандарт цаг", "SGT": "Сингапурын цаг", "ChST": "Чаморрогийн цаг", "BOT": "Боливийн цаг", "HNNOMX": "Баруун хойд Мексикийн стандарт цаг", "CAT": "Төв Африкийн цаг", "WESZ": "Баруун Европын зуны цаг", "WART": "Баруун Аргентины стандарт цаг", "HNEG": "Зүүн Гринландын стандарт цаг"},
78 // Locale returns the current translators string locale
79 func (mn *mn) Locale() string {
83 // PluralsCardinal returns the list of cardinal plural rules associated with 'mn'
84 func (mn *mn) PluralsCardinal() []locales.PluralRule {
85 return mn.pluralsCardinal
88 // PluralsOrdinal returns the list of ordinal plural rules associated with 'mn'
89 func (mn *mn) PluralsOrdinal() []locales.PluralRule {
90 return mn.pluralsOrdinal
93 // PluralsRange returns the list of range plural rules associated with 'mn'
94 func (mn *mn) PluralsRange() []locales.PluralRule {
95 return mn.pluralsRange
98 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'mn'
99 func (mn *mn) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
104 return locales.PluralRuleOne
107 return locales.PluralRuleOther
110 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'mn'
111 func (mn *mn) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
112 return locales.PluralRuleOther
115 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'mn'
116 func (mn *mn) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
118 start := mn.CardinalPluralRule(num1, v1)
119 end := mn.CardinalPluralRule(num2, v2)
121 if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
122 return locales.PluralRuleOther
123 } else if start == locales.PluralRuleOther && end == locales.PluralRuleOne {
124 return locales.PluralRuleOne
127 return locales.PluralRuleOther
131 // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
132 func (mn *mn) MonthAbbreviated(month time.Month) string {
133 return mn.monthsAbbreviated[month]
136 // MonthsAbbreviated returns the locales abbreviated months
137 func (mn *mn) MonthsAbbreviated() []string {
138 return mn.monthsAbbreviated[1:]
141 // MonthNarrow returns the locales narrow month given the 'month' provided
142 func (mn *mn) MonthNarrow(month time.Month) string {
143 return mn.monthsNarrow[month]
146 // MonthsNarrow returns the locales narrow months
147 func (mn *mn) MonthsNarrow() []string {
148 return mn.monthsNarrow[1:]
151 // MonthWide returns the locales wide month given the 'month' provided
152 func (mn *mn) MonthWide(month time.Month) string {
153 return mn.monthsWide[month]
156 // MonthsWide returns the locales wide months
157 func (mn *mn) MonthsWide() []string {
158 return mn.monthsWide[1:]
161 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
162 func (mn *mn) WeekdayAbbreviated(weekday time.Weekday) string {
163 return mn.daysAbbreviated[weekday]
166 // WeekdaysAbbreviated returns the locales abbreviated weekdays
167 func (mn *mn) WeekdaysAbbreviated() []string {
168 return mn.daysAbbreviated
171 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
172 func (mn *mn) WeekdayNarrow(weekday time.Weekday) string {
173 return mn.daysNarrow[weekday]
176 // WeekdaysNarrow returns the locales narrow weekdays
177 func (mn *mn) WeekdaysNarrow() []string {
181 // WeekdayShort returns the locales short weekday given the 'weekday' provided
182 func (mn *mn) WeekdayShort(weekday time.Weekday) string {
183 return mn.daysShort[weekday]
186 // WeekdaysShort returns the locales short weekdays
187 func (mn *mn) WeekdaysShort() []string {
191 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
192 func (mn *mn) WeekdayWide(weekday time.Weekday) string {
193 return mn.daysWide[weekday]
196 // WeekdaysWide returns the locales wide weekdays
197 func (mn *mn) WeekdaysWide() []string {
201 // Decimal returns the decimal point of number
202 func (mn *mn) Decimal() string {
206 // Group returns the group of number
207 func (mn *mn) Group() string {
211 // Group returns the minus sign of number
212 func (mn *mn) Minus() string {
216 // FmtNumber returns 'num' with digits/precision of 'v' for 'mn' and handles both Whole and Real numbers based on 'v'
217 func (mn *mn) FmtNumber(num float64, v uint64) string {
219 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
220 l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
223 b := make([]byte, 0, l)
225 for i := len(s) - 1; i >= 0; i-- {
228 b = append(b, mn.decimal[0])
235 b = append(b, mn.group[0])
246 b = append(b, mn.minus[0])
250 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
251 b[i], b[j] = b[j], b[i]
257 // FmtPercent returns 'num' with digits/precision of 'v' for 'mn' and handles both Whole and Real numbers based on 'v'
258 // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
259 func (mn *mn) FmtPercent(num float64, v uint64) string {
260 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
262 b := make([]byte, 0, l)
264 for i := len(s) - 1; i >= 0; i-- {
267 b = append(b, mn.decimal[0])
275 b = append(b, mn.minus[0])
279 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
280 b[i], b[j] = b[j], b[i]
283 b = append(b, mn.percent...)
288 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'mn'
289 func (mn *mn) FmtCurrency(num float64, v uint64, currency currency.Type) string {
291 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
292 symbol := mn.currencies[currency]
293 l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
296 b := make([]byte, 0, l)
298 for i := len(s) - 1; i >= 0; i-- {
301 b = append(b, mn.decimal[0])
308 b = append(b, mn.group[0])
318 for j := len(symbol) - 1; j >= 0; j-- {
319 b = append(b, symbol[j])
322 for j := len(mn.currencyPositivePrefix) - 1; j >= 0; j-- {
323 b = append(b, mn.currencyPositivePrefix[j])
327 b = append(b, mn.minus[0])
331 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
332 b[i], b[j] = b[j], b[i]
338 b = append(b, mn.decimal...)
341 for i := 0; i < 2-int(v); i++ {
349 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'mn'
350 // in accounting notation.
351 func (mn *mn) FmtAccounting(num float64, v uint64, currency currency.Type) string {
353 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
354 symbol := mn.currencies[currency]
355 l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
358 b := make([]byte, 0, l)
360 for i := len(s) - 1; i >= 0; i-- {
363 b = append(b, mn.decimal[0])
370 b = append(b, mn.group[0])
382 for j := len(symbol) - 1; j >= 0; j-- {
383 b = append(b, symbol[j])
386 for j := len(mn.currencyNegativePrefix) - 1; j >= 0; j-- {
387 b = append(b, mn.currencyNegativePrefix[j])
390 b = append(b, mn.minus[0])
394 for j := len(symbol) - 1; j >= 0; j-- {
395 b = append(b, symbol[j])
398 for j := len(mn.currencyPositivePrefix) - 1; j >= 0; j-- {
399 b = append(b, mn.currencyPositivePrefix[j])
405 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
406 b[i], b[j] = b[j], b[i]
412 b = append(b, mn.decimal...)
415 for i := 0; i < 2-int(v); i++ {
423 // FmtDateShort returns the short date representation of 't' for 'mn'
424 func (mn *mn) FmtDateShort(t time.Time) string {
426 b := make([]byte, 0, 32)
429 b = strconv.AppendInt(b, int64(t.Year()), 10)
431 b = strconv.AppendInt(b, int64(-t.Year()), 10)
434 b = append(b, []byte{0x2d}...)
440 b = strconv.AppendInt(b, int64(t.Month()), 10)
442 b = append(b, []byte{0x2d}...)
448 b = strconv.AppendInt(b, int64(t.Day()), 10)
453 // FmtDateMedium returns the medium date representation of 't' for 'mn'
454 func (mn *mn) FmtDateMedium(t time.Time) string {
456 b := make([]byte, 0, 32)
459 b = strconv.AppendInt(b, int64(t.Year()), 10)
461 b = strconv.AppendInt(b, int64(-t.Year()), 10)
464 b = append(b, []byte{0x20}...)
465 b = append(b, mn.monthsAbbreviated[t.Month()]...)
466 b = append(b, []byte{0x20}...)
467 b = strconv.AppendInt(b, int64(t.Day()), 10)
472 // FmtDateLong returns the long date representation of 't' for 'mn'
473 func (mn *mn) FmtDateLong(t time.Time) string {
475 b := make([]byte, 0, 32)
478 b = strconv.AppendInt(b, int64(t.Year()), 10)
480 b = strconv.AppendInt(b, int64(-t.Year()), 10)
483 b = append(b, []byte{0xd0, 0xbe, 0xd0, 0xbd, 0xd1, 0x8b}...)
484 b = append(b, []byte{0x20}...)
485 b = append(b, mn.monthsWide[t.Month()]...)
486 b = append(b, []byte{0xd1, 0x81, 0xd0, 0xb0, 0xd1, 0x80, 0xd1, 0x8b, 0xd0, 0xbd}...)
487 b = append(b, []byte{0x20}...)
488 b = strconv.AppendInt(b, int64(t.Day()), 10)
489 b = append(b, []byte{0xd3, 0xa9, 0xd0, 0xb4, 0xd3, 0xa9, 0xd1, 0x80}...)
494 // FmtDateFull returns the full date representation of 't' for 'mn'
495 func (mn *mn) FmtDateFull(t time.Time) string {
497 b := make([]byte, 0, 32)
499 b = append(b, mn.daysWide[t.Weekday()]...)
500 b = append(b, []byte{0x2c, 0x20}...)
503 b = strconv.AppendInt(b, int64(t.Year()), 10)
505 b = strconv.AppendInt(b, int64(-t.Year()), 10)
508 b = append(b, []byte{0x20, 0xd0, 0xbe, 0xd0, 0xbd, 0xd1, 0x8b}...)
509 b = append(b, []byte{0x20}...)
515 b = strconv.AppendInt(b, int64(t.Month()), 10)
517 b = append(b, []byte{0x20, 0xd1, 0x81, 0xd0, 0xb0, 0xd1, 0x80, 0xd1, 0x8b, 0xd0, 0xbd}...)
518 b = append(b, []byte{0x20}...)
519 b = strconv.AppendInt(b, int64(t.Day()), 10)
524 // FmtTimeShort returns the short time representation of 't' for 'mn'
525 func (mn *mn) FmtTimeShort(t time.Time) string {
527 b := make([]byte, 0, 32)
533 b = strconv.AppendInt(b, int64(t.Hour()), 10)
534 b = append(b, mn.timeSeparator...)
540 b = strconv.AppendInt(b, int64(t.Minute()), 10)
545 // FmtTimeMedium returns the medium time representation of 't' for 'mn'
546 func (mn *mn) FmtTimeMedium(t time.Time) string {
548 b := make([]byte, 0, 32)
554 b = strconv.AppendInt(b, int64(t.Hour()), 10)
555 b = append(b, mn.timeSeparator...)
561 b = strconv.AppendInt(b, int64(t.Minute()), 10)
562 b = append(b, mn.timeSeparator...)
568 b = strconv.AppendInt(b, int64(t.Second()), 10)
573 // FmtTimeLong returns the long time representation of 't' for 'mn'
574 func (mn *mn) FmtTimeLong(t time.Time) string {
576 b := make([]byte, 0, 32)
582 b = strconv.AppendInt(b, int64(t.Hour()), 10)
583 b = append(b, mn.timeSeparator...)
589 b = strconv.AppendInt(b, int64(t.Minute()), 10)
590 b = append(b, mn.timeSeparator...)
596 b = strconv.AppendInt(b, int64(t.Second()), 10)
597 b = append(b, []byte{0x20}...)
605 // FmtTimeFull returns the full time representation of 't' for 'mn'
606 func (mn *mn) FmtTimeFull(t time.Time) string {
608 b := make([]byte, 0, 32)
614 b = strconv.AppendInt(b, int64(t.Hour()), 10)
615 b = append(b, mn.timeSeparator...)
621 b = strconv.AppendInt(b, int64(t.Minute()), 10)
622 b = append(b, mn.timeSeparator...)
628 b = strconv.AppendInt(b, int64(t.Second()), 10)
629 b = append(b, []byte{0x20}...)
633 if btz, ok := mn.timezones[tz]; ok {
634 b = append(b, btz...)