react-moment where to set moment.locale

≡放荡痞女 提交于 2020-01-21 12:06:51

问题


After reading react-datepicker doc's I have tried changing my date picker language as the doc's instructions:

Globally by calling moment.locale(lang) Picker-specific by providing the locale prop

My question is where to write this setting in a react app.

1- app.js (constructor).

2- date-picker component(constructor).

3-somewhere else...

And how to set it as prop, I have tried :

<DatePicker locale='gr'
      minDate={this.props.minDate}
        selected={this.state.startDate}
        onChange={this.handleChange}
        disabled = {this.props.disabled}
    />;

and it is still showing up as English.

BTW - anyone know what is the language string to Hebrew? thanks.


回答1:


Using this question I was able to figure this so, import langue like:

import 'moment/locale/he';

And for each new moment just set -

moment().locale('he')

It is not really global(one signal setting) for all uses.




回答2:


If you need moment.locale(lang) globally then try react context api (for React v16.3 or greater). For Hebrew locale code is he, I think.



来源:https://stackoverflow.com/questions/51769039/react-moment-where-to-set-moment-locale

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!