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 currencyNegativePrefix 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 'el' locale
46 func New() locales.Translator {
49 pluralsCardinal: []locales.PluralRule{2, 6},
50 pluralsOrdinal: []locales.PluralRule{6},
51 pluralsRange: []locales.PluralRule{2, 6},
59 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", "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", "Δρχ", "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", "$", "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"},
60 currencyPositiveSuffix: " ",
61 currencyNegativePrefix: "(",
62 currencyNegativeSuffix: " )",
63 monthsAbbreviated: []string{"", "Ιαν", "Φεβ", "Μαρ", "Απρ", "Μαΐ", "Ιουν", "Ιουλ", "Αυγ", "Σεπ", "Οκτ", "Νοε", "Δεκ"},
64 monthsNarrow: []string{"", "Ι", "Φ", "Μ", "Α", "Μ", "Ι", "Ι", "Α", "Σ", "Ο", "Ν", "Δ"},
65 monthsWide: []string{"", "Ιανουαρίου", "Φεβρουαρίου", "Μαρτίου", "Απριλίου", "Μαΐου", "Ιουνίου", "Ιουλίου", "Αυγούστου", "Σεπτεμβρίου", "Οκτωβρίου", "Νοεμβρίου", "Δεκεμβρίου"},
66 daysAbbreviated: []string{"Κυρ", "Δευ", "Τρί", "Τετ", "Πέμ", "Παρ", "Σάβ"},
67 daysNarrow: []string{"Κ", "Δ", "Τ", "Τ", "Π", "Π", "Σ"},
68 daysShort: []string{"Κυ", "Δε", "Τρ", "Τε", "Πέ", "Πα", "Σά"},
69 daysWide: []string{"Κυριακή", "Δευτέρα", "Τρίτη", "Τετάρτη", "Πέμπτη", "Παρασκευή", "Σάββατο"},
70 periodsAbbreviated: []string{"π.μ.", "μ.μ."},
71 periodsNarrow: []string{"πμ", "μμ"},
72 periodsWide: []string{"π.μ.", "μ.μ."},
73 erasAbbreviated: []string{"π.Χ.", "μ.Χ."},
74 erasNarrow: []string{"", ""},
75 erasWide: []string{"προ Χριστού", "μετά Χριστόν"},
76 timezones: map[string]string{"ACDT": "Θερινή ώρα Κεντρικής Αυστραλίας", "WIB": "Ώρα Δυτικής Ινδονησίας", "LHST": "Χειμερινή ώρα Λορντ Χάου", "IST": "Ώρα Ινδίας", "HEEG": "Θερινή ώρα Ανατολικής Γροιλανδίας", "TMT": "Χειμερινή ώρα Τουρκμενιστάν", "OESZ": "Θερινή ώρα Ανατολικής Ευρώπης", "ART": "Χειμερινή ώρα Αργεντινής", "HNOG": "Χειμερινή ώρα Δυτικής Γροιλανδίας", "HEOG": "Θερινή ώρα Δυτικής Γροιλανδίας", "HAT": "Θερινή ώρα Νέας Γης", "EST": "Ανατολική χειμερινή ώρα Βόρειας Αμερικής", "HECU": "Θερινή ώρα Κούβας", "CST": "Κεντρική χειμερινή ώρα Βόρειας Αμερικής", "AWDT": "Θερινή ώρα Δυτικής Αυστραλίας", "MYT": "Ώρα Μαλαισίας", "NZDT": "Θερινή ώρα Νέας Ζηλανδίας", "VET": "Ώρα Βενεζουέλας", "AST": "Χειμερινή ώρα Ατλαντικού", "AEST": "Χειμερινή ώρα Ανατολικής Αυστραλίας", "WAST": "Θερινή ώρα Δυτικής Αφρικής", "HKST": "Θερινή ώρα Χονγκ Κονγκ", "HEPMX": "Θερινή ώρα Ειρηνικού Μεξικού", "BT": "Ώρα Μπουτάν", "HENOMX": "Θερινή ώρα Βορειοδυτικού Μεξικού", "ADT": "Θερινή ώρα Ατλαντικού", "ARST": "Θερινή ώρα Αργεντινής", "ACST": "Χειμερινή ώρα Κεντρικής Αυστραλίας", "CAT": "Ώρα Κεντρικής Αφρικής", "SGT": "Ώρα Σιγκαπούρης", "ChST": "Ώρα Τσαμόρο", "HEPM": "Θερινή ώρα Σαιντ Πιερ και Μικελόν", "WARST": "Θερινή ώρα Δυτικής Αργεντινής", "AKDT": "Θερινή ώρα Αλάσκας", "SAST": "Χειμερινή ώρα Νότιας Αφρικής", "AKST": "Χειμερινή ώρα Αλάσκας", "HNCU": "Χειμερινή ώρα Κούβας", "SRT": "Ώρα Σουρινάμ", "ACWDT": "Θερινή ώρα Κεντροδυτικής Αυστραλίας", "HAST": "Χειμερινή ώρα Χαβάης-Αλεούτιων νήσων", "HNEG": "Χειμερινή ώρα Ανατολικής Γροιλανδίας", "WIT": "Ώρα Ανατολικής Ινδονησίας", "MEZ": "Χειμερινή ώρα Κεντρικής Ευρώπης", "LHDT": "Θερινή ώρα Λορντ Χάου", "WAT": "Χειμερινή ώρα Δυτικής Αφρικής", "CLT": "Χειμερινή ώρα Χιλής", "GYT": "Ώρα Γουιάνας", "ECT": "Ώρα Εκουαδόρ", "AWST": "Χειμερινή ώρα Δυτικής Αυστραλίας", "HNPMX": "Χειμερινή ώρα Ειρηνικού Μεξικού", "TMST": "Θερινή ώρα Τουρκμενιστάν", "HNNOMX": "Χειμερινή ώρα Βορειοδυτικού Μεξικού", "WEZ": "Χειμερινή ώρα Δυτικής Ευρώπης", "PDT": "Θερινή ώρα Βόρειας Αμερικής", "MST": "Χειμερινή ώρα Μακάο", "WART": "Χειμερινή ώρα Δυτικής Αργεντινής", "∅∅∅": "Θερινή ώρα Αμαζονίου", "WESZ": "Θερινή ώρα Δυτικής Ευρώπης", "PST": "Χειμερινή ώρα Βόρειας Αμερικής", "CDT": "Κεντρική θερινή ώρα Βόρειας Αμερικής", "MDT": "Θερινή ώρα Μακάο", "ACWST": "Χειμερινή ώρα Κεντροδυτικής Αυστραλίας", "NZST": "Χειμερινή ώρα Νέας Ζηλανδίας", "JST": "Χειμερινή ώρα Ιαπωνίας", "JDT": "Θερινή ώρα Ιαπωνίας", "OEZ": "Χειμερινή ώρα Ανατολικής Ευρώπης", "EAT": "Ώρα Ανατολικής Αφρικής", "COT": "Χειμερινή ώρα Κολομβίας", "GMT": "Μέση ώρα Γκρίνουιτς", "HNPM": "Χειμερινή ώρα Σαιντ Πιερ και Μικελόν", "WITA": "Ώρα Κεντρικής Ινδονησίας", "AEDT": "Θερινή ώρα Ανατολικής Αυστραλίας", "CHAST": "Χειμερινή ώρα Τσάθαμ", "BOT": "Ώρα Βολιβίας", "UYT": "Χειμερινή ώρα Ουρουγουάης", "MESZ": "Θερινή ώρα Κεντρικής Ευρώπης", "HKT": "Χειμερινή ώρα Χονγκ Κονγκ", "CLST": "Θερινή ώρα Χιλής", "CHADT": "Θερινή ώρα Τσάθαμ", "UYST": "Θερινή ώρα Ουρουγουάης", "HADT": "Θερινή ώρα Χαβάης-Αλεούτιων νήσων", "HNT": "Χειμερινή ώρα Νέας Γης", "COST": "Θερινή ώρα Κολομβίας", "GFT": "Ώρα Γαλλικής Γουιάνας", "EDT": "Ανατολική θερινή ώρα Βόρειας Αμερικής"},
80 // Locale returns the current translators string locale
81 func (el *el) Locale() string {
85 // PluralsCardinal returns the list of cardinal plural rules associated with 'el'
86 func (el *el) PluralsCardinal() []locales.PluralRule {
87 return el.pluralsCardinal
90 // PluralsOrdinal returns the list of ordinal plural rules associated with 'el'
91 func (el *el) PluralsOrdinal() []locales.PluralRule {
92 return el.pluralsOrdinal
95 // PluralsRange returns the list of range plural rules associated with 'el'
96 func (el *el) PluralsRange() []locales.PluralRule {
97 return el.pluralsRange
100 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'el'
101 func (el *el) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
106 return locales.PluralRuleOne
109 return locales.PluralRuleOther
112 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'el'
113 func (el *el) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
114 return locales.PluralRuleOther
117 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'el'
118 func (el *el) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
120 start := el.CardinalPluralRule(num1, v1)
121 end := el.CardinalPluralRule(num2, v2)
123 if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
124 return locales.PluralRuleOther
125 } else if start == locales.PluralRuleOther && end == locales.PluralRuleOne {
126 return locales.PluralRuleOne
129 return locales.PluralRuleOther
133 // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
134 func (el *el) MonthAbbreviated(month time.Month) string {
135 return el.monthsAbbreviated[month]
138 // MonthsAbbreviated returns the locales abbreviated months
139 func (el *el) MonthsAbbreviated() []string {
140 return el.monthsAbbreviated[1:]
143 // MonthNarrow returns the locales narrow month given the 'month' provided
144 func (el *el) MonthNarrow(month time.Month) string {
145 return el.monthsNarrow[month]
148 // MonthsNarrow returns the locales narrow months
149 func (el *el) MonthsNarrow() []string {
150 return el.monthsNarrow[1:]
153 // MonthWide returns the locales wide month given the 'month' provided
154 func (el *el) MonthWide(month time.Month) string {
155 return el.monthsWide[month]
158 // MonthsWide returns the locales wide months
159 func (el *el) MonthsWide() []string {
160 return el.monthsWide[1:]
163 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
164 func (el *el) WeekdayAbbreviated(weekday time.Weekday) string {
165 return el.daysAbbreviated[weekday]
168 // WeekdaysAbbreviated returns the locales abbreviated weekdays
169 func (el *el) WeekdaysAbbreviated() []string {
170 return el.daysAbbreviated
173 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
174 func (el *el) WeekdayNarrow(weekday time.Weekday) string {
175 return el.daysNarrow[weekday]
178 // WeekdaysNarrow returns the locales narrow weekdays
179 func (el *el) WeekdaysNarrow() []string {
183 // WeekdayShort returns the locales short weekday given the 'weekday' provided
184 func (el *el) WeekdayShort(weekday time.Weekday) string {
185 return el.daysShort[weekday]
188 // WeekdaysShort returns the locales short weekdays
189 func (el *el) WeekdaysShort() []string {
193 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
194 func (el *el) WeekdayWide(weekday time.Weekday) string {
195 return el.daysWide[weekday]
198 // WeekdaysWide returns the locales wide weekdays
199 func (el *el) WeekdaysWide() []string {
203 // Decimal returns the decimal point of number
204 func (el *el) Decimal() string {
208 // Group returns the group of number
209 func (el *el) Group() string {
213 // Group returns the minus sign of number
214 func (el *el) Minus() string {
218 // FmtNumber returns 'num' with digits/precision of 'v' for 'el' and handles both Whole and Real numbers based on 'v'
219 func (el *el) FmtNumber(num float64, v uint64) string {
221 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
222 l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
225 b := make([]byte, 0, l)
227 for i := len(s) - 1; i >= 0; i-- {
230 b = append(b, el.decimal[0])
237 b = append(b, el.group[0])
248 b = append(b, el.minus[0])
252 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
253 b[i], b[j] = b[j], b[i]
259 // FmtPercent returns 'num' with digits/precision of 'v' for 'el' and handles both Whole and Real numbers based on 'v'
260 // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
261 func (el *el) FmtPercent(num float64, v uint64) string {
262 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
264 b := make([]byte, 0, l)
266 for i := len(s) - 1; i >= 0; i-- {
269 b = append(b, el.decimal[0])
277 b = append(b, el.minus[0])
281 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
282 b[i], b[j] = b[j], b[i]
285 b = append(b, el.percent...)
290 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'el'
291 func (el *el) FmtCurrency(num float64, v uint64, currency currency.Type) string {
293 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
294 symbol := el.currencies[currency]
295 l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
298 b := make([]byte, 0, l)
300 for i := len(s) - 1; i >= 0; i-- {
303 b = append(b, el.decimal[0])
310 b = append(b, el.group[0])
321 b = append(b, el.minus[0])
325 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
326 b[i], b[j] = b[j], b[i]
332 b = append(b, el.decimal...)
335 for i := 0; i < 2-int(v); i++ {
340 b = append(b, el.currencyPositiveSuffix...)
342 b = append(b, symbol...)
347 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'el'
348 // in accounting notation.
349 func (el *el) FmtAccounting(num float64, v uint64, currency currency.Type) string {
351 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
352 symbol := el.currencies[currency]
353 l := len(s) + len(symbol) + 6 + 1*len(s[:len(s)-int(v)-1])/3
356 b := make([]byte, 0, l)
358 for i := len(s) - 1; i >= 0; i-- {
361 b = append(b, el.decimal[0])
368 b = append(b, el.group[0])
380 b = append(b, el.currencyNegativePrefix[0])
385 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
386 b[i], b[j] = b[j], b[i]
392 b = append(b, el.decimal...)
395 for i := 0; i < 2-int(v); i++ {
401 b = append(b, el.currencyNegativeSuffix...)
402 b = append(b, symbol...)
405 b = append(b, el.currencyPositiveSuffix...)
406 b = append(b, symbol...)
412 // FmtDateShort returns the short date representation of 't' for 'el'
413 func (el *el) FmtDateShort(t time.Time) string {
415 b := make([]byte, 0, 32)
417 b = strconv.AppendInt(b, int64(t.Day()), 10)
418 b = append(b, []byte{0x2f}...)
419 b = strconv.AppendInt(b, int64(t.Month()), 10)
420 b = append(b, []byte{0x2f}...)
423 b = append(b, strconv.Itoa(t.Year())[2:]...)
425 b = append(b, strconv.Itoa(t.Year())[1:]...)
431 // FmtDateMedium returns the medium date representation of 't' for 'el'
432 func (el *el) FmtDateMedium(t time.Time) string {
434 b := make([]byte, 0, 32)
436 b = strconv.AppendInt(b, int64(t.Day()), 10)
437 b = append(b, []byte{0x20}...)
438 b = append(b, el.monthsAbbreviated[t.Month()]...)
439 b = append(b, []byte{0x20}...)
442 b = strconv.AppendInt(b, int64(t.Year()), 10)
444 b = strconv.AppendInt(b, int64(-t.Year()), 10)
450 // FmtDateLong returns the long date representation of 't' for 'el'
451 func (el *el) FmtDateLong(t time.Time) string {
453 b := make([]byte, 0, 32)
455 b = strconv.AppendInt(b, int64(t.Day()), 10)
456 b = append(b, []byte{0x20}...)
457 b = append(b, el.monthsWide[t.Month()]...)
458 b = append(b, []byte{0x20}...)
461 b = strconv.AppendInt(b, int64(t.Year()), 10)
463 b = strconv.AppendInt(b, int64(-t.Year()), 10)
469 // FmtDateFull returns the full date representation of 't' for 'el'
470 func (el *el) FmtDateFull(t time.Time) string {
472 b := make([]byte, 0, 32)
474 b = append(b, el.daysWide[t.Weekday()]...)
475 b = append(b, []byte{0x2c, 0x20}...)
476 b = strconv.AppendInt(b, int64(t.Day()), 10)
477 b = append(b, []byte{0x20}...)
478 b = append(b, el.monthsWide[t.Month()]...)
479 b = append(b, []byte{0x20}...)
482 b = strconv.AppendInt(b, int64(t.Year()), 10)
484 b = strconv.AppendInt(b, int64(-t.Year()), 10)
490 // FmtTimeShort returns the short time representation of 't' for 'el'
491 func (el *el) FmtTimeShort(t time.Time) string {
493 b := make([]byte, 0, 32)
501 b = strconv.AppendInt(b, int64(h), 10)
502 b = append(b, el.timeSeparator...)
508 b = strconv.AppendInt(b, int64(t.Minute()), 10)
509 b = append(b, []byte{0x20}...)
512 b = append(b, el.periodsAbbreviated[0]...)
514 b = append(b, el.periodsAbbreviated[1]...)
520 // FmtTimeMedium returns the medium time representation of 't' for 'el'
521 func (el *el) FmtTimeMedium(t time.Time) string {
523 b := make([]byte, 0, 32)
531 b = strconv.AppendInt(b, int64(h), 10)
532 b = append(b, el.timeSeparator...)
538 b = strconv.AppendInt(b, int64(t.Minute()), 10)
539 b = append(b, el.timeSeparator...)
545 b = strconv.AppendInt(b, int64(t.Second()), 10)
546 b = append(b, []byte{0x20}...)
549 b = append(b, el.periodsAbbreviated[0]...)
551 b = append(b, el.periodsAbbreviated[1]...)
557 // FmtTimeLong returns the long time representation of 't' for 'el'
558 func (el *el) FmtTimeLong(t time.Time) string {
560 b := make([]byte, 0, 32)
568 b = strconv.AppendInt(b, int64(h), 10)
569 b = append(b, el.timeSeparator...)
575 b = strconv.AppendInt(b, int64(t.Minute()), 10)
576 b = append(b, el.timeSeparator...)
582 b = strconv.AppendInt(b, int64(t.Second()), 10)
583 b = append(b, []byte{0x20}...)
586 b = append(b, el.periodsAbbreviated[0]...)
588 b = append(b, el.periodsAbbreviated[1]...)
591 b = append(b, []byte{0x20}...)
599 // FmtTimeFull returns the full time representation of 't' for 'el'
600 func (el *el) FmtTimeFull(t time.Time) string {
602 b := make([]byte, 0, 32)
610 b = strconv.AppendInt(b, int64(h), 10)
611 b = append(b, el.timeSeparator...)
617 b = strconv.AppendInt(b, int64(t.Minute()), 10)
618 b = append(b, el.timeSeparator...)
624 b = strconv.AppendInt(b, int64(t.Second()), 10)
625 b = append(b, []byte{0x20}...)
628 b = append(b, el.periodsAbbreviated[0]...)
630 b = append(b, el.periodsAbbreviated[1]...)
633 b = append(b, []byte{0x20}...)
637 if btz, ok := el.timezones[tz]; ok {
638 b = append(b, btz...)