March 25, 2012

How to set languages for two jquery ui datepickers

Question by Vincent

I have two jquery ui datepickers in my page and I would like to apply a specific language for each one of them (let says german for one datepicker and italian for the other datepicker)

Now here is the problem: the last language file that is called apply its settings to all the datepickers (in this case, italian is applied in both inputs).
I’m using the following code, what should I change to apply a specific language to each of the datepickers? thanks

<script type="text/javascript" src="http://jquery-ui.googlecode.com/svn/trunk/ui/i18n/jquery.ui.datepicker-de.js"></script>

<script type="text/javascript" src="http://jquery-ui.googlecode.com/svn/trunk/ui/i18n/jquery.ui.datepicker-it.js"></script>

$(function(){

    $.datepicker.setDefaults($.datepicker.regional['de']);
    $( "#en" ).datepicker();

    $.datepicker.setDefaults($.datepicker.regional['it']);
    $( "#it" ).datepicker();


    });

Answer by Starx

This is how you do it: [Read Manual]

$.datepicker.setDefaults($.datepicker.regional['de']); 
                      //  ^ first set a default locale
$("#en").datepicker($.datepicker.regional['en']);  
                 // ^ then different locale for different
$("#it").datepicker($.datepicker.regional['it']);  

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!