localization or internationalization in rails

Most of the new websites are having the feature of localization or internationalization on their site. With introduction of rails 2.3 this feature is provided by default But if you are still working in rails 2.0 or 2.1 then GlobalLite is the solution for you.. http://code.google.com/p/globalite/

How ever while implement it in one of my projects I noticed that the localized date time module used in the plugin has a problem when you have time_select tag in your form.

So when you use a time_select tag in your form it will generate an error message “Can’t convert nil into string”. The problem is in the file called localized_action_view.rb which you will find in plugins/globalite/lib/rails folder.

Apply the code below to get it fixed

def select_month(date, options = {}, html_options = {})
if options[:locale]
@original_locale = Locale.code
Locale.code = options[:locale]
val = date ? (date.kind_of?(Fixnum) ? date : date.month) : ”
if options[:use_hidden]
hidden_html(options[:field_name] || ‘month’, val, options)
month_options = []
monthnames = :date_helper_month_names.l
abbr_monthnames = :date_helper_abbr_month_names.l
month_names = options[:use_month_names] || (options[:use_short_month] ? abbr_monthnames : monthnames)
month_names.unshift(nil) if month_names.size < 13
1.upto(12) do |month_number|
month_name = if options[:use_month_numbers]
elsif options[:add_month_numbers]
month_number.to_s + ‘ – ‘ + month_names[month_number]

month_options << ((val == month_number) ?
%(<option value=”#{month_number}” selected=”selected”>#{month_name}</option>\n) :
%(<option value=”#{month_number}”>#{month_name}</option>\n)
@selector = select_html(options[:field_name] || ‘month’, month_options, options)
Locale.code = @original_locale if options[:locale]
return @selector
#  Locale.code = @original_locale if options[:locale]
#  return @selector

You may even Comment the date module in the code  plugins/globalite/lib/rails/localized_action_view.rb

this will make use of default rails date time. so nothing will get affected if you do this. But the solution mentioned about is a better one.

Njoi the power of Internationalization and make sure site global.

Be Sociable, Share!