|
|
HowToLocalize
How to localize
Introduction
Localization is now possible in CalendarDateSelect. However, since there are so many different approaches to localization, I didn't want to get in the way of any particular system. Therefore, there are certain extensible points of calendar date select that will let you integrate the plug-in with whatever localization system you choose to use.
Details
Here is one way to localize. Somewhere in your page, before displaying your calendars, put code in like this:
Manual translation
<script type="text/javascript">
_translations = {
"OK": "OK",
"Now": "Ahora",
"Today": "Hoy"
}
Date.weekdays = $w("D L Ma Mi J V S");
Date.months = $w("Enero Febrero Marzo Abril Mayo Junio Julio Agosto Septiembre Octubre Noviembre Deciembre" );
</script>
<%= calendar_date_select_tag "my_field", nil %>Translation using gettext
If you're using gettext, you can do the following:
<script type="text/javascript">
_translations = {
"OK": "<%=_("OK")%>",
"Now": "<%=_("Ahora")%>",
"Today": "<%=_("Hoy")%>"
}
Date.weekdays = $w("<%=_("D L Ma Mi J V S")%>");
Date.months = $w("<%=_("Enero Febrero Marzo Abril Mayo Junio Julio Agosto Septiembre Octubre Noviembre Deciembre")%>");
</script>
<%= calendar_date_select_tag "my_field", nil %>
Sign in to add a comment

It would be great to add something like set_tranlation_method where somebody can provide method he's already using for msgs localization.
When I translate it I can't save the date to DB because "Enero" it's not "January" and Rails can't understand it.
How to solve this?
Look in this file 1.8/usr/lib/ruby/1.8/date/format.rb
You'll need to implement your own date parsing method to grab the Spanish months it seems. I'd alias chain Date::parse and implement a catch to do something very similar to parse_us, but just create and reference a hash like Format::ES_ABBR_MONTHS
maybe it would be easier to have the calendar control put the value in both a hidden field (in English, which is actually saved to the database) and in a visible field (in Spanish or whatever other language, which is not saved to the db, or is saved as text, or whatever). This way you'd localize the UI without running into problems with backend components that expect/require English.
How it is possible to configure calendar to use ordering of weekdays starting from Monday?
:)
There are some kind of html bug in IE7 (not sp1), when "Now" button is translated to "Maintenance" (in french), Time dropdown and "Now", "OK" buttons are slide down ugly,
Ive had to to change placement of "OK" button to "Now", and put <br/> after, and then "NOw" ...
To make a Monday a first day in week change 3 lines in calendar_date_select.js:
Date.weekdays = $w("M T W T F S S"); className: (weekday==5) || (weekday==6) ? " weekend" : "" //clear the class pre_days = this.beginning_date.getDay() - 1 // draw some days before the factThanks Ryan.Warner.MN for comment
Another neat way:
and add a new js file as public/javascripts/calendar_date_select/locale/zh.js
the content of this file looks like:
Date.weekdays = $w("一 二 三 四 五 六 七"); Date.months = $w("一 二 三 四 五 六 七 八 九 十 十一 十二" ); Date.first_day_of_week = 1 _translations = { "OK": "确定", "Now": "现在", "Today": "今天" }Hope it's helpful:)
For portuguese you can do pt.js:
Date.weekdays = $w('D S T Q Q S S'); Date.months = $w('Janeiro Fevereiro Março Abril Maio Junho Julho Agosto Setembro Novembro Dezembro'); Date.first_day_of_week = 0 _translations = { "OK": "OK", "Now": "Agora", "Today": "Hoje" }Is it possible to change the value of the select button for hours ?
For french you can create fr.js:
Date.weekdays = $w('L Ma Me J V S D'); Date.months = $w('Janvier Février Mars Avril Mai Juin Juillet Août Septembre Octobre Novembre Décembre'); Date.first_day_of_week = 1; _translations = { "OK": "OK", "Now": "Maintenant", "Today": "Aujourd'hui" }Herve: it should be, and at one point was, but seems to be broken again. I'll have to look at it.