-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DatePicker] multi language support #537
Comments
+1 var cultureInfo = {
day: {
name: ['Sunday', 'Monday', ...],
abbr: ['Sun', 'Mon', ...]
},
month: {
name: ['January', 'February', ...],
abbr: ['Jan', 'Feb', ...]
}
};
<DatePicker
hintText="Portrait Dialog"
cultureInfo={cultureInfo}
/> |
+1 |
@mmrtnz @hai-cea How do you guys feel about utilizing http://momentjs.com/ for material-ui's date/time needs? We would be able to extract almost all of the datetime utils and have il8n for 'free'. |
@jkruder +1 |
+1 |
I see this closed but where's the implementation? I not found any help from docs |
@rkmax It's still an open issue. |
+1 |
Thanks @Griffosx. I need get solve some problems with my local dev folder to starting to contribute to mterial-ui |
@hai-cea In April I proposed using momentjs to enhance the date picker. It has i8l support so we could lean on their implementation and just expose some props. What do you think? |
I did something very quickly // src/utils/date-time.js
let moment = require('moment');
moment.locale('es');
module.exports = {
addDays(d, days) {
let newDate = this.clone(d);
newDate.add(days, 'days');
return newDate.toDate();
},
addMonths(d, months) {
let newDate = this.clone(d);
newDate.add(months, 'months');
return newDate.toDate();
},
addYears(d, years) {
let newDate = this.clone(d);
newDate.add(years, 'years');
return newDate.toDate();
},
clone(d) {
return moment(d);
},
cloneAsDate(d) {
let clonedDate = this.clone(d);
return clonedDate.toDate();
},
getDaysInMonth(d) {
let resultDate = this.clone(d);
return resultDate.daysInMonth();
},
getFirstDayOfMonth(d) {
let clonedDate = this.clone(d);
clonedDate.startOf('month');
return clonedDate.toDate();
},
getFullMonth(d) {
let clonedDate = this.clone(d);
return clonedDate.format('MMMM');
},
getShortMonth(d) {
let clonedDate = this.clone(d);
return clonedDate.format('MMM');
},
getDayOfWeek(d) {
let clonedDate = this.clone(d);
return clonedDate.format('dddd');
},
getWeekArray(d) {
let dayArray = [];
let daysInMonth = this.getDaysInMonth(d);
let daysInWeek;
let emptyDays;
let firstDayOfWeek;
let week;
let weekArray = [];
for (let i = 1; i <= daysInMonth; i++) {
dayArray.push(new Date(d.getFullYear(), d.getMonth(), i));
}
while (dayArray.length) {
firstDayOfWeek = dayArray[0].getDay();
daysInWeek = 7 - firstDayOfWeek;
emptyDays = 7 - daysInWeek;
week = dayArray.splice(0, daysInWeek);
for (let i = 0; i < emptyDays; i++) {
week.unshift(null);
}
weekArray.push(week);
}
return weekArray;
},
format(date) {
let m = date.getMonth() + 1;
let d = date.getDate();
let y = date.getFullYear();
return m + '/' + d + '/' + y;
},
isEqualDate(d1, d2) {
return d1 && d2 &&
(d1.getFullYear() === d2.getFullYear()) &&
(d1.getMonth() === d2.getMonth()) &&
(d1.getDate() === d2.getDate());
},
isBeforeDate(d1, d2) {
let date1 = this.cloneAsDate(d1);
let date2 = this.cloneAsDate(d2);
return (date1.getTime() < date2.getTime());
},
isAfterDate(d1, d2) {
let date1 = this.cloneAsDate(d1);
let date2 = this.cloneAsDate(d2);
return (date1.getTime() > date2.getTime());
},
isBetweenDates(dateToCheck, startDate, endDate) {
return (!(this.isBeforeDate(dateToCheck, startDate)) &&
!(this.isAfterDate(dateToCheck, endDate)));
},
monthDiff(d1, d2) {
let m;
m = (d1.getFullYear() - d2.getFullYear()) * 12;
m += d1.getMonth();
m -= d2.getMonth();
return m;
},
yearDiff(d1, d2) {
return ~~(this.monthDiff(d1, d2) / 12);
}
}; |
@jkruder Instead of using The
|
@oliviertassinari I like the idea of using |
I think that the intl polyfill support every browser since they use the data of http://cldr.unicode.org/ then do some massage to produce the output. |
I was proposing to update |
I read through the readme of the polyfill more closely and I believe that it does support Safari (although I did not see anything that explicitly confirms that). In regards to recreating the wheel, there may be some functionality in |
Example usage: <DatePicker
hintText="Fecha final"
container="inline"
DateTimeFormat={ Intl.DateTimeFormat }
locale='es-ES'
mode="landscape" /> |
Hey, I'm using Material UI date picker for reactjs 4 years after this thread, is there multi language support now? |
Hi!
It will be extremely useful to set Days of the Week and Months in different languages (spanish in my case).
I dont think that it should be that hard, the interface should be something like this:
I believe that the value outstands the complexity of implementing this 😄
Thanks!
The text was updated successfully, but these errors were encountered: