Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure the jQuery UI Datepicker to use a localized calendar?

I'm wondering if this is possible and if yes, how would I go about doing it? I'm trying to make the widget use a Jalali(Persian) Calender.

like image 413
Mohammad Sepahvand Avatar asked Jan 01 '13 13:01

Mohammad Sepahvand


1 Answers

jQuery UI Datepicker localization

In general, to add localization to jQuery UI Datepicker you need to include a specific localization file immediately after including the Datepicker's script. For example, to set a French localization, you'd do this:

[...include jQuery and jQuery UI...]
<script type="text/javascript" src="jquery.ui.datepicker-fr.js"></script>

The localization files are included as part of the the standard jQuery UI download, in a separate directory (development-bundle/ui/i18n). For more on this, see the Datepicker API documentation (under "Localization").

Current status: Farsi in, Jalali out

Currently, jQuery UI download package doesn't seem to include a Jalali localization file. For now, there seems to be only a regular (Georgian) calendar translated into Farsi (jquery.ui.datepicker-fr.js).

Solution 1 - custom localization file

If you prefer to stick with jQuery UI's datepicker, you can create a custom localization file, based on the format of existing localization files. If you're familiar with the calendar in question, it shouldn't be difficult.

Solution 2 - use a different plugin

Consider using the jQuery Calendars plugin instead. It already includes most common world calendars in several languages and formats, so generating a Jalali or any other foreign calendar for that matter is done by the flick of a setting.

like image 163
Boaz Avatar answered Oct 21 '22 11:10

Boaz