Using DayPicker

Localization

Localization Props

Change the Locale

To change the locale, pass to the locale prop a date-fns Locale object.

For example, to localize the calendar in Spanish, import the es locale object from date-fns and pass it to the component.

import { es } from "date-fns/locale";
// ...
<DayPicker locale={es} />;
marzo 2024
lumamijuvido
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

Override the First Day of the Week

Use weekStartsOn to override the first day of the week.

<DayPicker weekStartsOn={0} />
marzo 2024
dolumamijuvi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

Set the First Week of the Year

To override the date in the first week of the year, use firstWeekContainsDate. Use this prop to change the week number calculation according to date-fns getWeek function.

<DayPicker firstWeekContainsDate={1} showWeekNumber />
December 2020
#SaSuMoTuWeThFr
W49
1
2
3
4
W50
5
6
7
8
9
10
11
W51
12
13
14
15
16
17
18
W52
19
20
21
22
23
24
25
W1
26
27
28
29
30
31

Switch to ISO Week Dates

DayPicker uses date-fns getWeek to calculate the week number. By default, the week starts on Sunday and the first week of the year is the one that contains January 1st. Use ISOWeek to switch using ISO Week Dates instead of the locale setting.

<DayPicker ISOWeek showWeekNumber />
March 2024
#MoTuWeThFrSaSu
9
1
2
3
10
4
5
6
7
8
9
10
11
11
12
13
14
15
16
17
12
18
19
20
21
22
23
24
13
25
26
27
28
29
30
31

Translate ARIA labels

Use the labels prop to translate the labels used for ARIA.

TODO: This section is still a draft.

Switch the Text Direction

To add right-to-left text direction, set the dir prop to rtl.

import { arSA } from "date-fns/locale";
<DayPicker locale={es} />;
مارس 2024
أحداثنينثلاثاءأربعاءخميسجمعةسبت
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

Change the Numbering System

Use formatters to change the numbering system used in the calendar.

For example, to switch to hindu-arabic using toLocaleString:

import { DayPicker, Formatters } from "react-day-picker";
 
import { format } from "date-fns/format";
import { arSA } from "date-fns/locale";
 
const NU_LOCALE = "ar-u-nu-arab";
 
const formatDay: Formatters["formatDay"] = (day) =>
  day.getDate().toLocaleString(NU_LOCALE);
 
const formatWeekNumber: Formatters["formatWeekNumber"] = (weekNumber) => {
  return weekNumber.toLocaleString(NU_LOCALE);
};
 
const formatMonthCaption: Formatters["formatMonthCaption"] = (
  date,
  options,
) => {
  const y = date.getFullYear().toLocaleString(NU_LOCALE);
  const m = format(date, "LLLL", { locale: options?.locale });
  return `${m} ${y}`;
};
 
export function NumberingSystem() {
  return (
    <DayPicker
      locale={arSA}
      dir="rtl"
      showWeekNumber
      formatters={{ formatDay, formatMonthCaption, formatWeekNumber }}
    />
  );
}
مارس ٢٬٠٢٤
#أحداثنينثلاثاءأربعاءخميسجمعةسبت
٩
١
٢
١٠
٣
٤
٥
٦
٧
٨
٩
١١
١٠
١١
١٢
١٣
١٤
١٥
١٦
١٢
١٧
١٨
١٩
٢٠
٢١
٢٢
٢٣
١٣
٢٤
٢٥
٢٦
٢٧
٢٨
٢٩
٣٠
١٤
٣١