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
25 currencies []string // idx = enum of currency code
26 currencyPositiveSuffix string
27 currencyNegativeSuffix string
28 monthsAbbreviated []string
31 daysAbbreviated []string
35 periodsAbbreviated []string
36 periodsNarrow []string
39 erasAbbreviated []string
42 timezones map[string]string
45 // New returns a new instance of translator for the 'fi' locale
46 func New() locales.Translator {
49 pluralsCardinal: []locales.PluralRule{2, 6},
50 pluralsOrdinal: []locales.PluralRule{6},
51 pluralsRange: []locales.PluralRule{6},
59 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", "€", "mk", "FJD", "FKP", "FRF", "£", "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", "¥", "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", "MZN", "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", "$", "USN", "USS", "UYI", "UYP", "UYU", "UZS", "VEB", "VEF", "VND", "VNN", "VUV", "WST", "FCFA", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "XCD", "XDR", "XEU", "XFO", "XFU", "CFA", "XPD", "XPF", "XPT", "XRE", "XSU", "XTS", "XUA", "XXX", "YDD", "YER", "YUD", "YUM", "YUN", "YUR", "ZAL", "ZAR", "ZMK", "ZMW", "ZRN", "ZRZ", "ZWD", "ZWL", "ZWR"},
61 currencyPositiveSuffix: " ",
62 currencyNegativeSuffix: " ",
63 monthsAbbreviated: []string{"", "tammik.", "helmik.", "maalisk.", "huhtik.", "toukok.", "kesäk.", "heinäk.", "elok.", "syysk.", "lokak.", "marrask.", "jouluk."},
64 monthsNarrow: []string{"", "T", "H", "M", "H", "T", "K", "H", "E", "S", "L", "M", "J"},
65 monthsWide: []string{"", "tammikuuta", "helmikuuta", "maaliskuuta", "huhtikuuta", "toukokuuta", "kesäkuuta", "heinäkuuta", "elokuuta", "syyskuuta", "lokakuuta", "marraskuuta", "joulukuuta"},
66 daysAbbreviated: []string{"su", "ma", "ti", "ke", "to", "pe", "la"},
67 daysNarrow: []string{"S", "M", "T", "K", "T", "P", "L"},
68 daysShort: []string{"su", "ma", "ti", "ke", "to", "pe", "la"},
69 daysWide: []string{"sunnuntaina", "maanantaina", "tiistaina", "keskiviikkona", "torstaina", "perjantaina", "lauantaina"},
70 periodsAbbreviated: []string{"ap.", "ip."},
71 periodsNarrow: []string{"ap.", "ip."},
72 periodsWide: []string{"ap.", "ip."},
73 erasAbbreviated: []string{"eKr.", "jKr."},
74 erasNarrow: []string{"eKr", "jKr"},
75 erasWide: []string{"ennen Kristuksen syntymää", "jälkeen Kristuksen syntymän"},
76 timezones: map[string]string{"HEEG": "Itä-Grönlannin kesäaika", "AKDT": "Alaskan kesäaika", "ChST": "Tšamorron aika", "AWST": "Länsi-Australian normaaliaika", "ACWDT": "Läntisen Keski-Australian kesäaika", "IST": "Intian aika", "COT": "Kolumbian normaaliaika", "∅∅∅": "Amazonin kesäaika", "AEST": "Itä-Australian normaaliaika", "HNOG": "Länsi-Grönlannin normaaliaika", "TMST": "Turkmenistanin kesäaika", "HKST": "Hongkongin kesäaika", "EDT": "Yhdysvaltain itäinen kesäaika", "WEZ": "Länsi-Euroopan normaaliaika", "ACWST": "Läntisen Keski-Australian normaaliaika", "UYT": "Uruguayn normaaliaika", "TMT": "Turkmenistanin normaaliaika", "HEPMX": "Meksikon Tyynenmeren kesäaika", "SRT": "Surinamen aika", "WIT": "Itä-Indonesian aika", "LHDT": "Lord Howen kesäaika", "WART": "Länsi-Argentiinan normaaliaika", "HAT": "Newfoundlandin kesäaika", "EST": "Yhdysvaltain itäinen normaaliaika", "SGT": "Singaporen aika", "PST": "Yhdysvaltain Tyynenmeren normaaliaika", "HNCU": "Kuuban normaaliaika", "HEOG": "Länsi-Grönlannin kesäaika", "MST": "Macaon normaaliaika", "OESZ": "Itä-Euroopan kesäaika", "HNT": "Newfoundlandin normaaliaika", "CLT": "Chilen normaaliaika", "AKST": "Alaskan normaaliaika", "ACDT": "Keski-Australian kesäaika", "WESZ": "Länsi-Euroopan kesäaika", "HECU": "Kuuban kesäaika", "GFT": "Ranskan Guayanan aika", "WARST": "Länsi-Argentiinan kesäaika", "ART": "Argentiinan normaaliaika", "LHST": "Lord Howen normaaliaika", "VET": "Venezuelan aika", "EAT": "Itä-Afrikan aika", "SAST": "Etelä-Afrikan aika", "GYT": "Guyanan aika", "ACST": "Keski-Australian normaaliaika", "CST": "Yhdysvaltain keskinen normaaliaika", "HADT": "Havaijin-Aleuttien kesäaika", "HNNOMX": "Luoteis-Meksikon normaaliaika", "HENOMX": "Luoteis-Meksikon kesäaika", "ARST": "Argentiinan kesäaika", "CLST": "Chilen kesäaika", "CAT": "Keski-Afrikan aika", "GMT": "Greenwichin normaaliaika", "CHAST": "Chathamin normaaliaika", "CHADT": "Chathamin kesäaika", "BT": "Bhutanin aika", "HNPM": "Saint-Pierren ja Miquelonin normaaliaika", "MYT": "Malesian aika", "NZST": "Uuden-Seelannin normaaliaika", "ADT": "Kanadan Atlantin kesäaika", "WAT": "Länsi-Afrikan normaaliaika", "COST": "Kolumbian kesäaika", "WIB": "Länsi-Indonesian aika", "CDT": "Yhdysvaltain keskinen kesäaika", "UYST": "Uruguayn kesäaika", "WITA": "Keski-Indonesian aika", "PDT": "Yhdysvaltain Tyynenmeren kesäaika", "AWDT": "Länsi-Australian kesäaika", "MESZ": "Keski-Euroopan kesäaika", "JDT": "Japanin kesäaika", "AEDT": "Itä-Australian kesäaika", "ECT": "Ecuadorin aika", "HAST": "Havaijin-Aleuttien normaaliaika", "NZDT": "Uuden-Seelannin kesäaika", "WAST": "Länsi-Afrikan kesäaika", "MEZ": "Keski-Euroopan normaaliaika", "JST": "Japanin normaaliaika", "AST": "Kanadan Atlantin normaaliaika", "HKT": "Hongkongin normaaliaika", "HNPMX": "Meksikon Tyynenmeren normaaliaika", "MDT": "Macaon kesäaika", "OEZ": "Itä-Euroopan normaaliaika", "HNEG": "Itä-Grönlannin normaaliaika", "HEPM": "Saint-Pierren ja Miquelonin kesäaika", "BOT": "Bolivian aika"},
80 // Locale returns the current translators string locale
81 func (fi *fi) Locale() string {
85 // PluralsCardinal returns the list of cardinal plural rules associated with 'fi'
86 func (fi *fi) PluralsCardinal() []locales.PluralRule {
87 return fi.pluralsCardinal
90 // PluralsOrdinal returns the list of ordinal plural rules associated with 'fi'
91 func (fi *fi) PluralsOrdinal() []locales.PluralRule {
92 return fi.pluralsOrdinal
95 // PluralsRange returns the list of range plural rules associated with 'fi'
96 func (fi *fi) PluralsRange() []locales.PluralRule {
97 return fi.pluralsRange
100 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'fi'
101 func (fi *fi) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
106 if i == 1 && v == 0 {
107 return locales.PluralRuleOne
110 return locales.PluralRuleOther
113 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'fi'
114 func (fi *fi) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
115 return locales.PluralRuleOther
118 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'fi'
119 func (fi *fi) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
120 return locales.PluralRuleOther
123 // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
124 func (fi *fi) MonthAbbreviated(month time.Month) string {
125 return fi.monthsAbbreviated[month]
128 // MonthsAbbreviated returns the locales abbreviated months
129 func (fi *fi) MonthsAbbreviated() []string {
130 return fi.monthsAbbreviated[1:]
133 // MonthNarrow returns the locales narrow month given the 'month' provided
134 func (fi *fi) MonthNarrow(month time.Month) string {
135 return fi.monthsNarrow[month]
138 // MonthsNarrow returns the locales narrow months
139 func (fi *fi) MonthsNarrow() []string {
140 return fi.monthsNarrow[1:]
143 // MonthWide returns the locales wide month given the 'month' provided
144 func (fi *fi) MonthWide(month time.Month) string {
145 return fi.monthsWide[month]
148 // MonthsWide returns the locales wide months
149 func (fi *fi) MonthsWide() []string {
150 return fi.monthsWide[1:]
153 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
154 func (fi *fi) WeekdayAbbreviated(weekday time.Weekday) string {
155 return fi.daysAbbreviated[weekday]
158 // WeekdaysAbbreviated returns the locales abbreviated weekdays
159 func (fi *fi) WeekdaysAbbreviated() []string {
160 return fi.daysAbbreviated
163 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
164 func (fi *fi) WeekdayNarrow(weekday time.Weekday) string {
165 return fi.daysNarrow[weekday]
168 // WeekdaysNarrow returns the locales narrow weekdays
169 func (fi *fi) WeekdaysNarrow() []string {
173 // WeekdayShort returns the locales short weekday given the 'weekday' provided
174 func (fi *fi) WeekdayShort(weekday time.Weekday) string {
175 return fi.daysShort[weekday]
178 // WeekdaysShort returns the locales short weekdays
179 func (fi *fi) WeekdaysShort() []string {
183 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
184 func (fi *fi) WeekdayWide(weekday time.Weekday) string {
185 return fi.daysWide[weekday]
188 // WeekdaysWide returns the locales wide weekdays
189 func (fi *fi) WeekdaysWide() []string {
193 // Decimal returns the decimal point of number
194 func (fi *fi) Decimal() string {
198 // Group returns the group of number
199 func (fi *fi) Group() string {
203 // Group returns the minus sign of number
204 func (fi *fi) Minus() string {
208 // FmtNumber returns 'num' with digits/precision of 'v' for 'fi' and handles both Whole and Real numbers based on 'v'
209 func (fi *fi) FmtNumber(num float64, v uint64) string {
211 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
212 l := len(s) + 4 + 2*len(s[:len(s)-int(v)-1])/3
215 b := make([]byte, 0, l)
217 for i := len(s) - 1; i >= 0; i-- {
220 b = append(b, fi.decimal[0])
227 for j := len(fi.group) - 1; j >= 0; j-- {
228 b = append(b, fi.group[j])
240 for j := len(fi.minus) - 1; j >= 0; j-- {
241 b = append(b, fi.minus[j])
246 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
247 b[i], b[j] = b[j], b[i]
253 // FmtPercent returns 'num' with digits/precision of 'v' for 'fi' and handles both Whole and Real numbers based on 'v'
254 // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
255 func (fi *fi) FmtPercent(num float64, v uint64) string {
256 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
258 b := make([]byte, 0, l)
260 for i := len(s) - 1; i >= 0; i-- {
263 b = append(b, fi.decimal[0])
271 for j := len(fi.minus) - 1; j >= 0; j-- {
272 b = append(b, fi.minus[j])
277 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
278 b[i], b[j] = b[j], b[i]
281 b = append(b, fi.percentSuffix...)
283 b = append(b, fi.percent...)
288 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'fi'
289 func (fi *fi) FmtCurrency(num float64, v uint64, currency currency.Type) string {
291 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
292 symbol := fi.currencies[currency]
293 l := len(s) + len(symbol) + 6 + 2*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, fi.decimal[0])
308 for j := len(fi.group) - 1; j >= 0; j-- {
309 b = append(b, fi.group[j])
321 for j := len(fi.minus) - 1; j >= 0; j-- {
322 b = append(b, fi.minus[j])
327 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
328 b[i], b[j] = b[j], b[i]
334 b = append(b, fi.decimal...)
337 for i := 0; i < 2-int(v); i++ {
342 b = append(b, fi.currencyPositiveSuffix...)
344 b = append(b, symbol...)
349 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'fi'
350 // in accounting notation.
351 func (fi *fi) FmtAccounting(num float64, v uint64, currency currency.Type) string {
353 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
354 symbol := fi.currencies[currency]
355 l := len(s) + len(symbol) + 6 + 2*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, fi.decimal[0])
370 for j := len(fi.group) - 1; j >= 0; j-- {
371 b = append(b, fi.group[j])
384 for j := len(fi.minus) - 1; j >= 0; j-- {
385 b = append(b, fi.minus[j])
391 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
392 b[i], b[j] = b[j], b[i]
398 b = append(b, fi.decimal...)
401 for i := 0; i < 2-int(v); i++ {
407 b = append(b, fi.currencyNegativeSuffix...)
408 b = append(b, symbol...)
411 b = append(b, fi.currencyPositiveSuffix...)
412 b = append(b, symbol...)
418 // FmtDateShort returns the short date representation of 't' for 'fi'
419 func (fi *fi) FmtDateShort(t time.Time) string {
421 b := make([]byte, 0, 32)
423 b = strconv.AppendInt(b, int64(t.Day()), 10)
424 b = append(b, []byte{0x2e}...)
425 b = strconv.AppendInt(b, int64(t.Month()), 10)
426 b = append(b, []byte{0x2e}...)
429 b = strconv.AppendInt(b, int64(t.Year()), 10)
431 b = strconv.AppendInt(b, int64(-t.Year()), 10)
437 // FmtDateMedium returns the medium date representation of 't' for 'fi'
438 func (fi *fi) FmtDateMedium(t time.Time) string {
440 b := make([]byte, 0, 32)
442 b = strconv.AppendInt(b, int64(t.Day()), 10)
443 b = append(b, []byte{0x2e}...)
444 b = strconv.AppendInt(b, int64(t.Month()), 10)
445 b = append(b, []byte{0x2e}...)
448 b = strconv.AppendInt(b, int64(t.Year()), 10)
450 b = strconv.AppendInt(b, int64(-t.Year()), 10)
456 // FmtDateLong returns the long date representation of 't' for 'fi'
457 func (fi *fi) FmtDateLong(t time.Time) string {
459 b := make([]byte, 0, 32)
461 b = strconv.AppendInt(b, int64(t.Day()), 10)
462 b = append(b, []byte{0x2e, 0x20}...)
463 b = append(b, fi.monthsWide[t.Month()]...)
464 b = append(b, []byte{0x20}...)
467 b = strconv.AppendInt(b, int64(t.Year()), 10)
469 b = strconv.AppendInt(b, int64(-t.Year()), 10)
475 // FmtDateFull returns the full date representation of 't' for 'fi'
476 func (fi *fi) FmtDateFull(t time.Time) string {
478 b := make([]byte, 0, 32)
480 b = append(b, []byte{0x63, 0x63, 0x63, 0x63, 0x20}...)
481 b = strconv.AppendInt(b, int64(t.Day()), 10)
482 b = append(b, []byte{0x2e, 0x20}...)
483 b = append(b, fi.monthsWide[t.Month()]...)
484 b = append(b, []byte{0x20}...)
487 b = strconv.AppendInt(b, int64(t.Year()), 10)
489 b = strconv.AppendInt(b, int64(-t.Year()), 10)
495 // FmtTimeShort returns the short time representation of 't' for 'fi'
496 func (fi *fi) FmtTimeShort(t time.Time) string {
498 b := make([]byte, 0, 32)
500 b = strconv.AppendInt(b, int64(t.Hour()), 10)
501 b = append(b, []byte{0x2e}...)
507 b = strconv.AppendInt(b, int64(t.Minute()), 10)
512 // FmtTimeMedium returns the medium time representation of 't' for 'fi'
513 func (fi *fi) FmtTimeMedium(t time.Time) string {
515 b := make([]byte, 0, 32)
517 b = strconv.AppendInt(b, int64(t.Hour()), 10)
518 b = append(b, []byte{0x2e}...)
524 b = strconv.AppendInt(b, int64(t.Minute()), 10)
525 b = append(b, []byte{0x2e}...)
531 b = strconv.AppendInt(b, int64(t.Second()), 10)
536 // FmtTimeLong returns the long time representation of 't' for 'fi'
537 func (fi *fi) FmtTimeLong(t time.Time) string {
539 b := make([]byte, 0, 32)
541 b = strconv.AppendInt(b, int64(t.Hour()), 10)
542 b = append(b, []byte{0x2e}...)
548 b = strconv.AppendInt(b, int64(t.Minute()), 10)
549 b = append(b, []byte{0x2e}...)
555 b = strconv.AppendInt(b, int64(t.Second()), 10)
556 b = append(b, []byte{0x20}...)
564 // FmtTimeFull returns the full time representation of 't' for 'fi'
565 func (fi *fi) FmtTimeFull(t time.Time) string {
567 b := make([]byte, 0, 32)
569 b = strconv.AppendInt(b, int64(t.Hour()), 10)
570 b = append(b, []byte{0x2e}...)
576 b = strconv.AppendInt(b, int64(t.Minute()), 10)
577 b = append(b, []byte{0x2e}...)
583 b = strconv.AppendInt(b, int64(t.Second()), 10)
584 b = append(b, []byte{0x20}...)
588 if btz, ok := fi.timezones[tz]; ok {
589 b = append(b, btz...)