Skip to content

Commit ac0aad9

Browse files
javier-godoypaodb
authored andcommitted
feat: add i18n support to InlineDatePicker
Close #82
1 parent 574f1cf commit ac0aad9

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>org.vaadin.addons.flowingcode</groupId>
66
<artifactId>year-month-calendar</artifactId>
7-
<version>4.2.2-SNAPSHOT</version>
7+
<version>4.3.0-SNAPSHOT</version>
88
<name>Year Month Calendar Add-on</name>
99
<description>Year Month Calendar Add-on for Vaadin Flow</description>
1010

src/main/java/com/flowingcode/addons/ycalendar/InlineDatePicker.java

Lines changed: 14 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.
@@ -23,10 +23,13 @@
2323
import com.vaadin.flow.component.HasSize;
2424
import com.vaadin.flow.component.HasTheme;
2525
import com.vaadin.flow.component.Tag;
26+
import com.vaadin.flow.component.datepicker.DatePicker.DatePickerI18n;
2627
import com.vaadin.flow.component.dependency.JsModule;
2728
import com.vaadin.flow.component.dependency.Uses;
2829
import com.vaadin.flow.function.SerializableFunction;
30+
import com.vaadin.flow.internal.JsonSerializer;
2931
import java.time.LocalDate;
32+
import java.util.Objects;
3033
import java.util.Optional;
3134

3235
@SuppressWarnings("serial")
@@ -72,4 +75,14 @@ public boolean isWeekNumbersVisible() {
7275
return getElement().getProperty("showWeekNumbers", false);
7376
}
7477

78+
/**
79+
* Sets the i18n object.
80+
*
81+
* @param i18n the {@code DatepickerI18n} object used to initialize i18n
82+
*/
83+
public void setI18n(DatePickerI18n i18n) {
84+
Objects.requireNonNull(i18n, "The I18N properties object should not be null");
85+
getElement().setPropertyJson("i18n", JsonSerializer.toJson(i18n));
86+
}
87+
7588
}

src/main/resources/META-INF/frontend/fc-inline-date-picker/fc-inline-date-picker.js

Lines changed: 5 additions & 3 deletions
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.
@@ -54,8 +54,10 @@ export class InlineDatePicker extends LitElement {
5454
this.displayDate = this.displayDate || new Date();
5555
}
5656
if (changedProperties.has('i18n') && this.i18n) {
57-
this.shadowRoot.querySelector("fc-year-month-field").i18n=this.i18n;
58-
this.shadowRoot.querySelector("fc-month-calendar").i18n=this.i18n;
57+
[
58+
this.shadowRoot.querySelector("fc-year-month-field"),
59+
this.shadowRoot.querySelector("fc-month-calendar")
60+
].forEach(e=>{if (e) e.i18n=this.i18n;});
5961
}
6062
}
6163

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
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.
99
* You may obtain a copy of the License at
10-
*
10+
*
1111
* http://www.apache.org/licenses/LICENSE-2.0
12-
*
12+
*
1313
* Unless required by applicable law or agreed to in writing, software
1414
* distributed under the License is distributed on an "AS IS" BASIS,
1515
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -34,6 +34,9 @@ public class InlineDatePickerDemo extends Div {
3434
public InlineDatePickerDemo() {
3535

3636
InlineDatePicker field = new InlineDatePicker();
37+
// #if vaadin eq 0
38+
add(new LocaleSelector(field::setI18n));
39+
// #endif
3740

3841
field.addValueChangeListener(ev->{
3942
Notification.show(Objects.toString(ev.getValue()));

0 commit comments

Comments
 (0)