27

I am using the Bootstrap Date Range Picker provided and explained In this page I added all the library using the cdn, I mean this:

<script type="text/javascript" src="//cdn.jsdelivr.net/jquery/1/jquery.min.js"></script>
<script type="text/javascript" src="//cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/bootstrap/latest/css/bootstrap.css" />
<script type="text/javascript" src="//cdn.jsdelivr.net/bootstrap.daterangepicker/2/daterangepicker.js"></script>
<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/bootstrap.daterangepicker/2/daterangepicker.css" />

But the thing is that I need all in spanish and I don´t see a piece of code to configurate it. How should I do it?

davidkonrad
  • 83,997
  • 17
  • 205
  • 265
Sredny M Casanova
  • 4,735
  • 21
  • 70
  • 115

5 Answers5

67

Include the locale option and edit the appropriate strings, like fromLabel or December :

$('#datePicker').daterangepicker({
    "locale": {
        "format": "MM/DD/YYYY",
        "separator": " - ",
        "applyLabel": "Apply",
        "cancelLabel": "Cancel",
        "fromLabel": "From",
        "toLabel": "To",
        "customRangeLabel": "Custom",
        "daysOfWeek": [
            "Su",
            "Mo",
            "Tu",
            "We",
            "Th",
            "Fr",
            "Sa"
        ],
        "monthNames": [
            "January",
            "February",
            "March",
            "April",
            "May",
            "June",
            "July",
            "August",
            "September",
            "October",
            "November",
            "December"
        ],
        "firstDay": 1
    }
})

here is a demo with spanish month names -> http://jsfiddle.net/r21747qc/

davidkonrad
  • 83,997
  • 17
  • 205
  • 265
42

You can use moment-with-locales.min.js instead of moment.min.js

<script type="text/javascript" src="//cdn.jsdelivr.net/momentjs/latest/moment-with-locales.min.js"></script>

and set localization before initializing daterangepicker

moment.locale('es');
$('#datePicker').daterangepicker();
Oleg
  • 2,165
  • 1
  • 15
  • 7
  • 9
    it is very important to emphasis the word **instead**, if you load the both file `moment` and `moment-with-locales` this solution will NOT work. you have to **REPLACE** the `moment` with `moment-with-locales`. **DO NOT LOAD THEM BOTH** – Hakan Fıstık Jan 14 '17 at 08:51
4

I made an 'pt-br' example based on @davidkonrad's comment

$('input[name="daterange"]').daterangepicker({
"locale": {
    "format": "DD/MM/YYYY",
    "separator": " - ",
    "applyLabel": "Aplicar",
    "cancelLabel": "Cancelar",
    "fromLabel": "De",
    "toLabel": "Até",
    "customRangeLabel": "Custom",
    "daysOfWeek": [
        "Dom",
        "Seg",
        "Ter",
        "Qua",
        "Qui",
        "Sex",
        "Sáb"
    ],
    "monthNames": [
        "Janeiro",
        "Fevereiro",
        "Março",
        "Abril",
        "Maio",
        "Junho",
        "Julho",
        "Agosto",
        "Setembro",
        "Outubro",
        "Novembro",
        "Dezembro"
    ],
    "firstDay": 0
}});

https://jsfiddle.net/joaopedroraldi/d7bmppga/55

3

For those using Node

    var moment = require('moment');
    moment.locale('es');
    require('daterangepicker/daterangepicker');

Then set the options names as month and days names will be translated


$('#datePicker').daterangepicker({
    "locale": {
        "format": "MM/DD/YYYY",
        "separator": " - ",
        "applyLabel": "Apply",
        "cancelLabel": "Cancel",
        "fromLabel": "From",
        "toLabel": "To",
        "customRangeLabel": "Custom",
     }
});
Johan H.
  • 157
  • 3
  • 14
-1

$('input[name="fecha_rango"]').daterangepicker({ autoUpdateInput: false, format: "DD/MM/YYYY", "locale": {
"separator": " - ", "applyLabel": "Aplicar", "cancelLabel": "Cancelar", "fromLabel": "DE", "toLabel": "HASTA", "customRangeLabel": "Custom", "daysOfWeek": [ "Dom", "Lun", "Mar", "Mie", "Jue", "Vie", "Sáb" ], "monthNames": [ "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre" ], "firstDay": 1 }});

dgc
  • 1