Coder Social home page Coder Social logo

How to localize? about react-datepicker HOT 3 CLOSED

t0gre avatar t0gre commented on June 21, 2024
How to localize?

from react-datepicker.

Comments (3)

tresko avatar tresko commented on June 21, 2024

Thank you.

You pass the phrases as an object. DayLabelFormat, weekdayLabelFormat, and monthLabelForm, these are functions (callbacks) that take a date as an argument and return a string - formatted label. Below is an example with date-fns, but you can also use a moment or you can format labels by yourself.

Here is an example:`

import {es as locale} from 'date-fns/locale'
import {format} from 'date-fns'

function Test() {
  return (
    <DateRangeInput
      ...otherProps,
      displayFormat={displayFormat}
      phrases={{
        datepickerStartDatePlaceholder: 'Seleccionar',
        datepickerStartDateLabel: 'Fecha de inicio:',
        datepickerEndDatePlaceholder: 'Seleccionar',
        datepickerEndDateLabel: 'Fecha de inicio:',
        resetDates: 'Deshacer',
        startDateAriaLabel: 'Fecha de inicio',
        endDateAriaLabel: 'Fecha de inicio',
        startDatePlaceholder: 'Fecha de inicio',
        endDatePlaceholder: 'Fecha de inicio',
        close: 'Cerca',
      }}
      displayFormat={text('displayFormat', 'MM/dd/yyyy')}
      dayLabelFormat={(date: Date) => format(date, 'dd', {locale})}
      weekdayLabelFormat={(date: Date) => format(date, 'eeeeee', {locale})}
      monthLabelFormat={(date: Date) => format(date, 'MMMM yyyy', {locale})}
    />
  )
}

Here is a list of all possible phrases click

from react-datepicker.

PhilGarb avatar PhilGarb commented on June 21, 2024

Thank you so much :) This worked for me. I guess my problem was more with how date-fns handles localization and less about this library after all.

Are you interested in a pull request which takes your answer and maybe a link and small explanation of a date-fns example to extend the Readme?

from react-datepicker.

tresko avatar tresko commented on June 21, 2024

Yes, of course.

from react-datepicker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.