jQuery Datepicker localization

前端 未结 8 1266
我在风中等你
我在风中等你 2020-12-07 15:28

I need a french calendar and I can\'t understand the problem. I guess I\'m not using the regional options like it should be. But...

Here is my code :



        
相关标签:
8条回答
  • 2020-12-07 15:58

    datepicker in Finnish (Käännös suomeksi)

    $.datepicker.regional['fi'] = {
      closeText: "Valmis", // Display text for close link
      prevText: "Edel", // Display text for previous month link
      nextText: "Seur", // Display text for next month link
      currentText: "Tänään", // Display text for current month link
      monthNames: [ "Tammikuu","Helmikuu","Maaliskuu","Huhtikuu","Toukokuu","Kesäkuu",
      "Heinäkuu","Elokuu","Syyskuu","Lokakuu","Marraskuu","Joulukuu" ], // Names of months for drop-down and formatting
      monthNamesShort: [ "Tam", "Hel", "Maa", "Huh", "Tou", "Kes", "Hei", "Elo", "Syy", "Lok", "Mar", "Jou" ], // For formatting
      dayNames: [ "Sunnuntai", "Maanantai", "Tiistai", "Keskiviikko", "Torstai", "Perjantai", "Lauantai" ], // For formatting
      dayNamesShort: [ "Sun", "Maa", "Tii", "Kes", "Tor", "Per", "Lau" ], // For formatting
      dayNamesMin: [ "Su","Ma","Ti","Ke","To","Pe","La" ], // Column headings for days starting at Sunday
      weekHeader: "Vk", // Column header for week of the year
      dateFormat: "mm/dd/yy", // See format options on parseDate
      firstDay: 0, // The first day of the week, Sun = 0, Mon = 1, ...
      isRTL: false, // True if right-to-left language, false if left-to-right
      showMonthAfterYear: false, // True if the year select precedes month, false for month then year
      yearSuffix: "" // Additional text to append to the year in the month headers
      };
    
    0 讨论(0)
  • 2020-12-07 16:00

    That code should work, but you need to include the localization in your page (it isn't included by default). Try putting this in your <head> tag, somewhere after you include jQuery and jQueryUI:

    <script type="text/javascript"
            src="https://raw.githubusercontent.com/jquery/jquery-ui/master/ui/i18n/datepicker-fr.js">
    </script>
    

    I can't find where this is documented on the jQueryUI site, but if you view the source of this demo you'll see that this is how they do it. Also, please note that including this JS file will set the datepicker defaults to French, so if you want only some datepickers to be in French, you'll have to set the default back to English.

    You can find all languages here at github: https://github.com/jquery/jquery-ui/tree/master/ui/i18n

    0 讨论(0)
  • 2020-12-07 16:02

    You can do like this

     $.datepicker.regional['fr'] = {clearText: 'Effacer', clearStatus: '',
        closeText: 'Fermer', closeStatus: 'Fermer sans modifier',
        prevText: '&lt;Préc', prevStatus: 'Voir le mois précédent',
        nextText: 'Suiv&gt;', nextStatus: 'Voir le mois suivant',
        currentText: 'Courant', currentStatus: 'Voir le mois courant',
        monthNames: ['Janvier','Février','Mars','Avril','Mai','Juin',
        'Juillet','Août','Septembre','Octobre','Novembre','Décembre'],
        monthNamesShort: ['Jan','Fév','Mar','Avr','Mai','Jun',
        'Jul','Aoû','Sep','Oct','Nov','Déc'],
        monthStatus: 'Voir un autre mois', yearStatus: 'Voir un autre année',
        weekHeader: 'Sm', weekStatus: '',
        dayNames: ['Dimanche','Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi'],
        dayNamesShort: ['Dim','Lun','Mar','Mer','Jeu','Ven','Sam'],
        dayNamesMin: ['Di','Lu','Ma','Me','Je','Ve','Sa'],
        dayStatus: 'Utiliser DD comme premier jour de la semaine', dateStatus: 'Choisir le DD, MM d',
        dateFormat: 'dd/mm/yy', firstDay: 0, 
        initStatus: 'Choisir la date', isRTL: false};
     $.datepicker.setDefaults($.datepicker.regional['fr']);
    
    0 讨论(0)
  • 2020-12-07 16:07

    You must extend the regional options like this (code split on multiple lines for readability):

    var options = $.extend(
        {},                                  // empty object
        $.datepicker.regional["fr"],         // fr regional
        { dateFormat: "d MM, y" /*, ... */ } // your custom options
    );
    $("#datepicker").datepicker(options);
    

    The order of parameters is important because of the way jQuery.extend works. Two incorrect examples:

    /*
     * This overwrites the global variable itself instead of creating a
     * customized copy of french regional settings
     */
    $.extend($.datepicker.regional["fr"], { dateFormat: "d MM, y"});
    
    /*
     * The desired dateFormat is overwritten by french regional 
     * settings' date format
     */
    $.extend({ dateFormat: "d MM, y"}, $.datepicker.regional["fr"]);
    

    PS: you also need to load the jQuery UI i18n files:

    <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/i18n/jquery-ui-i18n.min.js">
    </script>
    
    0 讨论(0)
  • 2020-12-07 16:07

    In case you are looking for datepicker in spanish (datepicker en español)

    <script type="text/javascript">
        $.datepicker.regional['es'] = {
            monthNames: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'],
            monthNamesShort: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'],
            dayNames: ['Domingo', 'Lunes', 'Martes', 'Miercoles', 'Jueves', 'Viernes', 'Sabado'],
            dayNamesShort: ['Dom', 'Lun', 'Mar', 'Mie', 'Jue', 'Vie', 'Sab'],
            dayNamesMin: ['Do', 'Lu', 'Ma', 'Mc', 'Ju', 'Vi', 'Sa']
        }
    
        $.datepicker.setDefaults($.datepicker.regional['es']);
    
    </script>
    
    0 讨论(0)
  • 2020-12-07 16:15

    Datepicker in german (Deutsch):

    $.datepicker.regional['de'] = {
        monthNames: ['Januar','Februar','März','April','Mai','Juni',
        'Juli','August','September','Oktober','November','Dezember'],
        monthNamesShort: ['Jan','Feb','Mär','Apr','Mai','Jun',
        'Jul','Aug','Sep','Okt','Nov','Dez'],
        dayNames: ['Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag'],
        dayNamesShort: ['Son','Mon','Die','Mit','Don','Fre','Sam'],
        dayNamesMin: ['So','Mo','Di','Mi','Do','Fr','Sa'],
        firstDay: 1};
     $.datepicker.setDefaults($.datepicker.regional['de']);
    
    0 讨论(0)
提交回复
热议问题