Date Picker Localization and RTL
@pglejzer/datepicker-ui, the companion of timepicker-ui, takes month and weekday names from Intl and every other text from the labels group.
Locale
#calendar.locale is a BCP 47 tag. Month and weekday names, the first day of the week, the auto date format and the digits all come from Intl for that locale. The locale is resolved in this order:
- calendar.locale, when set to a valid BCP 47 tag
- the lang attribute of <html>
- navigator.language
- en-US
An invalid tag emits invalid-option. Any Intl locale works.
Digits and right-to-left
#Digits are shown in the numerals of the locale, and calendar.locale sets the language and the names. The layout is mirrored only when the input has a right-to-left direction, for example dir="rtl" on the input or on <html>. The container then gets the class dp-ui__container--rtl, and in the day grid the Left and Right arrow keys swap.
Week start
#calendar.weekStart is "auto", "sunday", "monday" or "saturday". "auto" follows the locale.
new DatepickerUI("#date", {calendar: { locale: "en-US", weekStart: "monday" },}).create();
Labels
#Every visible and assistive text is a label, the screen-reader ones included. Month and weekday names are not labels. The table summarizes the main ones. The full table with every key and default is on the Options page.
| labels.* | Used for |
|---|---|
| title | Modal header supporting text |
| noDate | Modal headline while nothing is selected |
| confirm, cancel | Confirm and cancel buttons |
| today, clear | Today and Clear buttons |
| previousMonth, nextMonth | Month navigation buttons |
| chooseMonth, chooseYear | Month and year menu buttons |
| invalidDate, unavailableDate | Messages for typed text |
| rangeStart, rangeEnd | Headline placeholders in range mode |
| multipleSelected | Headline in multiple mode, a PluralLabel |
Plural labels
#multipleSelected is a PluralLabel: a string, or an object keyed by Intl.PluralRules categories. {count} is replaced by the number of dates.
new DatepickerUI("#date", {calendar: { mode: "multiple" },labels: {multipleSelected: { one: "{count} date", other: "{count} dates" },},}).create();