Jorge.V
Jorge.V

Reputation: 1347

Changing locale for thymeleaf utility objects

I want to use #dates or #calendars to get a list of the elapsed months of the current year. This can be achieved using ${#dates.monthName(date)} and a bit of logic, but the name of the months comes in english, and I need it in spanish.

Is there a way to tell thymeleaf to use one locale or another? I've read it uses the standard Date and Calendar from Java, so maybe some sort of application settings for this classes in spring would work?

Upvotes: 0

Views: 342

Answers (1)

albertofontana
albertofontana

Reputation: 41

You've to use the method monthName(Object target, Locale locale) of Thymeleaf DateUtils. I think something like this should work:

${T(org.thymeleaf.util.DateUtils).monthName(#dates.createNow(), #locale.getDefault())}

Upvotes: 1

Related Questions