Browse project documentation

Calendars, language, digits, and RTL

Intl Datepickerv0.4.2View sourceEnglish / Persian

Configure the calendar independently from locale and translate the interface labels.

Calendar and locale are separate

calendar chooses the calendar used for selection and arithmetic. It defaults to gregory, regardless of locale. locale chooses date names, display conventions, default digits, week conventions, and direction. Its default is the document’s lang, then the browser language, with en-US as the environment fallback.

Calendar identifierCalendar systemOptional calendar module
gregoryGregorianIncluded
persianPersian / Solar Hijripersian
islamic, islamic-umalquraUmm al-Quraislamic
islamic-civilCivil Islamicislamic
islamic-tblaTabular Islamicislamic
hebrewHebrewhebrew
buddhistBuddhistbuddhist
japaneseJapanese erasjapanese
indianIndian nationalindian
ethiopic, ethioaaEthiopic / Amete Alemethiopic
copticCopticcoptic
rocMinguo / Taiwanroc

Use intl-datepicker/calendars/<module> from the last column. These are 14 accepted identifiers, including aliases and variants. The islamic alias uses Umm al-Qura for both arithmetic and formatting. Persian calculations follow the dependency’s calendar implementation; the tests verify that Esfand 30, 1403 is 2025-03-20.

Persian calendar with Persian labels

import 'intl-datepicker/calendars/persian';
import 'intl-datepicker/labels/fa';
import 'intl-datepicker';
<label for="persian-date">تاریخ</label>
<intl-datepicker id="persian-date" calendar="persian" locale="fa-IR"
  value="2024-03-20" allow-input></intl-datepicker>

The selected calendar date is { year: 1403, month: 1, day: 1 }. The machine value is 2024-03-20; the input normally displays ۱۴۰۳/۰۱/۰۱. Exact localized punctuation and spacing depend on the browser’s Intl data. This example imports both the calendar and interface translation: date-name localization alone does not translate buttons or validation messages.

Digits and direction

Set numerals="latn" for Latin digits in a Persian interface, or another supported numbering-system identifier such as arab. This changes display, not the ASCII machine value.

The component detects RTL from locale and sets its own dir="rtl"; horizontal keyboard movement follows that direction. Setting an unrelated ancestor’s dir does not change the calendar’s locale or keyboard rules. Configure locale explicitly when direction matters.

first-day-of-week accepts 0–6 (Sunday is 0) or sun through sat. Weekends come from locale week information with internal fallbacks. Use explicit disabled-days-of-week when business rules must not depend on runtime locale data. See constraints.

Locale labels

English is always available. Import /labels/fa, /labels/ar, or /labels/he for Persian, Arabic, or Hebrew. Resolution is English defaults, then registered language defaults, then your overrides. The language prefix is used (fa-IR uses fa). Other languages keep English interface labels until you supply overrides.

import 'intl-datepicker';

const picker = document.querySelector('intl-datepicker');
picker.labels = {
  today: 'Current day',
  dateTooEarly: 'Choose {date} or later',
  nights: { one: '{n} night', other: '{n} nights' },
};

A labels attribute accepts the same object as JSON. Property overrides take precedence over attribute overrides per key. Assign a new object to update it; mutating the returned object is not an update API. labels reads the resolved strings. Empty override strings are ignored.

KeysPurpose and placeholders
today, clear, clearDateFooter and input clear controls
datePicker, rangePresets, calendarNavigationAccessible region names
monthSelection, yearSelectionPicker view names
previousMonth, nextMonth, previousDecade, nextDecadeNavigation; year pages contain 20 years despite the key name
selectMonth, selectYear, weekNumberHeader controls and week column
selected, rangeStart, rangeEndState appended to accessible day names
rangeSelectedCompleted range announcement: {start}, {end}
formatHint, invalidDateTyped input: {format}, {example}
dateUnavailable, pleaseSelectDateUnavailable or required date
dateTooEarly, dateTooLateBound errors: {date}
rangeTooShort, rangeTooLongLength errors: {nights}
rangeUnavailable, rangeIncompleteUnavailable range or missing end
minNightsHint, maxNightsHintPending range guidance: {nights}
nightsString with {n}, or plural forms with a required other form

Plural categories use Intl.PluralRules; {n} uses the selected numerals. See IntlDatepickerLabels and PluralLabel in the type reference.

Switch calendars while retaining the selected day

Use this browser module with the Persian example above:

import 'intl-datepicker/calendars/persian';
import 'intl-datepicker/labels/fa';
import 'intl-datepicker';

const picker = document.querySelector('intl-datepicker');
picker.setValue('2024-03-20');
picker.setAttribute('calendar', 'gregory');
picker.setAttribute('locale', 'en-GB');
console.log(picker.value); // 2024-03-20
picker.setAttribute('calendar', 'persian');
picker.setAttribute('locale', 'fa-IR');
console.log(picker.getValue().calendar); // { year: 1403, month: 1, day: 1 }

For date, the underlying day is retained. Calendar/locale attribute changes do not emit intl-change; read the value after the change if your application needs it. Month/year switching selects the new calendar period containing the previous period’s first day, so its serialized value and bounds can change. A week can also change boundaries when its week convention changes.

Search documentation

Search across all projects. Close this window to return to your guide.

Tab to navigate · Enter to openEsc to close