go version)?$ go version go version go1.12.2 windows/amd64
Yes
go env)?go env Output
$ go env
set GOARCH=amd64
set GOBIN=
set GOCACHE=......AppDataLocalgo-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=.....go
set GOPROXY=
set GORACE=
set GOROOT=C:Go
set GOTMPDIR=
set GOTOOLDIR=C:Gopkgtoolwindows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=.....AppDataLocalTempgo-build844154330=/tmp/go-build -gno-record-gcc-switches
I am developing a web app that should support multiple languages (days and months names should also change when user selects a languag). I am using "github.com/beego/i18n" to achieve i18n on my front-end. All days and months (long and short names) are configured for each language in the locale.ini specified for that language. Even when I read the days and months for each language, I am not able to pass it so the time module uses it instead of the hard-coded English long/short days and months names.
Suggesting
var longDayNames
var shortDayNames
var shortMonthNames
var longMonthNames
be changed to
var ShortDayNames
var LongDayNames
var ShortMonthNames
var LongMonthNames
func (c *ExtendedController) UpdateDaysAndMonthsToUserLocale() {
time.LongDayNames = []string{
i18n.Tr(c.Lang, "LongDayNameSunday"),
i18n.Tr(c.Lang, "LongDayNameMonday"),
i18n.Tr(c.Lang, "LongDayNameTuesday"),
i18n.Tr(c.Lang, "LongDayNameWednesday"),
i18n.Tr(c.Lang, "LongDayNameThursday"),
i18n.Tr(c.Lang, "LongDayNameFriday"),
i18n.Tr(c.Lang, "LongDayNameSaturday"),
}
for index := 0; index < len(time.LongDayNames); index++ {
time.Days[index] = time.LongDayNames[index]
}
time.ShortDayNames = []string{
i18n.Tr(c.Lang, "ShortDayNameSunday"),
i18n.Tr(c.Lang, "ShortDayNameMonday"),
i18n.Tr(c.Lang, "ShortDayNameTuesday"),
i18n.Tr(c.Lang, "ShortDayNameWednesday"),
i18n.Tr(c.Lang, "ShortDayNameThursday"),
i18n.Tr(c.Lang, "ShortDayNameFriday"),
i18n.Tr(c.Lang, "ShortDayNameSaturday"),
}
time.LongMonthNames = []string{
i18n.Tr(c.Lang, "LongMonthNameJanuary"),
i18n.Tr(c.Lang, "LongMonthNameFebruary"),
i18n.Tr(c.Lang, "LongMonthNameMarch"),
i18n.Tr(c.Lang, "LongMonthNameApril"),
i18n.Tr(c.Lang, "LongMonthNameMay"),
i18n.Tr(c.Lang, "LongMonthNameJune"),
i18n.Tr(c.Lang, "LongMonthNameJuly"),
i18n.Tr(c.Lang, "LongMonthNameAugust"),
i18n.Tr(c.Lang, "LongMonthNameSeptember"),
i18n.Tr(c.Lang, "LongMonthNameOctober"),
i18n.Tr(c.Lang, "LongMonthNameNovember"),
i18n.Tr(c.Lang, "LongMonthNameDecember"),
}
for index := 0; index < len(time.LongMonthNames); index++ {
time.Months[index] = time.LongMonthNames[index]
}
time.ShortMonthNames = []string{
i18n.Tr(c.Lang, "ShortMonthNameJanuary"),
i18n.Tr(c.Lang, "ShortMonthNameFebruary"),
i18n.Tr(c.Lang, "ShortMonthNameMarch"),
i18n.Tr(c.Lang, "ShortMonthNameApril"),
i18n.Tr(c.Lang, "ShortMonthNameMay"),
i18n.Tr(c.Lang, "ShortMonthNameJune"),
i18n.Tr(c.Lang, "ShortMonthNameJuly"),
i18n.Tr(c.Lang, "ShortMonthNameAugust"),
i18n.Tr(c.Lang, "ShortMonthNameSeptember"),
i18n.Tr(c.Lang, "ShortMonthNameOctober"),
i18n.Tr(c.Lang, "ShortMonthNameNovember"),
i18n.Tr(c.Lang, "ShortMonthNameDecember"),
}
}
var LongDayNames = []string{
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
}
var ShortDayNames = []string{
"Sun",
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat",
}
var ShortMonthNames = []string{
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec",
}
var LongMonthNames = []string{
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
}
var longDayNames = []string{
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
}
var shortDayNames = []string{
"Sun",
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat",
}
var shortMonthNames = []string{
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec",
}
var longMonthNames = []string{
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
}
This is an API change, so I turned it into a proposal.
Personally I think this is simply beyond the scope of the time package. The time package provides simple functionality, using some English words, with no support for internationalization. Serious internationalization support should be done using a different package, such as https://godoc.org/gitlab.com/variadico/lctime (note that I have never tried that package myself and I don't know its quality).
Yes, this is definitely beyond the scope of the time package.
For better or worse, time prints English names.
Internationalized time support is meant to be in golang.org/x/text/date, but it hasn't been completed.
There's already an answer (use x/text/date), and the suggested approach is not safe for use by multiple goroutines: what if you have a server that wants to format dates differently in different requests? Modifying globals is not safe there.
This seems like a likely decline (unsafe, functionality started elsewhere).
Leaving open for a week for final comments.
No change in consensus, so declining.
Most helpful comment
This is an API change, so I turned it into a proposal.
Personally I think this is simply beyond the scope of the time package. The time package provides simple functionality, using some English words, with no support for internationalization. Serious internationalization support should be done using a different package, such as https://godoc.org/gitlab.com/variadico/lctime (note that I have never tried that package myself and I don't know its quality).