Hey there,
I was wondering, is it possible to use a different locale when using time.Format? I would like to display the dates in my application in another language than English.
Or should I just translate them myself for now?
Cheers!
评论:
tzmg:
SerialMiller:As far as I know this is not (yet) possible in the standard time library. A quick google gave me some hints about it being on the Roadmap but I can't find anything more on the subject. I did find a package https://github.com/mattbaird/go-i18n-formats but it doesn't look complete to me. Other i18n packages that I found seem to be only about translations tho...
For now I would work with template functions to handle it...
jeffrallen:Yeah, this is exactly what I've found :). Hoped someone did have another answer though. Going to solve it like this for now :).
SerialMiller:If the only thing about the locale you care about is the words for days of the week and months it seems like you could format to English then use string replacement to fix the words. It's a cheap trick, but for European languages it would work. The firmato string you use will have the other important part of the locale in it, i.e. the day/month/year order.
dchapes:Definetly, this is now how I've done it. Using a simple map[time.Month]string. Just was wondering if there was a simpeler way though :). Or if it was actually part of the standard Go packages, couldn't find it. Thanks for your input :).
SerialMiller:I first read this as "to use a different location when using
time.Format
" and was all set to link totime.LoadLocation
andtime.In
before I noticed it was "locale" :).Sadly the standard packages don't provide anything in the way of internationalization support for anything. :( I image if/when the Go project does any of this it would be added to the sub-repo repositories (like the
golang.org/x/text
package).
Most of my search queries in fact ended up at Location instead of locale, indeed :D.
Can imagine the confusion.
