Skip to content

Commit ae2a20a

Browse files
committed
Updated README.md
2 parents 2ccb0dc + 820fb50 commit ae2a20a

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ For the internationalization we decided to choose the library [Format.js](https:
494494
- Import your `.json` file/s on the `src/utils/index.js` and add them to `messages`.
495495
- Place your icon/s for your language/s on `src/assets`.
496496
- Import your icon/s and add it/them to `flags` on `src/utils/index.js`.
497-
- Import your language/s from the `date-fns` library and then call **registerLocale** and pass your import to make sure **DatePicker** can use your language.
497+
- Import your language/s from the `date-fns` library and then call **registerLocale** and pass your import to make sure **DatePicker** can use your language. Then put your language format on **dateFormat** for the **DatePicker**.
498498
499499
### Creating your translation file
500500
@@ -567,6 +567,7 @@ const date = Date.now();
567567
568568
- Import your language from `date-fns/locale/[yourlanguage]`
569569
- Add another **registerLocale** with your language as the first parameter and the import from `date-fns` as second parameter.
570+
- Place your language with its date format on **dateFormat**.
570571
571572
## Contributors
572573

src/components/DatePicker/index.jsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ import './DatePicker.scss';
1111
registerLocale('en', en);
1212
registerLocale('es', es);
1313

14+
const dateFormat = locale => {
15+
switch (locale) {
16+
case 'en':
17+
return 'MM-dd-yy';
18+
case 'es':
19+
return 'dd/MM/yy';
20+
default:
21+
return 'MM-dd-yy';
22+
}
23+
};
24+
1425
const DatePickerStyled = ({ name, date, setState }) => {
1526
const onDateChangedHandler = value =>
1627
setState(prevState => ({
@@ -25,12 +36,10 @@ const DatePickerStyled = ({ name, date, setState }) => {
2536
shallowEqual
2637
);
2738

28-
const dateFormat = locale === 'en' ? 'MM-dd-yy' : 'dd/MM/yy';
29-
3039
return (
3140
<DatePicker
3241
locale={locale}
33-
dateFormat={dateFormat}
42+
dateFormat={dateFormat(locale)}
3443
selected={date}
3544
onChange={onDateChangedHandler}
3645
/>

0 commit comments

Comments
 (0)