react-moment在哪里设置moment.locale [英] react-moment where to set moment.locale

查看:884
本文介绍了react-moment在哪里设置moment.locale的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读了react-datepicker 文档后,我尝试将日期选择器语言更改为doc的说明:

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

在全球范围内通过调用moment.locale(lang)Picker特定于 语言环境道具

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(构造函数).

1- app.js (constructor).

2-日期选择器组件(构造函数).

2- date-picker component(constructor).

3处其他地方...

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}
    />;

,它仍然显示为英语.

顺便说一句-有人知道希伯来语的语言是什么吗?谢谢.

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

推荐答案

使用问题,我能够弄清楚这一点,因此可以导入语言:

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

import 'moment/locale/he';

然后为每个新的moment设置-

moment().locale('he')

它并不是真正适用于所有用途的全局设置(一个信号设置).

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

这篇关于react-moment在哪里设置moment.locale的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆