Skip to content

Commit dc79344

Browse files
javier-godoypaodb
authored andcommitted
feat(demo): add i18n demo
1 parent 762d609 commit dc79344

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*-
2+
* #%L
3+
* Year Month Calendar Add-on
4+
* %%
5+
* Copyright (C) 2021 - 2024 Flowing Code
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package com.flowingcode.addons.ycalendar;
21+
22+
import com.flowingcode.vaadin.addons.demo.DemoSource;
23+
import com.vaadin.flow.component.datepicker.DatePicker.DatePickerI18n;
24+
import com.vaadin.flow.component.dependency.CssImport;
25+
import com.vaadin.flow.component.html.Div;
26+
import com.vaadin.flow.router.PageTitle;
27+
import com.vaadin.flow.router.Route;
28+
import java.text.DateFormatSymbols;
29+
import java.time.DayOfWeek;
30+
import java.time.temporal.WeekFields;
31+
import java.util.List;
32+
import java.util.Locale;
33+
34+
@CssImport(value = "./styles/test_year-month-calendar.css", themeFor = "vaadin-month-calendar")
35+
@PageTitle("i18n")
36+
@DemoSource
37+
@Route(value = "year-month-calendar/year-i18n", layout = YearMonthCalendarDemoView.class)
38+
public class YearI18NDemo extends Div {
39+
40+
public YearI18NDemo() {
41+
42+
Locale locale = Locale.GERMAN;
43+
44+
DatePickerI18n i18n = new DatePickerI18n();
45+
DateFormatSymbols dfs = DateFormatSymbols.getInstance(locale);
46+
i18n.setMonthNames(List.of(dfs.getMonths()));
47+
i18n.setWeekdays(List.of(dfs.getWeekdays()).stream().skip(1).toList());
48+
i18n.setWeekdaysShort(List.of(dfs.getShortWeekdays()).stream().skip(1).toList());
49+
50+
DayOfWeek firstDayOfWeek = WeekFields.of(locale).getFirstDayOfWeek();
51+
i18n.setFirstDayOfWeek(firstDayOfWeek.getValue() % 7);
52+
53+
YearCalendar calendar = new YearCalendar();
54+
// #if vaadin eq 0
55+
calendar.setClassNameGenerator(date -> {
56+
if (date.getDayOfWeek() == DayOfWeek.SATURDAY || date.getDayOfWeek() == DayOfWeek.SUNDAY) {
57+
return "weekend";
58+
}
59+
return null;
60+
});
61+
// #endif
62+
calendar.setI18n(i18n);
63+
add(calendar);
64+
}
65+
66+
}

src/test/java/com/flowingcode/addons/ycalendar/YearMonthCalendarDemoView.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* #%L
33
* Year Month Calendar Add-on
44
* %%
5-
* Copyright (C) 2021 - 2023 Flowing Code
5+
* Copyright (C) 2021 - 2024 Flowing Code
66
* %%
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
@@ -36,6 +36,7 @@ public class YearMonthCalendarDemoView extends TabbedDemo {
3636

3737
public YearMonthCalendarDemoView() {
3838
addDemo(YearDemo.class);
39+
addDemo(YearI18NDemo.class);
3940
addDemo(YearReadonlyDemo.class);
4041
addDemo(MonthDemo.class);
4142
addDemo(InlineDatePickerDemo.class);

0 commit comments

Comments
 (0)