timepicker-ui
4.6.0GitHub
timepicker-ui
Guides / Localization

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:

  1. calendar.locale, when set to a valid BCP 47 tag
  2. the lang attribute of <html>
  3. navigator.language
  4. en-US

An invalid tag emits invalid-option. Any Intl locale works.

de-DE
import DatepickerUI from "@pglejzer/datepicker-ui";
import "@pglejzer/datepicker-ui/index.css";
new DatepickerUI("#date", {
calendar: { locale: "de-DE" },
labels: { title: "Datum wählen", confirm: "OK", cancel: "Abbrechen" },
}).create();

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.

ar-EG
<input id="date" dir="rtl" />
import DatepickerUI from "@pglejzer/datepicker-ui";
import "@pglejzer/datepicker-ui/index.css";
new DatepickerUI("#date", {
calendar: { locale: "ar-EG" },
}).create();

Week start

#

calendar.weekStart is "auto", "sunday", "monday" or "saturday". "auto" follows the locale.

index.ts
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
titleModal header supporting text
noDateModal headline while nothing is selected
confirm, cancelConfirm and cancel buttons
today, clearToday and Clear buttons
previousMonth, nextMonthMonth navigation buttons
chooseMonth, chooseYearMonth and year menu buttons
invalidDate, unavailableDateMessages for typed text
rangeStart, rangeEndHeadline placeholders in range mode
multipleSelectedHeadline 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.

index.ts
new DatepickerUI("#date", {
calendar: { mode: "multiple" },
labels: {
multipleSelected: { one: "{count} date", other: "{count} dates" },
},
}).create();
#
Esc