How can i translate a timestamp date

Hello team,

i’m looking for a solution to translate a timestamp

Here is the code from my template

{{time (div (int .Params.dateAdd) 1000)  | dateFormat "2 Jan 2006"  }}

that return a correct date

 14 Sep 2016

but i can’t figure how to change the month

Thx ;p

Hello @jonathanulco,

currently neither Hugo itself nor the Golang’s templating language provide a way to translate timestamps. I guess you’re referring to the name of months in your example.

However, some folks in the community came up with a workaround that should do the trick. The docs provide an example on how to do it with the help of data files. Have a look at the “customize dates” section.

2 Likes

I 've some difficulty to cast a int from the month of the timestamp with Hugo
I 've tried

{{time ((div (int .Params.dateAdd) 1000)) }}
{{$test := (time 1496333001).Unix   }} {{ $test }}
{{(time (div (int .Params.dateAdd) 1000)).Month }}

or with go it’s ok

fmt.Printf("%d", (int((time.Unix(1496332344, 0)).Month())));

I use the above trick to add Croatian names for months, but considering that in Croatian language we have 7 cases the word is changing due to declination, I wonder if someone is familiar with the status of “Go does not yet have support for internationalized locales,” and/or can provide some (simple) workaround?

Maybe having one data file per case… :slight_smile: