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 'ms' locale
45 func New() locales.Translator {
48 pluralsCardinal: []locales.PluralRule{6},
49 pluralsOrdinal: []locales.PluralRule{2, 6},
50 pluralsRange: []locales.PluralRule{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", "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", "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", "MXN", "MXP", "MXV", "RM", "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", "THB", "TJR", "TJS", "TMM", "TMT", "TND", "TOP", "TPE", "TRL", "TRY", "TTD", "NT$", "TZS", "UAH", "UAK", "UGS", "UGX", "USD", "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 currencyNegativePrefix: "(",
60 currencyNegativeSuffix: ")",
61 monthsAbbreviated: []string{"", "Jan", "Feb", "Mac", "Apr", "Mei", "Jun", "Jul", "Ogo", "Sep", "Okt", "Nov", "Dis"},
62 monthsNarrow: []string{"", "J", "F", "M", "A", "M", "J", "J", "O", "S", "O", "N", "D"},
63 monthsWide: []string{"", "Januari", "Februari", "Mac", "April", "Mei", "Jun", "Julai", "Ogos", "September", "Oktober", "November", "Disember"},
64 daysAbbreviated: []string{"Ahd", "Isn", "Sel", "Rab", "Kha", "Jum", "Sab"},
65 daysNarrow: []string{"A", "I", "S", "R", "K", "J", "S"},
66 daysShort: []string{"Ah", "Is", "Se", "Ra", "Kh", "Ju", "Sa"},
67 daysWide: []string{"Ahad", "Isnin", "Selasa", "Rabu", "Khamis", "Jumaat", "Sabtu"},
68 periodsAbbreviated: []string{"PG", "PTG"},
69 periodsNarrow: []string{"a", "p"},
70 periodsWide: []string{"PG", "PTG"},
71 erasAbbreviated: []string{"S.M.", "TM"},
72 erasNarrow: []string{"", ""},
73 erasWide: []string{"S.M.", "TM"},
74 timezones: map[string]string{"WARST": "Waktu Musim Panas Argentina Barat", "LHDT": "Waktu Siang Lord Howe", "EAT": "Waktu Afrika Timur", "HEPM": "Waktu Siang Saint Pierre dan Miquelon", "MDT": "MDT", "UYST": "Waktu Musim Panas Uruguay", "ACWDT": "Waktu Siang Barat Tengah Australia", "NZDT": "Waktu Siang New Zealand", "CLST": "Waktu Musim Panas Chile", "TMT": "Waktu Piawai Turkmenistan", "GFT": "Waktu Guyana Perancis", "HAT": "Waktu Siang Newfoundland", "HEPMX": "Waktu Siang Pasifik Mexico", "PDT": "Waktu Siang Pasifik", "AWDT": "Waktu Siang Australia Barat", "CDT": "Waktu Siang Tengah", "ACWST": "Waktu Piawai Barat Tengah Australia", "ACST": "Waktu Piawai Australia Tengah", "WIT": "Waktu Indonesia Timur", "SAST": "Waktu Piawai Afrika Selatan", "CHADT": "Waktu Siang Chatham", "SRT": "Waktu Suriname", "WAT": "Waktu Piawai Afrika Barat", "OEZ": "Waktu Piawai Eropah Timur", "OESZ": "Waktu Musim Panas Eropah Timur", "LHST": "Waktu Piawai Lord Howe", "HNCU": "Waktu Piawai Cuba", "HECU": "Waktu Siang Cuba", "PST": "Waktu Piawai Pasifik", "BT": "Waktu Bhutan", "BOT": "Waktu Bolivia", "HNOG": "Waktu Piawai Greenland Barat", "WAST": "Waktu Musim Panas Afrika Barat", "HKST": "Waktu Musim Panas Hong Kong", "EST": "Waktu Piawai Timur", "WEZ": "Waktu Piawai Eropah Barat", "HNPMX": "Waktu Piawai Pasifik Mexico", "MESZ": "Waktu Musim Panas Eropah Tengah", "WART": "Waktu Piawai Argentina Barat", "IST": "Waktu Piawai India", "COT": "Waktu Piawai Colombia", "HNPM": "Waktu Piawai Saint Pierre dan Miquelon", "ADT": "Waktu Siang Atlantik", "CAT": "Waktu Afrika Tengah", "HAST": "Waktu Piawai Hawaii-Aleutian", "HADT": "Waktu Siang Hawaii-Aleutian", "AEST": "Waktu Piawai Timur Australia", "WESZ": "Waktu Musim Panas Eropah Barat", "ChST": "Waktu Piawai Chamorro", "WITA": "Waktu Indonesia Tengah", "AEDT": "Waktu Siang Australia Timur", "SGT": "Waktu Piawai Singapura", "JDT": "Waktu Siang Jepun", "AKST": "Waktu Piawai Alaska", "GMT": "Waktu Min Greenwich", "AWST": "Waktu Piawai Australia Barat", "NZST": "Waktu Piawai New Zealand", "VET": "Waktu Venezuela", "HENOMX": "Waktu Siang Barat Laut Mexico", "ECT": "Waktu Ecuador", "CHAST": "Waktu Piawai Chatham", "TMST": "Waktu Musim Panas Turkmenistan", "MEZ": "Waktu Piawai Eropah Tengah", "JST": "Waktu Piawai Jepun", "ART": "Waktu Piawai Argentina", "HKT": "Waktu Piawai Hong Kong", "EDT": "Waktu Siang Timur", "UYT": "Waktu Piawai Uruguay", "ARST": "Waktu Musim Panas Argentina", "HEEG": "Waktu Musim Panas Greenland Timur", "HNT": "Waktu Piawai Newfoundland", "CST": "Waktu Piawai Pusat", "AST": "Waktu Piawai Atlantik", "COST": "Waktu Musim Panas Colombia", "GYT": "Waktu Guyana", "ACDT": "Waktu Siang Australia Tengah", "HEOG": "Waktu Musim Panas Greenland Barat", "AKDT": "Waktu Siang Alaska", "WIB": "Waktu Indonesia Barat", "∅∅∅": "Waktu Musim Panas Brasilia", "MST": "MST", "MYT": "Waktu Malaysia", "HNNOMX": "Waktu Piawai Barat Laut Mexico", "HNEG": "Waktu Piawai Greenland Timur", "CLT": "Waktu Piawai Chile"},
78 // Locale returns the current translators string locale
79 func (ms *ms) Locale() string {
83 // PluralsCardinal returns the list of cardinal plural rules associated with 'ms'
84 func (ms *ms) PluralsCardinal() []locales.PluralRule {
85 return ms.pluralsCardinal
88 // PluralsOrdinal returns the list of ordinal plural rules associated with 'ms'
89 func (ms *ms) PluralsOrdinal() []locales.PluralRule {
90 return ms.pluralsOrdinal
93 // PluralsRange returns the list of range plural rules associated with 'ms'
94 func (ms *ms) PluralsRange() []locales.PluralRule {
95 return ms.pluralsRange
98 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'ms'
99 func (ms *ms) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
100 return locales.PluralRuleOther
103 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'ms'
104 func (ms *ms) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
109 return locales.PluralRuleOne
112 return locales.PluralRuleOther
115 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'ms'
116 func (ms *ms) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
117 return locales.PluralRuleOther
120 // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
121 func (ms *ms) MonthAbbreviated(month time.Month) string {
122 return ms.monthsAbbreviated[month]
125 // MonthsAbbreviated returns the locales abbreviated months
126 func (ms *ms) MonthsAbbreviated() []string {
127 return ms.monthsAbbreviated[1:]
130 // MonthNarrow returns the locales narrow month given the 'month' provided
131 func (ms *ms) MonthNarrow(month time.Month) string {
132 return ms.monthsNarrow[month]
135 // MonthsNarrow returns the locales narrow months
136 func (ms *ms) MonthsNarrow() []string {
137 return ms.monthsNarrow[1:]
140 // MonthWide returns the locales wide month given the 'month' provided
141 func (ms *ms) MonthWide(month time.Month) string {
142 return ms.monthsWide[month]
145 // MonthsWide returns the locales wide months
146 func (ms *ms) MonthsWide() []string {
147 return ms.monthsWide[1:]
150 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
151 func (ms *ms) WeekdayAbbreviated(weekday time.Weekday) string {
152 return ms.daysAbbreviated[weekday]
155 // WeekdaysAbbreviated returns the locales abbreviated weekdays
156 func (ms *ms) WeekdaysAbbreviated() []string {
157 return ms.daysAbbreviated
160 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
161 func (ms *ms) WeekdayNarrow(weekday time.Weekday) string {
162 return ms.daysNarrow[weekday]
165 // WeekdaysNarrow returns the locales narrow weekdays
166 func (ms *ms) WeekdaysNarrow() []string {
170 // WeekdayShort returns the locales short weekday given the 'weekday' provided
171 func (ms *ms) WeekdayShort(weekday time.Weekday) string {
172 return ms.daysShort[weekday]
175 // WeekdaysShort returns the locales short weekdays
176 func (ms *ms) WeekdaysShort() []string {
180 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
181 func (ms *ms) WeekdayWide(weekday time.Weekday) string {
182 return ms.daysWide[weekday]
185 // WeekdaysWide returns the locales wide weekdays
186 func (ms *ms) WeekdaysWide() []string {
190 // Decimal returns the decimal point of number
191 func (ms *ms) Decimal() string {
195 // Group returns the group of number
196 func (ms *ms) Group() string {
200 // Group returns the minus sign of number
201 func (ms *ms) Minus() string {
205 // FmtNumber returns 'num' with digits/precision of 'v' for 'ms' and handles both Whole and Real numbers based on 'v'
206 func (ms *ms) FmtNumber(num float64, v uint64) string {
208 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
209 l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
212 b := make([]byte, 0, l)
214 for i := len(s) - 1; i >= 0; i-- {
217 b = append(b, ms.decimal[0])
224 b = append(b, ms.group[0])
235 b = append(b, ms.minus[0])
239 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
240 b[i], b[j] = b[j], b[i]
246 // FmtPercent returns 'num' with digits/precision of 'v' for 'ms' and handles both Whole and Real numbers based on 'v'
247 // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
248 func (ms *ms) FmtPercent(num float64, v uint64) string {
249 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
251 b := make([]byte, 0, l)
253 for i := len(s) - 1; i >= 0; i-- {
256 b = append(b, ms.decimal[0])
264 b = append(b, ms.minus[0])
268 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
269 b[i], b[j] = b[j], b[i]
272 b = append(b, ms.percent...)
277 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'ms'
278 func (ms *ms) FmtCurrency(num float64, v uint64, currency currency.Type) string {
280 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
281 symbol := ms.currencies[currency]
282 l := len(s) + len(symbol) + 2 + 1*len(s[:len(s)-int(v)-1])/3
285 b := make([]byte, 0, l)
287 for i := len(s) - 1; i >= 0; i-- {
290 b = append(b, ms.decimal[0])
297 b = append(b, ms.group[0])
307 for j := len(symbol) - 1; j >= 0; j-- {
308 b = append(b, symbol[j])
312 b = append(b, ms.minus[0])
316 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
317 b[i], b[j] = b[j], b[i]
323 b = append(b, ms.decimal...)
326 for i := 0; i < 2-int(v); i++ {
334 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'ms'
335 // in accounting notation.
336 func (ms *ms) FmtAccounting(num float64, v uint64, currency currency.Type) string {
338 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
339 symbol := ms.currencies[currency]
340 l := len(s) + len(symbol) + 4 + 1*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, ms.decimal[0])
355 b = append(b, ms.group[0])
367 for j := len(symbol) - 1; j >= 0; j-- {
368 b = append(b, symbol[j])
371 b = append(b, ms.currencyNegativePrefix[0])
375 for j := len(symbol) - 1; j >= 0; j-- {
376 b = append(b, symbol[j])
382 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
383 b[i], b[j] = b[j], b[i]
389 b = append(b, ms.decimal...)
392 for i := 0; i < 2-int(v); i++ {
398 b = append(b, ms.currencyNegativeSuffix...)
404 // FmtDateShort returns the short date representation of 't' for 'ms'
405 func (ms *ms) FmtDateShort(t time.Time) string {
407 b := make([]byte, 0, 32)
409 b = strconv.AppendInt(b, int64(t.Day()), 10)
410 b = append(b, []byte{0x2f}...)
416 b = strconv.AppendInt(b, int64(t.Month()), 10)
418 b = append(b, []byte{0x2f}...)
421 b = append(b, strconv.Itoa(t.Year())[2:]...)
423 b = append(b, strconv.Itoa(t.Year())[1:]...)
429 // FmtDateMedium returns the medium date representation of 't' for 'ms'
430 func (ms *ms) FmtDateMedium(t time.Time) string {
432 b := make([]byte, 0, 32)
434 b = strconv.AppendInt(b, int64(t.Day()), 10)
435 b = append(b, []byte{0x20}...)
436 b = append(b, ms.monthsAbbreviated[t.Month()]...)
437 b = append(b, []byte{0x20}...)
440 b = strconv.AppendInt(b, int64(t.Year()), 10)
442 b = strconv.AppendInt(b, int64(-t.Year()), 10)
448 // FmtDateLong returns the long date representation of 't' for 'ms'
449 func (ms *ms) FmtDateLong(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, ms.monthsWide[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 // FmtDateFull returns the full date representation of 't' for 'ms'
468 func (ms *ms) FmtDateFull(t time.Time) string {
470 b := make([]byte, 0, 32)
472 b = append(b, ms.daysWide[t.Weekday()]...)
473 b = append(b, []byte{0x2c, 0x20}...)
474 b = strconv.AppendInt(b, int64(t.Day()), 10)
475 b = append(b, []byte{0x20}...)
476 b = append(b, ms.monthsWide[t.Month()]...)
477 b = append(b, []byte{0x20}...)
480 b = strconv.AppendInt(b, int64(t.Year()), 10)
482 b = strconv.AppendInt(b, int64(-t.Year()), 10)
488 // FmtTimeShort returns the short time representation of 't' for 'ms'
489 func (ms *ms) FmtTimeShort(t time.Time) string {
491 b := make([]byte, 0, 32)
499 b = strconv.AppendInt(b, int64(h), 10)
500 b = append(b, ms.timeSeparator...)
506 b = strconv.AppendInt(b, int64(t.Minute()), 10)
507 b = append(b, []byte{0x20}...)
510 b = append(b, ms.periodsAbbreviated[0]...)
512 b = append(b, ms.periodsAbbreviated[1]...)
518 // FmtTimeMedium returns the medium time representation of 't' for 'ms'
519 func (ms *ms) FmtTimeMedium(t time.Time) string {
521 b := make([]byte, 0, 32)
529 b = strconv.AppendInt(b, int64(h), 10)
530 b = append(b, ms.timeSeparator...)
536 b = strconv.AppendInt(b, int64(t.Minute()), 10)
537 b = append(b, ms.timeSeparator...)
543 b = strconv.AppendInt(b, int64(t.Second()), 10)
544 b = append(b, []byte{0x20}...)
547 b = append(b, ms.periodsAbbreviated[0]...)
549 b = append(b, ms.periodsAbbreviated[1]...)
555 // FmtTimeLong returns the long time representation of 't' for 'ms'
556 func (ms *ms) FmtTimeLong(t time.Time) string {
558 b := make([]byte, 0, 32)
566 b = strconv.AppendInt(b, int64(h), 10)
567 b = append(b, ms.timeSeparator...)
573 b = strconv.AppendInt(b, int64(t.Minute()), 10)
574 b = append(b, ms.timeSeparator...)
580 b = strconv.AppendInt(b, int64(t.Second()), 10)
581 b = append(b, []byte{0x20}...)
584 b = append(b, ms.periodsAbbreviated[0]...)
586 b = append(b, ms.periodsAbbreviated[1]...)
589 b = append(b, []byte{0x20}...)
597 // FmtTimeFull returns the full time representation of 't' for 'ms'
598 func (ms *ms) FmtTimeFull(t time.Time) string {
600 b := make([]byte, 0, 32)
608 b = strconv.AppendInt(b, int64(h), 10)
609 b = append(b, ms.timeSeparator...)
615 b = strconv.AppendInt(b, int64(t.Minute()), 10)
616 b = append(b, ms.timeSeparator...)
622 b = strconv.AppendInt(b, int64(t.Second()), 10)
623 b = append(b, []byte{0x20}...)
626 b = append(b, ms.periodsAbbreviated[0]...)
628 b = append(b, ms.periodsAbbreviated[1]...)
631 b = append(b, []byte{0x20}...)
635 if btz, ok := ms.timezones[tz]; ok {
636 b = append(b, btz...)