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 'lv' locale
45 func New() locales.Translator {
48 pluralsCardinal: []locales.PluralRule{1, 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", "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", "¥", "KES", "KGS", "KHR", "KMF", "KPW", "KRH", "KRO", "₩", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LTL", "LTT", "LUC", "LUF", "LUL", "Ls", "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", "$", "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{"", "janv.", "febr.", "marts", "apr.", "maijs", "jūn.", "jūl.", "aug.", "sept.", "okt.", "nov.", "dec."},
62 monthsNarrow: []string{"", "J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"},
63 monthsWide: []string{"", "janvāris", "februāris", "marts", "aprīlis", "maijs", "jūnijs", "jūlijs", "augusts", "septembris", "oktobris", "novembris", "decembris"},
64 daysAbbreviated: []string{"svētd.", "pirmd.", "otrd.", "trešd.", "ceturtd.", "piektd.", "sestd."},
65 daysNarrow: []string{"S", "P", "O", "T", "C", "P", "S"},
66 daysShort: []string{"Sv", "Pr", "Ot", "Tr", "Ce", "Pk", "Se"},
67 daysWide: []string{"svētdiena", "pirmdiena", "otrdiena", "trešdiena", "ceturtdiena", "piektdiena", "sestdiena"},
68 periodsAbbreviated: []string{"priekšp.", "pēcp."},
69 periodsNarrow: []string{"priekšp.", "pēcp."},
70 periodsWide: []string{"priekšpusdienā", "pēcpusdienā"},
71 erasAbbreviated: []string{"p.m.ē.", "m.ē."},
72 erasNarrow: []string{"p.m.ē.", "m.ē."},
73 erasWide: []string{"pirms mūsu ēras", "mūsu ērā"},
74 timezones: map[string]string{"CAT": "Centrālāfrikas laiks", "PDT": "Klusā okeāna vasaras laiks", "SRT": "Surinamas laiks", "MDT": "MDT", "HEOG": "Rietumgrenlandes vasaras laiks", "HKT": "Honkongas ziemas laiks", "GYT": "Gajānas laiks", "CHAST": "Četemas ziemas laiks", "BOT": "Bolīvijas laiks", "WIT": "Austrumindonēzijas laiks", "ACWST": "Austrālijas centrālais rietumu ziemas laiks", "ACWDT": "Austrālijas centrālais rietumu vasaras laiks", "HENOMX": "Ziemeļrietumu Meksikas vasaras laiks", "EDT": "Austrumu vasaras laiks", "ChST": "Čamorra ziemas laiks", "HNEG": "Austrumgrenlandes ziemas laiks", "HEEG": "Austrumgrenlandes vasaras laiks", "CHADT": "Četemas vasaras laiks", "NZST": "Jaunzēlandes ziemas laiks", "WAT": "Rietumāfrikas ziemas laiks", "CLT": "Čīles ziemas laiks", "GMT": "Griničas laiks", "SAST": "Dienvidāfrikas ziemas laiks", "ECT": "Ekvadoras laiks", "AWDT": "Austrālijas rietumu vasaras laiks", "MYT": "Malaizijas laiks", "WEZ": "Rietumeiropas ziemas laiks", "MST": "MST", "MEZ": "Centrāleiropas ziemas laiks", "ART": "Argentīnas ziemas laiks", "COT": "Kolumbijas ziemas laiks", "HNPM": "Senpjēras un Mikelonas ziemas laiks", "AKDT": "Aļaskas vasaras laiks", "SGT": "Singapūras laiks", "NZDT": "Jaunzēlandes vasaras laiks", "MESZ": "Centrāleiropas vasaras laiks", "WITA": "Centrālindonēzijas laiks", "OESZ": "Austrumeiropas vasaras laiks", "COST": "Kolumbijas vasaras laiks", "HNT": "Ņūfaundlendas ziemas laiks", "HNOG": "Rietumgrenlandes ziemas laiks", "∅∅∅": "Amazones vasaras laiks", "HNPMX": "Meksikas Klusā okeāna piekrastes ziemas laiks", "ACST": "Austrālijas centrālais ziemas laiks", "EAT": "Austrumāfrikas laiks", "WART": "Rietumargentīnas ziemas laiks", "LHST": "Lorda Hava salas ziemas laiks", "CDT": "Centrālais vasaras laiks", "WARST": "Rietumargentīnas vasaras laiks", "IST": "Indijas ziemas laiks", "AEDT": "Austrālijas austrumu vasaras laiks", "HNCU": "Kubas ziemas laiks", "CST": "Centrālais ziemas laiks", "HECU": "Kubas vasaras laiks", "TMT": "Turkmenistānas ziemas laiks", "JST": "Japānas ziemas laiks", "ARST": "Argentīnas vasaras laiks", "WAST": "Rietumāfrikas vasaras laiks", "HKST": "Honkongas vasaras laiks", "HEPMX": "Meksikas Klusā okeāna piekrastes vasaras laiks", "UYT": "Urugvajas ziemas laiks", "UYST": "Urugvajas vasaras laiks", "HADT": "Havaju–Aleutu vasaras laiks", "OEZ": "Austrumeiropas ziemas laiks", "AST": "Atlantijas ziemas laiks", "WESZ": "Rietumeiropas vasaras laiks", "AWST": "Austrālijas rietumu ziemas laiks", "HEPM": "Senpjēras un Mikelonas vasaras laiks", "BT": "Butānas laiks", "TMST": "Turkmenistānas vasaras laiks", "HAST": "Havaju–Aleutu ziemas laiks", "LHDT": "Lorda Hava salas vasaras laiks", "HAT": "Ņūfaundlendas vasaras laiks", "WIB": "Rietumindonēzijas laiks", "VET": "Venecuēlas laiks", "HNNOMX": "Ziemeļrietumu Meksikas ziemas laiks", "ADT": "Atlantijas vasaras laiks", "EST": "Austrumu ziemas laiks", "PST": "Klusā okeāna ziemas laiks", "AKST": "Aļaskas ziemas laiks", "ACDT": "Austrālijas centrālais vasaras laiks", "JDT": "Japānas vasaras laiks", "AEST": "Austrālijas austrumu ziemas laiks", "CLST": "Čīles vasaras laiks", "GFT": "Franču Gviānas laiks"},
78 // Locale returns the current translators string locale
79 func (lv *lv) Locale() string {
83 // PluralsCardinal returns the list of cardinal plural rules associated with 'lv'
84 func (lv *lv) PluralsCardinal() []locales.PluralRule {
85 return lv.pluralsCardinal
88 // PluralsOrdinal returns the list of ordinal plural rules associated with 'lv'
89 func (lv *lv) PluralsOrdinal() []locales.PluralRule {
90 return lv.pluralsOrdinal
93 // PluralsRange returns the list of range plural rules associated with 'lv'
94 func (lv *lv) PluralsRange() []locales.PluralRule {
95 return lv.pluralsRange
98 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'lv'
99 func (lv *lv) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
103 nMod100 := math.Mod(n, 100)
104 nMod10 := math.Mod(n, 10)
108 if (nMod10 == 0) || (nMod100 >= 11 && nMod100 <= 19) || (v == 2 && fMod100 >= 11 && fMod100 <= 19) {
109 return locales.PluralRuleZero
110 } else if (nMod10 == 1 && nMod100 != 11) || (v == 2 && fMod10 == 1 && fMod100 != 11) || (v != 2 && fMod10 == 1) {
111 return locales.PluralRuleOne
114 return locales.PluralRuleOther
117 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'lv'
118 func (lv *lv) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
119 return locales.PluralRuleOther
122 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'lv'
123 func (lv *lv) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
125 start := lv.CardinalPluralRule(num1, v1)
126 end := lv.CardinalPluralRule(num2, v2)
128 if start == locales.PluralRuleZero && end == locales.PluralRuleZero {
129 return locales.PluralRuleOther
130 } else if start == locales.PluralRuleZero && end == locales.PluralRuleOne {
131 return locales.PluralRuleOne
132 } else if start == locales.PluralRuleZero && end == locales.PluralRuleOther {
133 return locales.PluralRuleOther
134 } else if start == locales.PluralRuleOne && end == locales.PluralRuleZero {
135 return locales.PluralRuleOther
136 } else if start == locales.PluralRuleOne && end == locales.PluralRuleOne {
137 return locales.PluralRuleOne
138 } else if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
139 return locales.PluralRuleOther
140 } else if start == locales.PluralRuleOther && end == locales.PluralRuleZero {
141 return locales.PluralRuleOther
142 } else if start == locales.PluralRuleOther && end == locales.PluralRuleOne {
143 return locales.PluralRuleOne
146 return locales.PluralRuleOther
150 // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
151 func (lv *lv) MonthAbbreviated(month time.Month) string {
152 return lv.monthsAbbreviated[month]
155 // MonthsAbbreviated returns the locales abbreviated months
156 func (lv *lv) MonthsAbbreviated() []string {
157 return lv.monthsAbbreviated[1:]
160 // MonthNarrow returns the locales narrow month given the 'month' provided
161 func (lv *lv) MonthNarrow(month time.Month) string {
162 return lv.monthsNarrow[month]
165 // MonthsNarrow returns the locales narrow months
166 func (lv *lv) MonthsNarrow() []string {
167 return lv.monthsNarrow[1:]
170 // MonthWide returns the locales wide month given the 'month' provided
171 func (lv *lv) MonthWide(month time.Month) string {
172 return lv.monthsWide[month]
175 // MonthsWide returns the locales wide months
176 func (lv *lv) MonthsWide() []string {
177 return lv.monthsWide[1:]
180 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
181 func (lv *lv) WeekdayAbbreviated(weekday time.Weekday) string {
182 return lv.daysAbbreviated[weekday]
185 // WeekdaysAbbreviated returns the locales abbreviated weekdays
186 func (lv *lv) WeekdaysAbbreviated() []string {
187 return lv.daysAbbreviated
190 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
191 func (lv *lv) WeekdayNarrow(weekday time.Weekday) string {
192 return lv.daysNarrow[weekday]
195 // WeekdaysNarrow returns the locales narrow weekdays
196 func (lv *lv) WeekdaysNarrow() []string {
200 // WeekdayShort returns the locales short weekday given the 'weekday' provided
201 func (lv *lv) WeekdayShort(weekday time.Weekday) string {
202 return lv.daysShort[weekday]
205 // WeekdaysShort returns the locales short weekdays
206 func (lv *lv) WeekdaysShort() []string {
210 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
211 func (lv *lv) WeekdayWide(weekday time.Weekday) string {
212 return lv.daysWide[weekday]
215 // WeekdaysWide returns the locales wide weekdays
216 func (lv *lv) WeekdaysWide() []string {
220 // Decimal returns the decimal point of number
221 func (lv *lv) Decimal() string {
225 // Group returns the group of number
226 func (lv *lv) Group() string {
230 // Group returns the minus sign of number
231 func (lv *lv) Minus() string {
235 // FmtNumber returns 'num' with digits/precision of 'v' for 'lv' and handles both Whole and Real numbers based on 'v'
236 func (lv *lv) FmtNumber(num float64, v uint64) string {
238 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
239 l := len(s) + 2 + 2*len(s[:len(s)-int(v)-1])/3
242 b := make([]byte, 0, l)
244 for i := len(s) - 1; i >= 0; i-- {
247 b = append(b, lv.decimal[0])
254 for j := len(lv.group) - 1; j >= 0; j-- {
255 b = append(b, lv.group[j])
267 b = append(b, lv.minus[0])
271 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
272 b[i], b[j] = b[j], b[i]
278 // FmtPercent returns 'num' with digits/precision of 'v' for 'lv' and handles both Whole and Real numbers based on 'v'
279 // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
280 func (lv *lv) FmtPercent(num float64, v uint64) string {
281 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
283 b := make([]byte, 0, l)
285 for i := len(s) - 1; i >= 0; i-- {
288 b = append(b, lv.decimal[0])
296 b = append(b, lv.minus[0])
300 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
301 b[i], b[j] = b[j], b[i]
304 b = append(b, lv.percent...)
309 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'lv'
310 func (lv *lv) FmtCurrency(num float64, v uint64, currency currency.Type) string {
312 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
313 symbol := lv.currencies[currency]
314 l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
317 b := make([]byte, 0, l)
319 for i := len(s) - 1; i >= 0; i-- {
322 b = append(b, lv.decimal[0])
329 for j := len(lv.group) - 1; j >= 0; j-- {
330 b = append(b, lv.group[j])
342 b = append(b, lv.minus[0])
346 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
347 b[i], b[j] = b[j], b[i]
353 b = append(b, lv.decimal...)
356 for i := 0; i < 2-int(v); i++ {
361 b = append(b, lv.currencyPositiveSuffix...)
363 b = append(b, symbol...)
368 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'lv'
369 // in accounting notation.
370 func (lv *lv) FmtAccounting(num float64, v uint64, currency currency.Type) string {
372 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
373 symbol := lv.currencies[currency]
374 l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
377 b := make([]byte, 0, l)
379 for i := len(s) - 1; i >= 0; i-- {
382 b = append(b, lv.decimal[0])
389 for j := len(lv.group) - 1; j >= 0; j-- {
390 b = append(b, lv.group[j])
403 b = append(b, lv.minus[0])
408 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
409 b[i], b[j] = b[j], b[i]
415 b = append(b, lv.decimal...)
418 for i := 0; i < 2-int(v); i++ {
424 b = append(b, lv.currencyNegativeSuffix...)
425 b = append(b, symbol...)
428 b = append(b, lv.currencyPositiveSuffix...)
429 b = append(b, symbol...)
435 // FmtDateShort returns the short date representation of 't' for 'lv'
436 func (lv *lv) FmtDateShort(t time.Time) string {
438 b := make([]byte, 0, 32)
444 b = strconv.AppendInt(b, int64(t.Day()), 10)
445 b = append(b, []byte{0x2e}...)
451 b = strconv.AppendInt(b, int64(t.Month()), 10)
453 b = append(b, []byte{0x2e}...)
456 b = append(b, strconv.Itoa(t.Year())[2:]...)
458 b = append(b, strconv.Itoa(t.Year())[1:]...)
464 // FmtDateMedium returns the medium date representation of 't' for 'lv'
465 func (lv *lv) FmtDateMedium(t time.Time) string {
467 b := make([]byte, 0, 32)
470 b = strconv.AppendInt(b, int64(t.Year()), 10)
472 b = strconv.AppendInt(b, int64(-t.Year()), 10)
475 b = append(b, []byte{0x2e, 0x20, 0x67, 0x61, 0x64, 0x61}...)
476 b = append(b, []byte{0x20}...)
477 b = strconv.AppendInt(b, int64(t.Day()), 10)
478 b = append(b, []byte{0x2e, 0x20}...)
479 b = append(b, lv.monthsAbbreviated[t.Month()]...)
484 // FmtDateLong returns the long date representation of 't' for 'lv'
485 func (lv *lv) FmtDateLong(t time.Time) string {
487 b := make([]byte, 0, 32)
490 b = strconv.AppendInt(b, int64(t.Year()), 10)
492 b = strconv.AppendInt(b, int64(-t.Year()), 10)
495 b = append(b, []byte{0x2e, 0x20, 0x67, 0x61, 0x64, 0x61}...)
496 b = append(b, []byte{0x20}...)
497 b = strconv.AppendInt(b, int64(t.Day()), 10)
498 b = append(b, []byte{0x2e, 0x20}...)
499 b = append(b, lv.monthsWide[t.Month()]...)
504 // FmtDateFull returns the full date representation of 't' for 'lv'
505 func (lv *lv) FmtDateFull(t time.Time) string {
507 b := make([]byte, 0, 32)
509 b = append(b, lv.daysWide[t.Weekday()]...)
510 b = append(b, []byte{0x2c, 0x20}...)
513 b = strconv.AppendInt(b, int64(t.Year()), 10)
515 b = strconv.AppendInt(b, int64(-t.Year()), 10)
518 b = append(b, []byte{0x2e, 0x20, 0x67, 0x61, 0x64, 0x61}...)
519 b = append(b, []byte{0x20}...)
520 b = strconv.AppendInt(b, int64(t.Day()), 10)
521 b = append(b, []byte{0x2e, 0x20}...)
522 b = append(b, lv.monthsWide[t.Month()]...)
527 // FmtTimeShort returns the short time representation of 't' for 'lv'
528 func (lv *lv) FmtTimeShort(t time.Time) string {
530 b := make([]byte, 0, 32)
536 b = strconv.AppendInt(b, int64(t.Hour()), 10)
537 b = append(b, lv.timeSeparator...)
543 b = strconv.AppendInt(b, int64(t.Minute()), 10)
548 // FmtTimeMedium returns the medium time representation of 't' for 'lv'
549 func (lv *lv) FmtTimeMedium(t time.Time) string {
551 b := make([]byte, 0, 32)
557 b = strconv.AppendInt(b, int64(t.Hour()), 10)
558 b = append(b, lv.timeSeparator...)
564 b = strconv.AppendInt(b, int64(t.Minute()), 10)
565 b = append(b, lv.timeSeparator...)
571 b = strconv.AppendInt(b, int64(t.Second()), 10)
576 // FmtTimeLong returns the long time representation of 't' for 'lv'
577 func (lv *lv) FmtTimeLong(t time.Time) string {
579 b := make([]byte, 0, 32)
585 b = strconv.AppendInt(b, int64(t.Hour()), 10)
586 b = append(b, lv.timeSeparator...)
592 b = strconv.AppendInt(b, int64(t.Minute()), 10)
593 b = append(b, lv.timeSeparator...)
599 b = strconv.AppendInt(b, int64(t.Second()), 10)
600 b = append(b, []byte{0x20}...)
608 // FmtTimeFull returns the full time representation of 't' for 'lv'
609 func (lv *lv) FmtTimeFull(t time.Time) string {
611 b := make([]byte, 0, 32)
617 b = strconv.AppendInt(b, int64(t.Hour()), 10)
618 b = append(b, lv.timeSeparator...)
624 b = strconv.AppendInt(b, int64(t.Minute()), 10)
625 b = append(b, lv.timeSeparator...)
631 b = strconv.AppendInt(b, int64(t.Second()), 10)
632 b = append(b, []byte{0x20}...)
636 if btz, ok := lv.timezones[tz]; ok {
637 b = append(b, btz...)