How to change the language of flatpickr?

1

I have a date field in my view that is as follows:

<input class="flatpickr flatpickr-input active_es" type="text" placeholder="Select Date.." readonly="readonly">

and a javascript where I use Flatpickr:

function form__date_register() {
    flatpickr('.js--input--date_register', {
      minDate: '1920-01-01',        
      locale: 'es',     
    }); 
}

but I can not find a way for the calendar to be in Spanish and not in English. I hope and someone can help me thanks.

    
asked by Jasi Enriquez 31.05.2018 в 02:08
source

1 answer

1

You only add the following information about the locale configuration (local) to your jquery:

function form__date_register() {
    flatpickr('.js--input--date_register', {
      minDate: '1920-01-01',  
      locale: {
        firstDayOfWeek: 1,
        weekdays: {
          shorthand: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa'],
          longhand: ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'],         
        }, 
        months: {
          shorthand: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Оct', 'Nov', 'Dic'],
          longhand: ['Enero', 'Febreo', 'Мarzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'],
        },
      },
    }); 
}

I recommend you to place the parameters as a separate function (example flatParameters() ) in your function file js to which you can access globally. In this way you avoid repeating code because you would only call each time you use the calendar to function flatParameters() to set in language. This way you keep the principle DRY (Do not Repeat Yourself) that allows you to maintain good programming practices.

I hope it helps. Greetings!

    
answered by 31.05.2018 / 02:30
source