Matthis
(Matthis Rouch)
February 23, 2017, 12:41pm
#1
Hi, I would like to set the locale for the Calendar ui component, so that days ‘Monday’ ‘Tuesday’, etc… are shown in another language.
The Vaadin calendar component has a setlocale method which can do this - how could I access this method for the Calendar Cuba component?
If this is not possible using the native Cuba component, would there be another way to change the days and months language easily?
Thanks,
artamonov
(Yuriy Artamonov)
March 1, 2017, 1:38pm
#2
Hi,
Currently we do not have API that can solve your task, but you can unwrap CUBA component and set Locale to Vaadin calendar instance:
@Inject
protected Calendar calendar;
...
// get Vaadin calendar from CUBA component
CubaCalendar vCalendar = calendar.unwrap(CubaCalendar.class);
vCalendar.setMonthNamesShort(null); // disable automatic month names
vCalendar.setDayNamesShort(null); // disable automatic day names
vCalendar.setLocale(Locale.CANADA);
1 Like
Matthis
(Matthis Rouch)
March 1, 2017, 1:53pm
#3
Hi Yuriy,
Thank you for your answer and sample code!
This is an easy way to achieve what I want to do.
Best regards
iskandarov
(Rostislav Iskandarov)
April 25, 2017, 11:47am
#4
Hi,
Since the platform version 6.5.0, the following methods are available for the Calendar component.
Map<DayOfWeek, String> getDayNames();
void setDayNames(Map<DayOfWeek, String> dayNames);
Map<Month, String> getMonthNames();
void setMonthNames(Map<Month, String> monthNames);
So you can customize days and months programmatically.
public class EventBrowse extends AbstractLookup {
@Inject
private Calendar eventsCalendar;
@Override
public void init(Map<String, Object> params) {
Map<DayOfWeek, String> days = eventsCalendar.getDayNames();
days.put(DayOfWeek.MONDAY, "Primidi");
days.put(DayOfWeek.TUESDAY, "Duodi");
days.put(DayOfWeek.WEDNESDAY, "Tridi");
days.put(DayOfWeek.THURSDAY, "Quardidi");
days.put(DayOfWeek.FRIDAY, "Quintidi");
days.put(DayOfWeek.SATURDAY, "Sextidi");
days.put(DayOfWeek.SUNDAY, "Septidi");
eventsCalendar.setDayNames(days);
super.init(params);
}
}
Matthis
(Matthis Rouch)
April 25, 2017, 2:23pm
#5
Good to know! Thanks for implementing and following up!!
system
(system)
April 25, 2017, 2:23pm
#6
eddy4016
(Eddy Chan)
December 1, 2017, 7:39am
#7
I think there is a bug with the allocation of Days. I have checked this in my own project and a sample project and happens in both. It appears to be doing this:
Sunday = Monday
Monday = Tuesday
etc.