jQuery Datepicker localization
Solution 1
You can do like this
$.datepicker.regional['fr'] = {clearText: 'Effacer', clearStatus: '',
closeText: 'Fermer', closeStatus: 'Fermer sans modifier',
prevText: '<Préc', prevStatus: 'Voir le mois précédent',
nextText: 'Suiv>', 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']);
Solution 2
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
Solution 3
If you want to include some options besides regional localization, you have to use $.extend, like this:
$(function() {
$('#Date').datepicker($.extend({
showMonthAfterYear: false,
dateFormat:'d MM, y'
},
$.datepicker.regional['fr']
));
});
Solution 4
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>
Solution 5
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
};
Shipow
Algolia - UI/UX - Devsigner - Data - Analytics - Sass - Javascript - API I love to test each new shiny frameworks that just came out.
Updated on July 05, 2022Comments
-
Shipow almost 2 years
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 :
$(function() { $('#Date').datepicker({ showMonthAfterYear: false, showOn: 'both', buttonImage: 'media/img/calendar.png', buttonImageOnly: true, dateFormat:'d MM, y' }, $.datepicker.regional['fr'] ); });
-
Deckard about 12 yearsActually I found this approach to be the best for my purpose. That way you can inject the strings by your own variables and don't have to rely on the (sometimes incomplete) jQuery UI localization.
-
elboletaire over 11 yearsYou can find them now on github at github.com/jquery/jquery-ui/blob/master/ui/i18n
-
Salman A about 8 yearsThis is incorrect. It will overwrite the date format and show month after year setting with that of french regional.
-
MV. over 7 yearsThis is exactly what fixes my problem (setting the locale resets the dateFormat option even if explicitly set). Thanks (and great you showed non-working examples).
-
Funk Forty Niner over 7 yearsThe jqueryui.com/demos/datepicker/localization.html URL is a 404 now for the "view the source of this demo".
-
ThorstenC almost 6 yearsThats it! Setting regional resets the Datepicker options! Was looking for that for two days.