i18n
The following languages are supported(according to the order of translation time)
- Simplified Chinese(zh-CN):translated by gouguoyin
- Traditional Chinese(zh-TW):translated by gouguoyin
- English(en):translated by gouguoyin
- Japanese(jp):translated by gouguoyin
- Korean(kr):translated by nannul
- German(de):translated by benzammour
- Spanish(es):translated by hgisinger
- Turkish(tr): translated by emresenyuva
- Portuguese(pt): translated by felipear89
- Russian(ru): translated by zemlyak
- Ukrainian(uk): translated by open-git
- Romanian(ro): translated by DrOctavius
- Indonesian(id): translated by justpoypoy
- Italian(it): translated by nicoloHevelop
- Bahasa Malaysia(ms-MY): translated by hollowaykeanho
- French(fr): translated by hollowaykeanho
- Thailand(th): translated by izcream
- Swedish(se): translated by jwanglof
- Farsi(fa): translated by erfanMomeniii
- Dutch(nl): translated by RemcoE33
- VietNamese(vi): translated by culy247
- Hindi(hi): translated by chauhan17nitin
- Polish(pl): translated by gouguoyin
- Bulgarian(bg): translated by yuksbg
- Arabic(ar): translated by zumoshi
- Hungarian(hu): translated by kenlas
- Dansk(dk): translated by Munk91
- Norwegian(nb): translated by bendikrb
Ask for help to translate carbon in other languages
The following methods are supported
Constellation()
:get constellation name, likeAries
Season()
:get season name, likeSpring
DiffForHumans()
:get the difference with human-readable format string, like1 year from now
ToMonthString()
:output month format string, likeJanuary
ToShortMonthString()
:output short month format string, likeJan
ToWeekString()
:output week format string, likeSunday
ToShortWeekString()
:output short week format string, likeSun
Set locale
go
lang := carbon.NewLanguage()
lang.SetLocale("en")
carbon.SetTestNow(carbon.Parse("2020-08-05 13:14:15"))
now := carbon.Now().SetLanguage(lang)
now.Copy().AddHours(1).DiffForHumans() // 1 hour from now
now.Copy().AddHours(1).ToMonthString() // August
now.Copy().AddHours(1).ToShortMonthString() // Aug
now.Copy().AddHours(1).ToWeekString() // Wednesday
now.Copy().AddHours(1).ToShortWeekString() // Wed
now.Copy().AddHours(1).Constellation() // Leo
now.Copy().AddHours(1).Season() // Summer
Reset some resources
the rests still translate from the given locale
go
lang := carbon.NewLanguage()
resources := map[string]string {
"hour": "%dh",
}
lang.SetLocale("en").SetResources(resources)
carbon.SetTestNow(carbon.Parse("2020-08-05 13:14:15"))
now := carbon.Now().SetLanguage(lang)
now.Copy().AddYears(1).DiffForHumans() // 1 year from now
now.Copy().AddHours(1).DiffForHumans() // 1h from now
now.ToMonthString() // August
now.ToShortMonthString() // Aug
now.ToWeekString() // Tuesday
now.ToShortWeekString() // Tue
now.Constellation() // Leo
now.Season() // Summer
Reset all resources
go
lang := carbon.NewLanguage()
resources := map[string]string {
"months": "january|february|march|april|may|june|july|august|september|october|november|december",
"short_months": "jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec",
"weeks": "sunday|monday|tuesday|wednesday|thursday|friday|saturday",
"short_weeks": "sun|mon|tue|wed|thu|fri|sat",
"seasons": "spring|summer|autumn|winter",
"constellations": "aries|taurus|gemini|cancer|leo|virgo|libra|scorpio|sagittarius|capricornus|aquarius|pisce",
"year": "1 yr|%d yrs",
"month": "1 mo|%d mos",
"week": "%dw",
"day": "%dd",
"hour": "%dh",
"minute": "%dm",
"second": "%ds",
"now": "just now",
"ago": "%s ago",
"from_now": "in %s",
"before": "%s before",
"after": "%s after",
}
lang.SetResources(resources)
carbon.SetTestNow(carbon.Parse("2020-08-05 13:14:15"))
now := carbon.Now().SetLanguage(lang)
now.Copy().AddYears(1).DiffForHumans() // in 1 yr
now.Copy().AddHours(1).DiffForHumans() // in 1h
now.ToMonthString() // august
now.ToShortMonthString() // aug
now.ToWeekString() // tuesday
now.ToShortWeekString() // tue
now.Constellation() // leo
now.Season() // summer