简体   繁体   English

Airbnb用非英语语言环境反应日期日历

[英]Airbnb react-dates calendar with non-English locale

I am trying to use airbnb react-dates with non-English locale (Persian) and everything is working fine, except for the first day of the month.我正在尝试使用带有非英语语言环境(波斯语)的airbnb react-dates并且一切正常,除了当月的第一天。

The months do not start from the first day in Persian (Jalaali) calendar to the 30th day, they start from the 10th day of the month and continue to the 10th day of the next month.月份不是从波斯 (Jalaali) 历法的第一天开始到第 30 天,而是从当月的第 10 天开始并持续到下个月的第 10 天。

This problem even exists in their example .这个问题甚至存在于他们的例子中 I was wondering if there is any way to deal with this issue.我想知道是否有任何方法可以解决这个问题。

I have been dealing with this issue in a project,this problem is currently an open issue in airbnb react-dates.我一直在一个项目中处理这个问题,这个问题目前是airbnb react-dates中的一个未解决的问题。 In order to solve this, I have forked the original project so that it works with jalali moment and the months start from the correct day,the link to the github and npm repositories are:为了解决这个问题,我分叉了原始项目,以便它与 jalali 时刻一起工作,月份从正确的日期开始,github 和 npm 存储库的链接是:

how to use:如何使用:

  • import momentJalali from 'moment-jalaali'

  • in the constructor of the component in which you want to use datepicker set the appropriate locale :在要使用 datepicker 的组件的构造函数中设置适当的语言环境:

    momentJalali.locale('fa')

  • import the datepicker from the forked repository:从分叉存储库导入日期选择器:

import {SingleDatePicker,DateRangePicker} from "react-dates-jalali";

  • in render section use the singdatepicker in the following way:在渲染部分以下列方式使用 singdatepicker:

     <SingleDatePicker date={date} //momentDate if you have not set this property,it automatically sets to today focused={this.onFocusChange}//function change focused:open-close onFocusChange={.../function} showClearDate={true} required={true} isRTL={true} monthFormat={monthFormat}//for persian:'jMMMM jYYYY', for english :'MMMM YYYY' onDateChange={this.onDateChange}//function set your date Change />
  • in render section use the daterangepicker in the following way:在渲染部分,按以下方式使用 daterangepicker:

     <DateRangePicker startDate={startDate} //moment startDate if you have not set this property,it automatically sets to today endDate={endDate} //moment endDate onFocusChange={.../function} required={true} isRTL={true} onDatesChange={this.onDatesChange}//function set startDate and endDate focusedInput={focusedInput}//similar to airbnb api-open\\close showClearDates={true} monthFormat={monthFormat}//for persian:'jMMMM jYYYY', for english :'MMMM YYYY' />

Needless to say,this repositories support all other airbnb react-dates apis which are not mentioned here.不用说,此存储库支持此处未提及的所有其他 airbnb react-dates api。

You can also this repository if your site is multilingual and you can change the locale and month format whenever you want.如果您的站点是多语言的,并且您可以随时更改区域设置和月份格式,您也可以使用此存储库。

I just imported moment and locale like this and it worked:我只是像这样导入了momentlocale并且它起作用了:

import moment from 'moment';
import 'moment/locale/pt-br';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM