Different Locales
Turning this date picker into another locale date picker is as easy as changing the locale
prop. For other features like minimum and maximum dates, just use them as you would normally use:
Using Predefined Locales
For now, there are two predefined locales; en
and fa
. You can use them by passing them to locale
prop as a string.
import React, { useState } from "react";
import "react-modern-calendar-datepicker/lib/DatePicker.css";
import DatePicker from "react-modern-calendar-datepicker";
const App = () => {
const [selectedDay, setSelectedDay] = useState(null);
return (
<DatePicker
value={selectedDay}
onChange={setSelectedDay}
shouldHighlightWeekends
locale="fa" // add this
/>
);
};
export default App;
import React, { useState } from "react";
import "react-modern-calendar-datepicker/lib/DatePicker.css";
import { Calendar } from "react-modern-calendar-datepicker";
const App = () => {
const [selectedDay, setSelectedDay] = useState(null);
return (
<Calendar
value={selectedDay}
onChange={setSelectedDay}
shouldHighlightWeekends
locale="fa" // add this
/>
);
};
export default App;
شیدسچپج
۱
۲
۳
۴
۵
۶
۷
۸
۹
۱۰
۱۱
۱۲
۱۳
۱۴
۱۵
۱۶
۱۷
۱۸
۱۹
۲۰
۲۱
۲۲
۲۳
۲۴
۲۵
۲۶
۲۷
۲۸
۲۹
۳۰
۳۱
Using Custom Locales
If your locale is missing in predefined locales, you can add your own custom locale by passing a locale object to locale
prop. This is an example of default English picker's data:
import React, { useState } from "react";
import "react-modern-calendar-datepicker/lib/DatePicker.css";
import { Calendar } from "react-modern-calendar-datepicker";
const myCustomLocale = {
// months list by order
months: [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December',
],
// week days by order
weekDays: [
{
name: 'Sunday', // used for accessibility
short: 'S', // displayed at the top of days' rows
isWeekend: true, // is it a formal weekend or not?
},
{
name: 'Monday',
short: 'M',
},
{
name: 'Tuesday',
short: 'T',
},
{
name: 'Wednesday',
short: 'W',
},
{
name: 'Thursday',
short: 'T',
},
{
name: 'Friday',
short: 'F',
},
{
name: 'Saturday',
short: 'S',
isWeekend: true,
},
],
// just play around with this number between 0 and 6
weekStartingIndex: 0,
// return a { year: number, month: number, day: number } object
getToday(gregorainTodayObject) {
return gregorainTodayObject;
},
// return a native JavaScript date here
toNativeDate(date) {
return new Date(date.year, date.month - 1, date.day);
},
// return a number for date's month length
getMonthLength(date) {
return new Date(date.year, date.month, 0).getDate();
},
// return a transformed digit to your locale
transformDigit(digit) {
return digit;
},
// texts in the date picker
nextMonth: 'Next Month',
previousMonth: 'Previous Month',
openMonthSelector: 'Open Month Selector',
openYearSelector: 'Open Year Selector',
closeMonthSelector: 'Close Month Selector',
closeYearSelector: 'Close Year Selector',
defaultPlaceholder: 'Select...',
// for input range value
from: 'from',
to: 'to',
// used for input value when multi dates are selected
digitSeparator: ',',
// if your provide -2 for example, year will be 2 digited
yearLetterSkip: 0,
// is your language rtl or ltr?
isRtl: false,
}
const App = () => {
const [selectedDay, setSelectedDay] = useState(null);
return (
<Calendar
value={selectedDay}
onChange={setSelectedDay}
locale={myCustomLocale} // custom locale object
shouldHighlightWeekends
/>
);
};
export default App;
SMTWTFS
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