React-datepicker: locale property doesn't work with "pt-BR" locale

Created on 24 Oct 2019  路  4Comments  路  Source: Hacker0x01/react-datepicker

Describe the bug
I'm using locale pt-BR but component still in english (labels and formats)

Screenshots
image

image

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser: Opera
  • Version: 63.0.3368.107

  • OS: Windows 10

  • Browser: Firefox
  • Version: 69.0.3

  • OS: Windows 10

  • Browser: Chrome
  • Version: 77.0.3865.120

Most helpful comment

@Cligor use 'ptBR' instead of 'pt-BR'

import ReactDatePicker,{registerLocale} from 'react-datepicker';
import ptBR from 'date-fns/locale/pt-BR';
registerLocale('ptBR', ptBR);

 <ReactDatePicker
        name='date'
        selected={selected}
        locale="ptBR"

      />

All 4 comments

The same thing, but with 'ru' locale

@Cligor, I made it work for 'ru' locale by installing date-fns as a dependency (maybe it is unnecessary as soon as date-fns is dep of react-datepicker) and importing of the desired local and passing it as locale prop into Datepicker component.

import ru from 'date-fns/locale/ru';

<Datepicker
    selected={value}
    onChange={date => onValueChange(date)}
    showTimeSelect
    showTimeSelectOnly
    timeIntervals={10}
    timeCaption="Time"
    locale={ru}
    dateFormat="hh:mm aa"
/>

@Cligor use 'ptBR' instead of 'pt-BR'

import ReactDatePicker,{registerLocale} from 'react-datepicker';
import ptBR from 'date-fns/locale/pt-BR';
registerLocale('ptBR', ptBR);

 <ReactDatePicker
        name='date'
        selected={selected}
        locale="ptBR"

      />

@ShiiRochi @lucaswx2 Both solutions work. Thanks guys!

Was this page helpful?
0 / 5 - 0 ratings