如何将所有 react-big-calendar 更改为法语?
How to change all react-big-calendar to French?
我尝试在 BigCalendar
上添加 culture='fr'
,但是,我得到一个错误。
我的代码是:
import moment from "moment";
BigCalendar.momentLocalizer(moment);
export default class Agenda extends Component {
constructor(props){
super(props);
this.state = {
events: [
{
title: 'Calendar 1',
start: new Date(2019, 2, 19, 15, 0, 0), //03:00 PM
end: new Date(2019, 2, 19, 16, 30, 0), //04:30 PM
},
{
title: 'Calendar 2 ',
start: new Date(2019, 2, 20, 12, 30, 0), //08:30 AM
end: new Date(2019, 2, 20, 18, 0, 0), //18:00 PM
},
{
title: 'Calendar 3 ',
start: new Date(2019, 2, 22, 10, 30, 0), //10:30 AM
end: new Date(2019, 2, 22, 19, 0, 0), //07:00 PM
},
{
title: 'Calendar 4 ',
start: new Date(2019, 2, 23, 7, 30, 0), //08:30 AM
end: new Date(2019, 2, 23, 11, 0, 0), //11:00 AM
},
],
}
render() {
return (
<div>
<BigCalendar
selectable
events={this.state.events}
defaultDate={new Date(2019, 2, 19)}
defaultView="week"
culture = 'fr'
style={{ height: "100vh" }}
/>
</div>
)
}
};
当我 运行 它时,我得到:
我该如何解决?
您发布的错误可能是因为您没有将 localizer 作为 props 传递给 BigCalendar。要解决这个问题,您可以尝试分配一个变量
const localizer = BigCalendar.momentLocalizer(moment);
然后将其作为道具传递
<BigCalendar
localizer={localizer}
...
/>
希望对您有所帮助!
参考:http://intljusticemission.github.io/react-big-calendar/examples/index.html#intro
我通过在我的组件上添加 import 'moment/locale/fr';
来解决这个问题。
你可以这样做,我强烈推荐你使用“moment”库
就日期而言,它使事情变得容易得多,您可以翻译成您选择的语言
import React, { Fragment, useState } from 'react'
import { Calendar, momentLocalizer } from 'react-big-calendar'
import "react-big-calendar/lib/css/react-big-calendar.css";
import moment from "moment";
require('moment/locale/es.js')
const localizer = momentLocalizer(moment);
function Citas() {
const [Events, setEvents] = useState([
{
start: moment().toDate(),
end: moment()
.add(1, "days")
.toDate(),
title: "Some title"
}
]);
return (
<Fragment>
<div className="font-weight-bold mb-2 px-3 shadow-sm p-2 bg-light">CITAS </div>
<div className="px-3">mas datos sobre citas
<Calendar
localizer={localizer}
defaultDate={new Date()}
defaultView="month"
events={Events}
style={{ height: "100vh" }}
messages={{
next: "sig",
previous: "ant",
today: "Hoy",
month: "Mes",
week: "Semana",
day: "Día"
}}
/>
</div>
</Fragment>
)
}
export default Citas
我使用西班牙语 react-big-calendar
。
import { Calendar, momentLocalizer } from "react-big-calendar"
import moment from "moment"
import 'moment/locale/es';
//...
const localizer = momentLocalizer(moment)
//...
<DragAndDropCalendar localizer={localizer} /*otherprops*/ />
我尝试在 BigCalendar
上添加 culture='fr'
,但是,我得到一个错误。
我的代码是:
import moment from "moment";
BigCalendar.momentLocalizer(moment);
export default class Agenda extends Component {
constructor(props){
super(props);
this.state = {
events: [
{
title: 'Calendar 1',
start: new Date(2019, 2, 19, 15, 0, 0), //03:00 PM
end: new Date(2019, 2, 19, 16, 30, 0), //04:30 PM
},
{
title: 'Calendar 2 ',
start: new Date(2019, 2, 20, 12, 30, 0), //08:30 AM
end: new Date(2019, 2, 20, 18, 0, 0), //18:00 PM
},
{
title: 'Calendar 3 ',
start: new Date(2019, 2, 22, 10, 30, 0), //10:30 AM
end: new Date(2019, 2, 22, 19, 0, 0), //07:00 PM
},
{
title: 'Calendar 4 ',
start: new Date(2019, 2, 23, 7, 30, 0), //08:30 AM
end: new Date(2019, 2, 23, 11, 0, 0), //11:00 AM
},
],
}
render() {
return (
<div>
<BigCalendar
selectable
events={this.state.events}
defaultDate={new Date(2019, 2, 19)}
defaultView="week"
culture = 'fr'
style={{ height: "100vh" }}
/>
</div>
)
}
};
当我 运行 它时,我得到:
我该如何解决?
您发布的错误可能是因为您没有将 localizer 作为 props 传递给 BigCalendar。要解决这个问题,您可以尝试分配一个变量
const localizer = BigCalendar.momentLocalizer(moment);
然后将其作为道具传递
<BigCalendar
localizer={localizer}
...
/>
希望对您有所帮助!
参考:http://intljusticemission.github.io/react-big-calendar/examples/index.html#intro
我通过在我的组件上添加 import 'moment/locale/fr';
来解决这个问题。
你可以这样做,我强烈推荐你使用“moment”库 就日期而言,它使事情变得容易得多,您可以翻译成您选择的语言
import React, { Fragment, useState } from 'react'
import { Calendar, momentLocalizer } from 'react-big-calendar'
import "react-big-calendar/lib/css/react-big-calendar.css";
import moment from "moment";
require('moment/locale/es.js')
const localizer = momentLocalizer(moment);
function Citas() {
const [Events, setEvents] = useState([
{
start: moment().toDate(),
end: moment()
.add(1, "days")
.toDate(),
title: "Some title"
}
]);
return (
<Fragment>
<div className="font-weight-bold mb-2 px-3 shadow-sm p-2 bg-light">CITAS </div>
<div className="px-3">mas datos sobre citas
<Calendar
localizer={localizer}
defaultDate={new Date()}
defaultView="month"
events={Events}
style={{ height: "100vh" }}
messages={{
next: "sig",
previous: "ant",
today: "Hoy",
month: "Mes",
week: "Semana",
day: "Día"
}}
/>
</div>
</Fragment>
)
}
export default Citas
我使用西班牙语 react-big-calendar
。
import { Calendar, momentLocalizer } from "react-big-calendar"
import moment from "moment"
import 'moment/locale/es';
//...
const localizer = momentLocalizer(moment)
//...
<DragAndDropCalendar localizer={localizer} /*otherprops*/ />