Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react-moment where to set moment.locale

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.

like image 394
Itsik Mauyhas Avatar asked Aug 09 '18 14:08

Itsik Mauyhas


People also ask

How do I change my locale in moments?

updateLocale(localeName, config) to change an existing locale. moment. defineLocale(localeName, config) should only be used for creating a new locale.

How do I change locale globally moments?

To change active locales, simply call moment. locale with the key of a loaded locale. As of 2.21. 0, Moment will console.

How do I import a locale moment?

moment. Loading locales in NodeJS is super easy. If there is a locale file in moment/locale/ named after that key, import it first, then call moment. locale to load it. To save the step of loading individual locales (i.e. just load them all), import the moment/min/moment-with-locales module instead.

What is Moment () in react?

For this, we'll be using a library called moment js. A lightweight JavaScript date library for parsing, validating, manipulating, and formatting dates.


1 Answers

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.

moment doc

like image 184
Itsik Mauyhas Avatar answered Sep 21 '22 15:09

Itsik Mauyhas