Vaadin日期选择器翻译的月份



是否有办法使日期选择器以默认英语以外的其他语言显示月份?

例如,在德语/DE中设置它以显示六月为Juni ?

可以设置DatePicker的大小asetI18n(DatePicker.DatePickerI18n)值。例如

def datePicker = new DatePicker().tap {
setI18n(new DatePicker.DatePickerI18n().tap {
def locale = Locale.GERMAN
// date formats
setDateFormats(
DateTimeFormatterBuilder.getLocalizedDateTimePattern(
FormatStyle.MEDIUM,
null,
IsoChronology.INSTANCE,
locale
).replace('y', 'yyyy'),
// this would be useful in theory, but is not in practice, because the first format always wins
DateTimeFormatterBuilder.getLocalizedDateTimePattern(
FormatStyle.SHORT,
null,
IsoChronology.INSTANCE,
locale
)
)
// days
def daysOfWeek = [DayOfWeek.SUNDAY] + DayOfWeek.values().toList() // sunday first, because ISO is a joke for some
setWeekdays(daysOfWeek*.getDisplayName(TextStyle.FULL, locale))
setWeekdaysShort(daysOfWeek*.getDisplayName(TextStyle.SHORT, locale))
setFirstDayOfWeek(WeekFields.of(locale).firstDayOfWeek.value % 7) // this works because, because value is + 1
// months
setMonthNames(Month.values()*.getDisplayName(TextStyle.FULL, locale))
// words (use your translation backend here)
setWeek("Woche")
setToday("Heute")
setCancel("Abbrechen")
})
addValueChangeListener{
Notification.show(it.value.toString())
}
}

嗯,有趣的是,我们的文档中没有关于这个的代码示例。我希望API文档现在已经足够了:

Java: https://vaadin.com/api/platform/23.1.0/com/vaadin/flow/component/datepicker/DatePicker.html getI18n ()

打印稿:https://cdn.vaadin.com/vaadin-web-components/23.1.0//元素/vaadin-date-picker # property-i18n

这是我的客户日期选择器:

package com.xyz.NoteService.component;
import com.vaadin.flow.component.datepicker.DatePicker;
import java.util.Arrays;
import java.util.Locale;
public class CustomerDatePicker extends DatePicker {
public CustomerDatePicker(String label) {
super.setLabel(label);
super.setLocale(new Locale("de"));
super.setI18n(
new DatePickerI18n().setWeek("Woche").setCalendar("Kalender")
.setClear("Löschen").setToday("Heute")
.setCancel("Abbrechen").setFirstDayOfWeek(1)
.setMonthNames(Arrays.asList("Januar", "Februar",
"März", "April", "Mai", "Juni",
"Juli", "August", "September", "Oktober",
"November", "Dezember")).setWeekdays(
Arrays.asList("Sonntag", "Montag", "Dienstag",
"Mittwoch", "Donnerstag", "Freitag",
"Samstag")).setWeekdaysShort(
Arrays.asList("So", "Mo", "Di", "Mi", "Do", "Fr",
"Sa")));
}
}

相关内容

  • 没有找到相关文章

最新更新