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 'he' locale
45 func New() locales.Translator {
48 pluralsCardinal: []locales.PluralRule{2, 3, 5, 6},
49 pluralsOrdinal: []locales.PluralRule{6},
50 pluralsRange: []locales.PluralRule{5, 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", "CA$", "CDF", "CHE", "CHF", "CHW", "CLE", "CLF", "CLP", "CNX", "\u200eCN¥\u200e", "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", "ל״י", "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", "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"},
59 currencyPositiveSuffix: " ",
60 currencyNegativeSuffix: " ",
61 monthsAbbreviated: []string{"", "ינו׳", "פבר׳", "מרץ", "אפר׳", "מאי", "יוני", "יולי", "אוג׳", "ספט׳", "אוק׳", "נוב׳", "דצמ׳"},
62 monthsNarrow: []string{"", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"},
63 monthsWide: []string{"", "ינואר", "פברואר", "מרץ", "אפריל", "מאי", "יוני", "יולי", "אוגוסט", "ספטמבר", "אוקטובר", "נובמבר", "דצמבר"},
64 daysAbbreviated: []string{"יום א׳", "יום ב׳", "יום ג׳", "יום ד׳", "יום ה׳", "יום ו׳", "שבת"},
65 daysNarrow: []string{"א׳", "ב׳", "ג׳", "ד׳", "ה׳", "ו׳", "ש׳"},
66 daysShort: []string{"א׳", "ב׳", "ג׳", "ד׳", "ה׳", "ו׳", "ש׳"},
67 daysWide: []string{"יום ראשון", "יום שני", "יום שלישי", "יום רביעי", "יום חמישי", "יום שישי", "יום שבת"},
68 periodsAbbreviated: []string{"לפנה״צ", "אחה״צ"},
69 periodsNarrow: []string{"", ""},
70 periodsWide: []string{"לפנה״צ", "אחה״צ"},
71 erasAbbreviated: []string{"לפנה״ס", "לספירה"},
72 erasNarrow: []string{"", ""},
73 erasWide: []string{"", ""},
74 timezones: map[string]string{"AEDT": "שעון מזרח אוסטרליה (קיץ)", "COST": "שעון קולומביה (קיץ)", "GFT": "שעון גיאנה הצרפתית", "HNPMX": "שעון מערב מקסיקו (חורף)", "HEPM": "שעון סנט פייר ומיקלון (קיץ)", "MEZ": "שעון מרכז אירופה (חורף)", "OESZ": "שעון מזרח אירופה (קיץ)", "LHDT": "שעון אי הלורד האו (קיץ)", "ChST": "שעון צ׳אמורו", "SRT": "שעון סורינאם", "HENOMX": "שעון צפון-מערב מקסיקו (קיץ)", "ADT": "שעון האוקיינוס האטלנטי (קיץ)", "LHST": "שעון אי הלורד האו (חורף)", "ARST": "שעון ארגנטינה (קיץ)", "CLST": "שעון צ׳ילה (קיץ)", "MDT": "שעון קיץ מקאו", "ACWST": "שעון מרכז-מערב אוסטרליה (חורף)", "WITA": "שעון מרכז אינדונזיה", "GMT": "שעון גריניץ׳\u200f", "CHAST": "שעון צ׳טהאם (חורף)", "BOT": "שעון בוליביה", "CDT": "שעון מרכז ארה״ב (קיץ)", "MST": "שעון חורף מקאו", "IST": "שעון הודו", "HEEG": "שעון מזרח גרינלנד (קיץ)", "HKST": "שעון הונג קונג (קיץ)", "HEPMX": "שעון מערב מקסיקו (קיץ)", "HNPM": "שעון סנט פייר ומיקלון (חורף)", "NZST": "שעון ניו זילנד (חורף)", "WARST": "שעון מערב ארגנטינה (קיץ)", "EDT": "שעון החוף המזרחי (קיץ)", "HNCU": "שעון קובה (חורף)", "CHADT": "שעון צ׳טהאם (קיץ)", "BT": "שעון בהוטן", "UYT": "שעון אורוגוואי (חורף)", "ACWDT": "שעון מרכז-מערב אוסטרליה (קיץ)", "WEZ": "שעון מערב אירופה (חורף)", "CAT": "שעון מרכז אפריקה", "MYT": "שעון מלזיה", "JDT": "שעון יפן (קיץ)", "OEZ": "שעון מזרח אירופה (חורף)", "WAST": "שעון מערב אפריקה (קיץ)", "CLT": "שעון צ׳ילה (חורף)", "HEOG": "שעון מערב גרינלנד (קיץ)", "EAT": "שעון מזרח אפריקה", "COT": "שעון קולומביה (חורף)", "AKST": "שעון אלסקה (חורף)", "AKDT": "שעון אלסקה (קיץ)", "WIB": "שעון מערב אינדונזיה", "∅∅∅": "שעון ברזיליה (קיץ)", "CST": "שעון מרכז ארה״ב (חורף)", "JST": "שעון יפן (חורף)", "WAT": "שעון מערב אפריקה (חורף)", "AST": "שעון האוקיינוס האטלנטי (חורף)", "PDT": "שעון מערב ארה״ב (קיץ)", "NZDT": "שעון ניו זילנד (קיץ)", "MESZ": "שעון מרכז אירופה (קיץ)", "HNNOMX": "שעון צפון-מערב מקסיקו (חורף)", "HNOG": "שעון מערב גרינלנד (חורף)", "PST": "שעון מערב ארה״ב (חורף)", "VET": "שעון ונצואלה", "ART": "שעון ארגנטינה (חורף)", "AEST": "שעון מזרח אוסטרליה (חורף)", "SAST": "שעון דרום אפריקה", "HKT": "שעון הונג קונג (חורף)", "ACST": "שעון מרכז אוסטרליה (חורף)", "AWST": "שעון מערב אוסטרליה (חורף)", "UYST": "שעון אורוגוואי (קיץ)", "WIT": "שעון מזרח אינדונזיה", "TMST": "שעון טורקמניסטן (קיץ)", "WART": "שעון מערב ארגנטינה (חורף)", "AWDT": "שעון מערב אוסטרליה (קיץ)", "TMT": "שעון טורקמניסטן (חורף)", "HADT": "שעון האיים האלאוטיים הוואי (קיץ)", "GYT": "שעון גיאנה", "ACDT": "שעון מרכז אוסטרליה (קיץ)", "EST": "שעון החוף המזרחי (חורף)", "ECT": "שעון אקוודור", "SGT": "שעון סינגפור", "HECU": "שעון קובה (קיץ)", "HAST": "שעון האיים האלאוטיים הוואי (חורף)", "HNEG": "שעון מזרח גרינלנד (חורף)", "HNT": "שעון ניופאונדלנד (חורף)", "HAT": "שעון ניופאונדלנד (קיץ)", "WESZ": "שעון מערב אירופה (קיץ)"},
78 // Locale returns the current translators string locale
79 func (he *he) Locale() string {
83 // PluralsCardinal returns the list of cardinal plural rules associated with 'he'
84 func (he *he) PluralsCardinal() []locales.PluralRule {
85 return he.pluralsCardinal
88 // PluralsOrdinal returns the list of ordinal plural rules associated with 'he'
89 func (he *he) PluralsOrdinal() []locales.PluralRule {
90 return he.pluralsOrdinal
93 // PluralsRange returns the list of range plural rules associated with 'he'
94 func (he *he) PluralsRange() []locales.PluralRule {
95 return he.pluralsRange
98 // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'he'
99 func (he *he) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
103 nMod10 := math.Mod(n, 10)
105 if i == 1 && v == 0 {
106 return locales.PluralRuleOne
107 } else if i == 2 && v == 0 {
108 return locales.PluralRuleTwo
109 } else if v == 0 && (n < 0 || n > 10) && nMod10 == 0 {
110 return locales.PluralRuleMany
113 return locales.PluralRuleOther
116 // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'he'
117 func (he *he) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
118 return locales.PluralRuleOther
121 // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'he'
122 func (he *he) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
124 start := he.CardinalPluralRule(num1, v1)
125 end := he.CardinalPluralRule(num2, v2)
127 if start == locales.PluralRuleOne && end == locales.PluralRuleTwo {
128 return locales.PluralRuleOther
129 } else if start == locales.PluralRuleOne && end == locales.PluralRuleMany {
130 return locales.PluralRuleMany
131 } else if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
132 return locales.PluralRuleOther
133 } else if start == locales.PluralRuleTwo && end == locales.PluralRuleMany {
134 return locales.PluralRuleOther
135 } else if start == locales.PluralRuleTwo && end == locales.PluralRuleOther {
136 return locales.PluralRuleOther
137 } else if start == locales.PluralRuleMany && end == locales.PluralRuleMany {
138 return locales.PluralRuleMany
139 } else if start == locales.PluralRuleMany && end == locales.PluralRuleOther {
140 return locales.PluralRuleMany
141 } else if start == locales.PluralRuleOther && end == locales.PluralRuleOne {
142 return locales.PluralRuleOther
143 } else if start == locales.PluralRuleOther && end == locales.PluralRuleTwo {
144 return locales.PluralRuleOther
145 } else if start == locales.PluralRuleOther && end == locales.PluralRuleMany {
146 return locales.PluralRuleMany
149 return locales.PluralRuleOther
153 // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
154 func (he *he) MonthAbbreviated(month time.Month) string {
155 return he.monthsAbbreviated[month]
158 // MonthsAbbreviated returns the locales abbreviated months
159 func (he *he) MonthsAbbreviated() []string {
160 return he.monthsAbbreviated[1:]
163 // MonthNarrow returns the locales narrow month given the 'month' provided
164 func (he *he) MonthNarrow(month time.Month) string {
165 return he.monthsNarrow[month]
168 // MonthsNarrow returns the locales narrow months
169 func (he *he) MonthsNarrow() []string {
170 return he.monthsNarrow[1:]
173 // MonthWide returns the locales wide month given the 'month' provided
174 func (he *he) MonthWide(month time.Month) string {
175 return he.monthsWide[month]
178 // MonthsWide returns the locales wide months
179 func (he *he) MonthsWide() []string {
180 return he.monthsWide[1:]
183 // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
184 func (he *he) WeekdayAbbreviated(weekday time.Weekday) string {
185 return he.daysAbbreviated[weekday]
188 // WeekdaysAbbreviated returns the locales abbreviated weekdays
189 func (he *he) WeekdaysAbbreviated() []string {
190 return he.daysAbbreviated
193 // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
194 func (he *he) WeekdayNarrow(weekday time.Weekday) string {
195 return he.daysNarrow[weekday]
198 // WeekdaysNarrow returns the locales narrow weekdays
199 func (he *he) WeekdaysNarrow() []string {
203 // WeekdayShort returns the locales short weekday given the 'weekday' provided
204 func (he *he) WeekdayShort(weekday time.Weekday) string {
205 return he.daysShort[weekday]
208 // WeekdaysShort returns the locales short weekdays
209 func (he *he) WeekdaysShort() []string {
213 // WeekdayWide returns the locales wide weekday given the 'weekday' provided
214 func (he *he) WeekdayWide(weekday time.Weekday) string {
215 return he.daysWide[weekday]
218 // WeekdaysWide returns the locales wide weekdays
219 func (he *he) WeekdaysWide() []string {
223 // Decimal returns the decimal point of number
224 func (he *he) Decimal() string {
228 // Group returns the group of number
229 func (he *he) Group() string {
233 // Group returns the minus sign of number
234 func (he *he) Minus() string {
238 // FmtNumber returns 'num' with digits/precision of 'v' for 'he' and handles both Whole and Real numbers based on 'v'
239 func (he *he) FmtNumber(num float64, v uint64) string {
241 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
242 l := len(s) + 5 + 1*len(s[:len(s)-int(v)-1])/3
245 b := make([]byte, 0, l)
247 for i := len(s) - 1; i >= 0; i-- {
250 b = append(b, he.decimal[0])
257 b = append(b, he.group[0])
268 for j := len(he.minus) - 1; j >= 0; j-- {
269 b = append(b, he.minus[j])
274 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
275 b[i], b[j] = b[j], b[i]
281 // FmtPercent returns 'num' with digits/precision of 'v' for 'he' and handles both Whole and Real numbers based on 'v'
282 // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
283 func (he *he) FmtPercent(num float64, v uint64) string {
284 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
286 b := make([]byte, 0, l)
288 for i := len(s) - 1; i >= 0; i-- {
291 b = append(b, he.decimal[0])
299 for j := len(he.minus) - 1; j >= 0; j-- {
300 b = append(b, he.minus[j])
305 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
306 b[i], b[j] = b[j], b[i]
309 b = append(b, he.percent...)
314 // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'he'
315 func (he *he) FmtCurrency(num float64, v uint64, currency currency.Type) string {
317 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
318 symbol := he.currencies[currency]
319 l := len(s) + len(symbol) + 7 + 1*len(s[:len(s)-int(v)-1])/3
322 b := make([]byte, 0, l)
324 for i := len(s) - 1; i >= 0; i-- {
327 b = append(b, he.decimal[0])
334 b = append(b, he.group[0])
345 for j := len(he.minus) - 1; j >= 0; j-- {
346 b = append(b, he.minus[j])
351 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
352 b[i], b[j] = b[j], b[i]
358 b = append(b, he.decimal...)
361 for i := 0; i < 2-int(v); i++ {
366 b = append(b, he.currencyPositiveSuffix...)
368 b = append(b, symbol...)
373 // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'he'
374 // in accounting notation.
375 func (he *he) FmtAccounting(num float64, v uint64, currency currency.Type) string {
377 s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
378 symbol := he.currencies[currency]
379 l := len(s) + len(symbol) + 7 + 1*len(s[:len(s)-int(v)-1])/3
382 b := make([]byte, 0, l)
384 for i := len(s) - 1; i >= 0; i-- {
387 b = append(b, he.decimal[0])
394 b = append(b, he.group[0])
406 for j := len(he.minus) - 1; j >= 0; j-- {
407 b = append(b, he.minus[j])
413 for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
414 b[i], b[j] = b[j], b[i]
420 b = append(b, he.decimal...)
423 for i := 0; i < 2-int(v); i++ {
429 b = append(b, he.currencyNegativeSuffix...)
430 b = append(b, symbol...)
433 b = append(b, he.currencyPositiveSuffix...)
434 b = append(b, symbol...)
440 // FmtDateShort returns the short date representation of 't' for 'he'
441 func (he *he) FmtDateShort(t time.Time) string {
443 b := make([]byte, 0, 32)
445 b = strconv.AppendInt(b, int64(t.Day()), 10)
446 b = append(b, []byte{0x2e}...)
447 b = strconv.AppendInt(b, int64(t.Month()), 10)
448 b = append(b, []byte{0x2e}...)
451 b = strconv.AppendInt(b, int64(t.Year()), 10)
453 b = strconv.AppendInt(b, int64(-t.Year()), 10)
459 // FmtDateMedium returns the medium date representation of 't' for 'he'
460 func (he *he) FmtDateMedium(t time.Time) string {
462 b := make([]byte, 0, 32)
464 b = strconv.AppendInt(b, int64(t.Day()), 10)
465 b = append(b, []byte{0x20, 0xd7, 0x91}...)
466 b = append(b, he.monthsAbbreviated[t.Month()]...)
467 b = append(b, []byte{0x20}...)
470 b = strconv.AppendInt(b, int64(t.Year()), 10)
472 b = strconv.AppendInt(b, int64(-t.Year()), 10)
478 // FmtDateLong returns the long date representation of 't' for 'he'
479 func (he *he) FmtDateLong(t time.Time) string {
481 b := make([]byte, 0, 32)
483 b = strconv.AppendInt(b, int64(t.Day()), 10)
484 b = append(b, []byte{0x20, 0xd7, 0x91}...)
485 b = append(b, he.monthsWide[t.Month()]...)
486 b = append(b, []byte{0x20}...)
489 b = strconv.AppendInt(b, int64(t.Year()), 10)
491 b = strconv.AppendInt(b, int64(-t.Year()), 10)
497 // FmtDateFull returns the full date representation of 't' for 'he'
498 func (he *he) FmtDateFull(t time.Time) string {
500 b := make([]byte, 0, 32)
502 b = append(b, he.daysWide[t.Weekday()]...)
503 b = append(b, []byte{0x2c, 0x20}...)
504 b = strconv.AppendInt(b, int64(t.Day()), 10)
505 b = append(b, []byte{0x20, 0xd7, 0x91}...)
506 b = append(b, he.monthsWide[t.Month()]...)
507 b = append(b, []byte{0x20}...)
510 b = strconv.AppendInt(b, int64(t.Year()), 10)
512 b = strconv.AppendInt(b, int64(-t.Year()), 10)
518 // FmtTimeShort returns the short time representation of 't' for 'he'
519 func (he *he) FmtTimeShort(t time.Time) string {
521 b := make([]byte, 0, 32)
523 b = strconv.AppendInt(b, int64(t.Hour()), 10)
524 b = append(b, he.timeSeparator...)
530 b = strconv.AppendInt(b, int64(t.Minute()), 10)
535 // FmtTimeMedium returns the medium time representation of 't' for 'he'
536 func (he *he) FmtTimeMedium(t time.Time) string {
538 b := make([]byte, 0, 32)
540 b = strconv.AppendInt(b, int64(t.Hour()), 10)
541 b = append(b, he.timeSeparator...)
547 b = strconv.AppendInt(b, int64(t.Minute()), 10)
548 b = append(b, he.timeSeparator...)
554 b = strconv.AppendInt(b, int64(t.Second()), 10)
559 // FmtTimeLong returns the long time representation of 't' for 'he'
560 func (he *he) FmtTimeLong(t time.Time) string {
562 b := make([]byte, 0, 32)
564 b = strconv.AppendInt(b, int64(t.Hour()), 10)
565 b = append(b, he.timeSeparator...)
571 b = strconv.AppendInt(b, int64(t.Minute()), 10)
572 b = append(b, he.timeSeparator...)
578 b = strconv.AppendInt(b, int64(t.Second()), 10)
579 b = append(b, []byte{0x20}...)
587 // FmtTimeFull returns the full time representation of 't' for 'he'
588 func (he *he) FmtTimeFull(t time.Time) string {
590 b := make([]byte, 0, 32)
592 b = strconv.AppendInt(b, int64(t.Hour()), 10)
593 b = append(b, he.timeSeparator...)
599 b = strconv.AppendInt(b, int64(t.Minute()), 10)
600 b = append(b, he.timeSeparator...)
606 b = strconv.AppendInt(b, int64(t.Second()), 10)
607 b = append(b, []byte{0x20}...)
611 if btz, ok := he.timezones[tz]; ok {
612 b = append(b, btz...)