Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: time: Long/Short day and month names should start with Upper case to allow customization #34698

Closed
borowszky opened this issue Oct 4, 2019 · 4 comments

Comments

@borowszky
Copy link

borowszky commented Oct 4, 2019

What version of Go are you using (go version)?

$ go version
go version go1.12.2  windows/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GOARCH=amd64
set GOBIN=
set GOCACHE=......\AppData\Local\go-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:\Go\pkg\tool\windows_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=.....\AppData\Local\Temp\go-build844154330=/tmp/go-build -gno-record-gcc-switches

What did you do?

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"),
}

}

What did you expect to see?

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", }

What did you see instead?

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", }

@ianlancetaylor ianlancetaylor changed the title go/scr/time: Long/Short day and month names should start with Upper case to allow customization proposal: time: Long/Short day and month names should start with Upper case to allow customization Oct 4, 2019
@gopherbot gopherbot added this to the Proposal milestone Oct 4, 2019
@ianlancetaylor
Copy link
Contributor

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).

@rsc
Copy link
Contributor

rsc commented Nov 13, 2019

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.

@rsc
Copy link
Contributor

rsc commented Nov 20, 2019

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.

@rsc
Copy link
Contributor

rsc commented Nov 27, 2019

No change in consensus, so declining.

@rsc rsc closed this as completed Nov 27, 2019
@golang golang locked and limited conversation to collaborators Nov 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants