What's new? | Help | Directory | Sign in
Google
calendardateselect
Rails Date Picker: Calendar Date Select
  
  
  
    
Search
for
Updated Jul 12, 2007 by jtkimbell
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 %>

Comment by kacper.ciesla, Nov 15, 2007

It would be great to add something like set_tranlation_method where somebody can provide method he's already using for msgs localization.

Comment by oterosantos, Dec 17, 2007

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?

Comment by timcharper, Dec 17, 2007

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

Comment by brandon.zylstra, Feb 27, 2008

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.

Comment by vkalion, Mar 06, 2008

How it is possible to configure calendar to use ordering of weekdays starting from Monday?

Comment by alex.creopolis, Mar 06, 2008

:)

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" ...

Comment by vkalion, Mar 14, 2008

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 fact

Thanks Ryan.Warner.MN for comment

Comment by Li.ChangGeng, May 28, 2008

Another neat way:

    <%= calendar_date_select_includes nil,:locale=>'zh' %>

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:)

Comment by brunoaalves, Jun 12, 2008

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"
}
Comment by herve.nivon, Jun 24, 2008

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"
}
Comment by timcharper, Jun 24, 2008

Herve: it should be, and at one point was, but seems to be broken again. I'll have to look at it.


Sign in to add a comment