gpt4 book ai didi

javascript - Airbnb react-dates calendar with non-English locale

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:54:34 26 4
gpt4 key购买 nike

我正在尝试使用 airbnb react-dates使用非英语语言环境(波斯语)并且一切正常,除了本月的第一天。

月份不是从波斯(Jalaali)日历的第一天开始到第 30 天,而是从该月的第 10 天开始,一直持续到下个月的第 10 天。

这个问题甚至存在于他们的example .我想知道有没有什么办法可以解决这个问题。

最佳答案

我一直在一个项目中处理这个问题,这个问题目前是 airbnb react-dates 中的一个开放问题。为了解决这个问题,我 fork 了原始项目,以便它与 jalali moment 一起工作,月份从正确的日期开始,github 和 npm 存储库的链接是:

使用方法:

  • 从 'moment-jalaali' 导入 momentJalali

  • 在要使用日期选择器的组件的构造函数中设置适当的语言环境:

    momentJalali.locale('fa')

  • 从 fork 的存储库导入日期选择器:

从“react-dates-jalali”导入 {SingleDatePicker,DateRangePicker};

  • 在渲染部分按以下方式使用 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
    />
  • 在渲染部分按以下方式使用 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'
    />

不用说,此存储库支持此处未提及的所有其他 airbnb react-dates api。

如果您的网站是多语言的,您也可以使用此存储库,并且您可以随时更改语言环境和月份格式。

关于javascript - Airbnb react-dates calendar with non-English locale,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48595519/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com