Best practice: How to localize datePicker?

44 views
Skip to first unread message

Thorsten Eilers

unread,
Aug 6, 2012, 4:11:00 AM8/6/12
to cfwh...@googlegroups.com
Morning,

i installed jQuery, jQuery UI and the datePicker plugin from http://cfwheels.org/plugins/listing/82

Whats the best way to localize the datePicker based on my var session.locale?

I am planning for 12 languages.

Someone suggested to put this code in the jQuery-File.

jQuery(function($){
        $.datepicker.regional['de'] = {clearText: 'löschen', clearStatus: 'aktuelles Datum löschen',
                closeText: 'schließen', closeStatus: 'ohne Änderungen schließen',
                prevText: '<zurück', prevStatus: 'letzten Monat zeigen',
                nextText: 'Vor>', nextStatus: 'nächsten Monat zeigen',
                currentText: 'heute', currentStatus: '',
                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'],
                monthStatus: 'anderen Monat anzeigen', yearStatus: 'anderes Jahr anzeigen',
                weekHeader: 'Wo', weekStatus: 'Woche des Monats',
                dayNames: ['Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag'],
                dayNamesShort: ['So','Mo','Di','Mi','Do','Fr','Sa'],
                dayNamesMin: ['So','Mo','Di','Mi','Do','Fr','Sa'],
                dayStatus: 'Setze DD als ersten Wochentag', dateStatus: 'Wähle D, M d',
                dateFormat: 'dd.mm.yy', firstDay: 1, 
                initStatus: 'Wähle ein Datum', isRTL: false};
        $.datepicker.setDefaults($.datepicker.regional['de']);
});


But I will need this for 12 languages. And I am not sure how to have a clean way to handle the different textstrings for every language.
I plan to put all textstrings in standard java properties files.

Does anybody has some input or how do you handle this?
Regards
Thorsten

Adam Chapman

unread,
Aug 13, 2012, 8:53:22 PM8/13/12
to cfwh...@googlegroups.com
Hi Thorsten,

I would look at creating a large structure of structures that contain all the default options you want to use in the datePicker.. like:

dpLang = {};
dpLang.en = {closeText: 'Close'... etc};
dpLang.de = {closeText: 'schließen' ... etc} ;
... etc

Then when you call your datePicker, reference the structure from the sessions variable and set any additional values... like:

dpArgs = dpLang[session.language];
dpArgs.objectName = "myObj";
dpArgs.property = "myDate"; 

datePicker(argumentCollection=dpArgs);

Regards,
Adam

Thorsten Eilers

unread,
Aug 14, 2012, 2:38:16 AM8/14/12
to cfwh...@googlegroups.com

Thanks Adam, when I have time for this I will give your approach a try.

tpet...@gmail.com

unread,
Aug 14, 2012, 1:16:36 PM8/14/12
to cfwh...@googlegroups.com
http://docs.jquery.com/UI/Datepicker  look at the Localization section

the documentation said to create separate files each language you want
Reply all
Reply to author
Forward
0 new messages