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 currencyPositiveSuffix string
27 currencyNegativePrefix string
28 currencyNegativeSuffix string
29 monthsAbbreviated []string
32 daysAbbreviated []string
36 periodsAbbreviated []string
37 periodsNarrow []string
40 erasAbbreviated []string
43 timezones map[string]string
46 // New returns a new instance of translator for the 'mgh' locale
47 func New() locales.Translator {
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", "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", "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", "MTn", "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"},
57 currencyPositivePrefix: " ",
58 currencyPositiveSuffix: "K",
59 currencyNegativePrefix: " ",
60 currencyNegativeSuffix: "K",
61 monthsAbbreviated: []string{"", "Kwa", "Una", "Rar", "Che", "Tha", "Moc", "Sab", "Nan", "Tis", "Kum", "Moj", "Yel"},
62 monthsNarrow: []string{"", "K", "U", "R", "C", "T", "M", "S", "N", "T", "K", "M", "Y"},
63 monthsWide: []string{"", "Mweri wo kwanza", "Mweri wo unayeli", "Mweri wo uneraru", "Mweri wo unecheshe", "Mweri wo unethanu", "Mweri wo thanu na mocha", "Mweri wo saba", "Mweri wo nane", "Mweri wo tisa", "Mweri wo kumi", "Mweri wo kumi na moja", "Mweri wo kumi na yel’li"},
64 daysAbbreviated: []string{"Sab", "Jtt", "Jnn", "Jtn", "Ara", "Iju", "Jmo"},
65 daysNarrow: []string{"S", "J", "J", "J", "A", "I", "J"},
66 daysWide: []string{"Sabato", "Jumatatu", "Jumanne", "Jumatano", "Arahamisi", "Ijumaa", "Jumamosi"},
67 periodsAbbreviated: []string{"wichishu", "mchochil’l"},
68 periodsWide: []string{"wichishu", "mchochil’l"},
69 erasAbbreviated: []string{"HY", "YY"},
70 erasNarrow: []string{"", ""},
71 erasWide: []string{"Hinapiya yesu", "Yopia yesu"},
72 timezones: map[string]string{"JST": "JST", "OESZ": "OESZ", "MST": "MST", "HEOG": "HEOG", "MYT": "MYT", "TMST": "TMST", "AST": "AST", "COST": "COST", "ACST": "ACST", "HNPMX": "HNPMX", "AWDT": "AWDT", "ACWST": "ACWST", "WART": "WART", "HAT": "HAT", "BT": "BT", "MDT": "MDT", "WAST": "WAST", "ChST": "ChST", "CHAST": "CHAST", "MEZ": "MEZ", "AEDT": "AEDT", "MESZ": "MESZ", "HKST": "HKST", "EDT": "EDT", "WIB": "WIB", "LHDT": "LHDT", "∅∅∅": "∅∅∅", "HNNOMX": "HNNOMX", "HEEG": "HEEG", "ACDT": "ACDT", "CAT": "CAT", "BOT": "BOT", "CST": "CST", "LHST": "LHST", "VET": "VET", "SAST": "SAST", "WAT": "WAT", "CLST": "CLST", "SGT": "SGT", "GMT": "GMT", "TMT": "TMT", "OEZ": "OEZ", "CLT": "CLT", "ECT": "ECT", "HNCU": "HNCU", "CDT": "CDT", "UYST": "UYST", "WIT": "WIT", "ADT": "ADT", "HNOG": "HNOG", "GFT": "GFT", "GYT": "GYT", "PDT": "PDT", "UYT": "UYT", "WARST": "WARST", "ARST": "ARST", "COT": "COT", "EST": "EST", "PST": "PST", "CHADT": "CHADT", "HECU": "HECU", "NZDT": "NZDT", "AEST": "AEST", "AWST": "AWST", "HKT": "HKT", "WESZ": "WESZ", "HEPMX": "HEPMX", "HENOMX": "HENOMX", "IST": "IST", "EAT": "EAT", "AKST": "AKST", "AKDT": "AKDT", "SRT": "SRT", "ACWDT": "ACWDT", "JDT": "JDT", "HNPM": "HNPM", "HNEG": "HNEG", "HNT": "HNT", "WEZ": "WEZ", "HEPM": "HEPM", "WITA": "WITA", "ART": "ART", "NZST": "NZST", "HAST": "HAST", "HADT": "HADT"},
76 // Locale returns the current translators string locale
77 func (mgh *mgh) Locale() string {
81 // PluralsCardinal returns the list of cardinal plural rules associated with 'mgh'
82 func (mgh *mgh) PluralsCardinal() []locales.PluralRule {
83 return mgh.pluralsCardinal
86 // PluralsOrdinal returns the list of ordinal plural rules associated with 'mgh'
87 func (mgh *mgh) PluralsOrdinal() []locales.PluralRule {
88 return mgh.pluralsOrdinal
91 // PluralsRange returns the list of range plural rules associated with 'mgh'
92 func (mgh *mgh) PluralsRange() []locales.PluralRule {
93 return mgh.pluralsRange
96 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'mgh'
97 func (mgh *mgh) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
98 return locales.PluralRuleUnknown
101 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'mgh'
102 func (mgh *mgh) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
103 return locales.PluralRuleUnknown
106 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'mgh'
107 func (mgh *mgh) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
108 return locales.PluralRuleUnknown
111 // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
112 func (mgh *mgh) MonthAbbreviated(month time.Month) string {
113 return mgh.monthsAbbreviated[month]
116 // MonthsAbbreviated returns the locales abbreviated months
117 func (mgh *mgh) MonthsAbbreviated() []string {
118 return mgh.monthsAbbreviated[1:]
121 // MonthNarrow returns the locales narrow month given the 'month' provided
122 func (mgh *mgh) MonthNarrow(month time.Month) string {
123 return mgh.monthsNarrow[month]
126 // MonthsNarrow returns the locales narrow months
127 func (mgh *mgh) MonthsNarrow() []string {
128 return mgh.monthsNarrow[1:]
131 // MonthWide returns the locales wide month given the 'month' provided
132 func (mgh *mgh) MonthWide(month time.Month) string {
133 return mgh.monthsWide[month]
136 // MonthsWide returns the locales wide months
137 func (mgh *mgh) MonthsWide() []string {
138 return mgh.monthsWide[1:]
141 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
142 func (mgh *mgh) WeekdayAbbreviated(weekday time.Weekday) string {
143 return mgh.daysAbbreviated[weekday]
146 // WeekdaysAbbreviated returns the locales abbreviated weekdays
147 func (mgh *mgh) WeekdaysAbbreviated() []string {
148 return mgh.daysAbbreviated
151 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
152 func (mgh *mgh) WeekdayNarrow(weekday time.Weekday) string {
153 return mgh.daysNarrow[weekday]
156 // WeekdaysNarrow returns the locales narrow weekdays
157 func (mgh *mgh) WeekdaysNarrow() []string {
158 return mgh.daysNarrow
161 // WeekdayShort returns the locales short weekday given the 'weekday' provided
162 func (mgh *mgh) WeekdayShort(weekday time.Weekday) string {
163 return mgh.daysShort[weekday]
166 // WeekdaysShort returns the locales short weekdays
167 func (mgh *mgh) WeekdaysShort() []string {
171 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
172 func (mgh *mgh) WeekdayWide(weekday time.Weekday) string {
173 return mgh.daysWide[weekday]
176 // WeekdaysWide returns the locales wide weekdays
177 func (mgh *mgh) WeekdaysWide() []string {
181 // Decimal returns the decimal point of number
182 func (mgh *mgh) Decimal() string {
186 // Group returns the group of number
187 func (mgh *mgh) Group() string {
191 // Group returns the minus sign of number
192 func (mgh *mgh) Minus() string {
196 // FmtNumber returns 'num' with digits/precision of 'v' for 'mgh' and handles both Whole and Real numbers based on 'v'
197 func (mgh *mgh) FmtNumber(num float64, v uint64) string {
199 return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
202 // FmtPercent returns 'num' with digits/precision of 'v' for 'mgh' and handles both Whole and Real numbers based on 'v'
203 // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
204 func (mgh *mgh) FmtPercent(num float64, v uint64) string {
205 return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
208 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'mgh'
209 func (mgh *mgh) FmtCurrency(num float64, v uint64, currency currency.Type) string {
211 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
212 symbol := mgh.currencies[currency]
213 l := len(s) + len(symbol) + 4
215 b := make([]byte, 0, l)
217 for i := len(s) - 1; i >= 0; i-- {
220 b = append(b, mgh.decimal[0])
227 for j := len(symbol) - 1; j >= 0; j-- {
228 b = append(b, symbol[j])
231 for j := len(mgh.currencyPositivePrefix) - 1; j >= 0; j-- {
232 b = append(b, mgh.currencyPositivePrefix[j])
236 b = append(b, mgh.minus[0])
240 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
241 b[i], b[j] = b[j], b[i]
244 b = append(b, mgh.currencyPositiveSuffix...)
249 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'mgh'
250 // in accounting notation.
251 func (mgh *mgh) FmtAccounting(num float64, v uint64, currency currency.Type) string {
253 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
254 symbol := mgh.currencies[currency]
255 l := len(s) + len(symbol) + 4
257 b := make([]byte, 0, l)
259 for i := len(s) - 1; i >= 0; i-- {
262 b = append(b, mgh.decimal[0])
271 for j := len(symbol) - 1; j >= 0; j-- {
272 b = append(b, symbol[j])
275 for j := len(mgh.currencyNegativePrefix) - 1; j >= 0; j-- {
276 b = append(b, mgh.currencyNegativePrefix[j])
279 b = append(b, mgh.minus[0])
283 for j := len(symbol) - 1; j >= 0; j-- {
284 b = append(b, symbol[j])
287 for j := len(mgh.currencyPositivePrefix) - 1; j >= 0; j-- {
288 b = append(b, mgh.currencyPositivePrefix[j])
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]
299 b = append(b, mgh.currencyNegativeSuffix...)
302 b = append(b, mgh.currencyPositiveSuffix...)
308 // FmtDateShort returns the short date representation of 't' for 'mgh'
309 func (mgh *mgh) FmtDateShort(t time.Time) string {
311 b := make([]byte, 0, 32)
317 b = strconv.AppendInt(b, int64(t.Day()), 10)
318 b = append(b, []byte{0x2f}...)
324 b = strconv.AppendInt(b, int64(t.Month()), 10)
326 b = append(b, []byte{0x2f}...)
329 b = strconv.AppendInt(b, int64(t.Year()), 10)
331 b = strconv.AppendInt(b, int64(-t.Year()), 10)
337 // FmtDateMedium returns the medium date representation of 't' for 'mgh'
338 func (mgh *mgh) FmtDateMedium(t time.Time) string {
340 b := make([]byte, 0, 32)
342 b = strconv.AppendInt(b, int64(t.Day()), 10)
343 b = append(b, []byte{0x20}...)
344 b = append(b, mgh.monthsAbbreviated[t.Month()]...)
345 b = append(b, []byte{0x20}...)
348 b = strconv.AppendInt(b, int64(t.Year()), 10)
350 b = strconv.AppendInt(b, int64(-t.Year()), 10)
356 // FmtDateLong returns the long date representation of 't' for 'mgh'
357 func (mgh *mgh) FmtDateLong(t time.Time) string {
359 b := make([]byte, 0, 32)
361 b = strconv.AppendInt(b, int64(t.Day()), 10)
362 b = append(b, []byte{0x20}...)
363 b = append(b, mgh.monthsWide[t.Month()]...)
364 b = append(b, []byte{0x20}...)
367 b = strconv.AppendInt(b, int64(t.Year()), 10)
369 b = strconv.AppendInt(b, int64(-t.Year()), 10)
375 // FmtDateFull returns the full date representation of 't' for 'mgh'
376 func (mgh *mgh) FmtDateFull(t time.Time) string {
378 b := make([]byte, 0, 32)
380 b = append(b, mgh.daysWide[t.Weekday()]...)
381 b = append(b, []byte{0x2c, 0x20}...)
382 b = strconv.AppendInt(b, int64(t.Day()), 10)
383 b = append(b, []byte{0x20}...)
384 b = append(b, mgh.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 // FmtTimeShort returns the short time representation of 't' for 'mgh'
397 func (mgh *mgh) FmtTimeShort(t time.Time) string {
399 b := make([]byte, 0, 32)
405 b = strconv.AppendInt(b, int64(t.Hour()), 10)
406 b = append(b, mgh.timeSeparator...)
412 b = strconv.AppendInt(b, int64(t.Minute()), 10)
417 // FmtTimeMedium returns the medium time representation of 't' for 'mgh'
418 func (mgh *mgh) FmtTimeMedium(t time.Time) string {
420 b := make([]byte, 0, 32)
426 b = strconv.AppendInt(b, int64(t.Hour()), 10)
427 b = append(b, mgh.timeSeparator...)
433 b = strconv.AppendInt(b, int64(t.Minute()), 10)
434 b = append(b, mgh.timeSeparator...)
440 b = strconv.AppendInt(b, int64(t.Second()), 10)
445 // FmtTimeLong returns the long time representation of 't' for 'mgh'
446 func (mgh *mgh) FmtTimeLong(t time.Time) string {
448 b := make([]byte, 0, 32)
454 b = strconv.AppendInt(b, int64(t.Hour()), 10)
455 b = append(b, mgh.timeSeparator...)
461 b = strconv.AppendInt(b, int64(t.Minute()), 10)
462 b = append(b, mgh.timeSeparator...)
468 b = strconv.AppendInt(b, int64(t.Second()), 10)
469 b = append(b, []byte{0x20}...)
477 // FmtTimeFull returns the full time representation of 't' for 'mgh'
478 func (mgh *mgh) FmtTimeFull(t time.Time) string {
480 b := make([]byte, 0, 32)
486 b = strconv.AppendInt(b, int64(t.Hour()), 10)
487 b = append(b, mgh.timeSeparator...)
493 b = strconv.AppendInt(b, int64(t.Minute()), 10)
494 b = append(b, mgh.timeSeparator...)
500 b = strconv.AppendInt(b, int64(t.Second()), 10)
501 b = append(b, []byte{0x20}...)
505 if btz, ok := mgh.timezones[tz]; ok {
506 b = append(b, btz...)