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 currencyPositiveSuffix 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 'vi' 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", "AU$", "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", "MNT", "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", "US$", "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 currencyPositiveSuffix: " ",
60 currencyNegativeSuffix: " ",
61 monthsAbbreviated: []string{"", "thg 1", "thg 2", "thg 3", "thg 4", "thg 5", "thg 6", "thg 7", "thg 8", "thg 9", "thg 10", "thg 11", "thg 12"},
62 monthsNarrow: []string{"", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"},
63 monthsWide: []string{"", "tháng 1", "tháng 2", "tháng 3", "tháng 4", "tháng 5", "tháng 6", "tháng 7", "tháng 8", "tháng 9", "tháng 10", "tháng 11", "tháng 12"},
64 daysAbbreviated: []string{"CN", "Th 2", "Th 3", "Th 4", "Th 5", "Th 6", "Th 7"},
65 daysNarrow: []string{"CN", "T2", "T3", "T4", "T5", "T6", "T7"},
66 daysShort: []string{"CN", "T2", "T3", "T4", "T5", "T6", "T7"},
67 daysWide: []string{"Chủ Nhật", "Thứ Hai", "Thứ Ba", "Thứ Tư", "Thứ Năm", "Thứ Sáu", "Thứ Bảy"},
68 periodsAbbreviated: []string{"SA", "CH"},
69 periodsNarrow: []string{"s", "c"},
70 periodsWide: []string{"SA", "CH"},
71 erasAbbreviated: []string{"", ""},
72 erasNarrow: []string{"tr. CN", "sau CN"},
73 erasWide: []string{"", ""},
74 timezones: map[string]string{"NZDT": "Giờ Mùa Hè New Zealand", "EAT": "Giờ Đông Phi", "GYT": "Giờ Guyana", "PDT": "Giờ Mùa hè Thái Bình Dương", "WIT": "Giờ Miền Đông Indonesia", "HADT": "Giờ Mùa Hè Hawaii-Aleutian", "WART": "Giờ chuẩn miền mây Argentina", "LHDT": "Giờ Mùa Hè Lord Howe", "PST": "Giờ chuẩn Thái Bình Dương", "WESZ": "Giờ Mùa hè Tây Âu", "WIB": "Giờ Miền Tây Indonesia", "TMT": "Giờ Chuẩn Turkmenistan", "HENOMX": "Giờ Mùa Hè Tây Bắc Mexico", "ART": "Giờ Chuẩn Argentina", "HNOG": "Giờ Chuẩn Miền Tây Greenland", "CLST": "Giờ Mùa Hè Chile", "CDT": "Giờ mùa hè miền trung", "MDT": "Giờ Mùa Hè Ma Cao", "VET": "Giờ Venezuela", "AKST": "Giờ Chuẩn Alaska", "HKT": "Giờ Chuẩn Hồng Kông", "SGT": "Giờ Singapore", "CAT": "Giờ Trung Phi", "∅∅∅": "Giờ Mùa Hè Acre", "WARST": "Giờ mùa hè miền tây Argentina", "JDT": "Giờ Mùa Hè Nhật Bản", "OEZ": "Giờ Chuẩn Đông Âu", "GFT": "Giờ Guiana thuộc Pháp", "WEZ": "Giờ Chuẩn Tây Âu", "HNCU": "Giờ Chuẩn Cuba", "BOT": "Giờ Bolivia", "WAST": "Giờ Mùa Hè Tây Phi", "GMT": "Giờ Trung bình Greenwich", "AWST": "Giờ Chuẩn Miền Tây Nước Úc", "UYT": "Giờ Chuẩn Uruguay", "MEZ": "Giờ Chuẩn Trung Âu", "IST": "Giờ Chuẩn Ấn Độ", "AEDT": "Giờ Mùa Hè Miền Đông Nước Úc", "ACWST": "Giờ Chuẩn Miền Trung Tây Nước Úc", "SAST": "Giờ Chuẩn Nam Phi", "EDT": "Giờ mùa hè miền đông", "HEPMX": "Giờ Mùa Hè Thái Bình Dương Mexico", "ChST": "Giờ Chamorro", "OESZ": "Giờ Mùa Hè Đông Âu", "HEEG": "Giờ Mùa Hè Miền Đông Greenland", "AWDT": "Giờ Mùa Hè Miền Tây Nước Úc", "HEOG": "Giờ Mùa Hè Miền Tây Greenland", "ECT": "Giờ Ecuador", "HECU": "Giờ Mùa Hè Cuba", "CST": "Giờ chuẩn miền trung", "WAT": "Giờ Chuẩn Tây Phi", "HKST": "Giờ Mùa Hè Hồng Kông", "BT": "Giờ Bhutan", "CLT": "Giờ Chuẩn Chile", "EST": "Giờ chuẩn miền đông", "AKDT": "Giờ Mùa Hè Alaska", "NZST": "Giờ Chuẩn New Zealand", "TMST": "Giờ Mùa Hè Turkmenistan", "HNNOMX": "Giờ Chuẩn Tây Bắc Mexico", "JST": "Giờ Chuẩn Nhật Bản", "ADT": "Giờ Mùa hè Đại Tây Dương", "ACST": "Giờ Chuẩn Miền Trung Nước Úc", "HNPMX": "Giờ Chuẩn Thái Bình Dương Mexico", "HEPM": "Giờ Mùa Hè Saint Pierre và Miquelon", "ACWDT": "Giờ Mùa Hè Miền Trung Tây Nước Úc", "MESZ": "Giờ Mùa Hè Trung Âu", "AEST": "Giờ Chuẩn Miền Đông Nước Úc", "HNEG": "Giờ Chuẩn Miền Đông Greenland", "COST": "Giờ Mùa Hè Colombia", "SRT": "Giờ Suriname", "HAST": "Giờ Chuẩn Hawaii-Aleutian", "COT": "Giờ Chuẩn Colombia", "HAT": "Giờ Mùa Hè Newfoundland", "HNT": "Giờ Chuẩn Newfoundland", "HNPM": "Giờ Chuẩn St. Pierre và Miquelon", "CHADT": "Giờ Mùa Hè Chatham", "UYST": "Giờ Mùa Hè Uruguay", "LHST": "Giờ Chuẩn Lord Howe", "ARST": "Giờ Mùa Hè Argentina", "AST": "Giờ Chuẩn Đại Tây Dương", "ACDT": "Giờ Mùa Hè Miền Trung Nước Úc", "MST": "Giờ Chuẩn Ma Cao", "MYT": "Giờ Malaysia", "WITA": "Giờ Miền Trung Indonesia", "CHAST": "Giờ Chuẩn Chatham"},
78 // Locale returns the current translators string locale
79 func (vi *vi) Locale() string {
83 // PluralsCardinal returns the list of cardinal plural rules associated with 'vi'
84 func (vi *vi) PluralsCardinal() []locales.PluralRule {
85 return vi.pluralsCardinal
88 // PluralsOrdinal returns the list of ordinal plural rules associated with 'vi'
89 func (vi *vi) PluralsOrdinal() []locales.PluralRule {
90 return vi.pluralsOrdinal
93 // PluralsRange returns the list of range plural rules associated with 'vi'
94 func (vi *vi) PluralsRange() []locales.PluralRule {
95 return vi.pluralsRange
98 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'vi'
99 func (vi *vi) 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 'vi'
104 func (vi *vi) 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 'vi'
116 func (vi *vi) 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 (vi *vi) MonthAbbreviated(month time.Month) string {
122 return vi.monthsAbbreviated[month]
125 // MonthsAbbreviated returns the locales abbreviated months
126 func (vi *vi) MonthsAbbreviated() []string {
127 return vi.monthsAbbreviated[1:]
130 // MonthNarrow returns the locales narrow month given the 'month' provided
131 func (vi *vi) MonthNarrow(month time.Month) string {
132 return vi.monthsNarrow[month]
135 // MonthsNarrow returns the locales narrow months
136 func (vi *vi) MonthsNarrow() []string {
137 return vi.monthsNarrow[1:]
140 // MonthWide returns the locales wide month given the 'month' provided
141 func (vi *vi) MonthWide(month time.Month) string {
142 return vi.monthsWide[month]
145 // MonthsWide returns the locales wide months
146 func (vi *vi) MonthsWide() []string {
147 return vi.monthsWide[1:]
150 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
151 func (vi *vi) WeekdayAbbreviated(weekday time.Weekday) string {
152 return vi.daysAbbreviated[weekday]
155 // WeekdaysAbbreviated returns the locales abbreviated weekdays
156 func (vi *vi) WeekdaysAbbreviated() []string {
157 return vi.daysAbbreviated
160 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
161 func (vi *vi) WeekdayNarrow(weekday time.Weekday) string {
162 return vi.daysNarrow[weekday]
165 // WeekdaysNarrow returns the locales narrow weekdays
166 func (vi *vi) WeekdaysNarrow() []string {
170 // WeekdayShort returns the locales short weekday given the 'weekday' provided
171 func (vi *vi) WeekdayShort(weekday time.Weekday) string {
172 return vi.daysShort[weekday]
175 // WeekdaysShort returns the locales short weekdays
176 func (vi *vi) WeekdaysShort() []string {
180 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
181 func (vi *vi) WeekdayWide(weekday time.Weekday) string {
182 return vi.daysWide[weekday]
185 // WeekdaysWide returns the locales wide weekdays
186 func (vi *vi) WeekdaysWide() []string {
190 // Decimal returns the decimal point of number
191 func (vi *vi) Decimal() string {
195 // Group returns the group of number
196 func (vi *vi) Group() string {
200 // Group returns the minus sign of number
201 func (vi *vi) Minus() string {
205 // FmtNumber returns 'num' with digits/precision of 'v' for 'vi' and handles both Whole and Real numbers based on 'v'
206 func (vi *vi) 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, vi.decimal[0])
224 b = append(b, vi.group[0])
235 b = append(b, vi.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 'vi' 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 (vi *vi) 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, vi.decimal[0])
264 b = append(b, vi.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, vi.percent...)
277 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'vi'
278 func (vi *vi) FmtCurrency(num float64, v uint64, currency currency.Type) string {
280 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
281 symbol := vi.currencies[currency]
282 l := len(s) + len(symbol) + 4 + 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, vi.decimal[0])
297 b = append(b, vi.group[0])
308 b = append(b, vi.minus[0])
312 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
313 b[i], b[j] = b[j], b[i]
319 b = append(b, vi.decimal...)
322 for i := 0; i < 2-int(v); i++ {
327 b = append(b, vi.currencyPositiveSuffix...)
329 b = append(b, symbol...)
334 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'vi'
335 // in accounting notation.
336 func (vi *vi) FmtAccounting(num float64, v uint64, currency currency.Type) string {
338 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
339 symbol := vi.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, vi.decimal[0])
355 b = append(b, vi.group[0])
367 b = append(b, vi.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, vi.decimal...)
382 for i := 0; i < 2-int(v); i++ {
388 b = append(b, vi.currencyNegativeSuffix...)
389 b = append(b, symbol...)
392 b = append(b, vi.currencyPositiveSuffix...)
393 b = append(b, symbol...)
399 // FmtDateShort returns the short date representation of 't' for 'vi'
400 func (vi *vi) FmtDateShort(t time.Time) string {
402 b := make([]byte, 0, 32)
408 b = strconv.AppendInt(b, int64(t.Day()), 10)
409 b = append(b, []byte{0x2f}...)
415 b = strconv.AppendInt(b, int64(t.Month()), 10)
417 b = append(b, []byte{0x2f}...)
420 b = strconv.AppendInt(b, int64(t.Year()), 10)
422 b = strconv.AppendInt(b, int64(-t.Year()), 10)
428 // FmtDateMedium returns the medium date representation of 't' for 'vi'
429 func (vi *vi) FmtDateMedium(t time.Time) string {
431 b := make([]byte, 0, 32)
433 b = strconv.AppendInt(b, int64(t.Day()), 10)
434 b = append(b, []byte{0x20}...)
435 b = append(b, vi.monthsAbbreviated[t.Month()]...)
436 b = append(b, []byte{0x2c, 0x20}...)
439 b = strconv.AppendInt(b, int64(t.Year()), 10)
441 b = strconv.AppendInt(b, int64(-t.Year()), 10)
447 // FmtDateLong returns the long date representation of 't' for 'vi'
448 func (vi *vi) FmtDateLong(t time.Time) string {
450 b := make([]byte, 0, 32)
452 b = strconv.AppendInt(b, int64(t.Day()), 10)
453 b = append(b, []byte{0x20}...)
454 b = append(b, vi.monthsWide[t.Month()]...)
455 b = append(b, []byte{0x2c, 0x20}...)
458 b = strconv.AppendInt(b, int64(t.Year()), 10)
460 b = strconv.AppendInt(b, int64(-t.Year()), 10)
466 // FmtDateFull returns the full date representation of 't' for 'vi'
467 func (vi *vi) FmtDateFull(t time.Time) string {
469 b := make([]byte, 0, 32)
471 b = append(b, vi.daysWide[t.Weekday()]...)
472 b = append(b, []byte{0x2c, 0x20}...)
473 b = strconv.AppendInt(b, int64(t.Day()), 10)
474 b = append(b, []byte{0x20}...)
475 b = append(b, vi.monthsWide[t.Month()]...)
476 b = append(b, []byte{0x2c, 0x20}...)
479 b = strconv.AppendInt(b, int64(t.Year()), 10)
481 b = strconv.AppendInt(b, int64(-t.Year()), 10)
487 // FmtTimeShort returns the short time representation of 't' for 'vi'
488 func (vi *vi) FmtTimeShort(t time.Time) string {
490 b := make([]byte, 0, 32)
496 b = strconv.AppendInt(b, int64(t.Hour()), 10)
497 b = append(b, vi.timeSeparator...)
503 b = strconv.AppendInt(b, int64(t.Minute()), 10)
508 // FmtTimeMedium returns the medium time representation of 't' for 'vi'
509 func (vi *vi) FmtTimeMedium(t time.Time) string {
511 b := make([]byte, 0, 32)
517 b = strconv.AppendInt(b, int64(t.Hour()), 10)
518 b = append(b, vi.timeSeparator...)
524 b = strconv.AppendInt(b, int64(t.Minute()), 10)
525 b = append(b, vi.timeSeparator...)
531 b = strconv.AppendInt(b, int64(t.Second()), 10)
536 // FmtTimeLong returns the long time representation of 't' for 'vi'
537 func (vi *vi) FmtTimeLong(t time.Time) string {
539 b := make([]byte, 0, 32)
545 b = strconv.AppendInt(b, int64(t.Hour()), 10)
546 b = append(b, vi.timeSeparator...)
552 b = strconv.AppendInt(b, int64(t.Minute()), 10)
553 b = append(b, vi.timeSeparator...)
559 b = strconv.AppendInt(b, int64(t.Second()), 10)
560 b = append(b, []byte{0x20}...)
568 // FmtTimeFull returns the full time representation of 't' for 'vi'
569 func (vi *vi) FmtTimeFull(t time.Time) string {
571 b := make([]byte, 0, 32)
577 b = strconv.AppendInt(b, int64(t.Hour()), 10)
578 b = append(b, vi.timeSeparator...)
584 b = strconv.AppendInt(b, int64(t.Minute()), 10)
585 b = append(b, vi.timeSeparator...)
591 b = strconv.AppendInt(b, int64(t.Second()), 10)
592 b = append(b, []byte{0x20}...)
596 if btz, ok := vi.timezones[tz]; ok {
597 b = append(b, btz...)