def localize(locale, object, format = :default)
raise ArgumentError, "Object must be a Date, DateTime or Time object. #{object.inspect} given." unless object.respond_to?(:strftime)
type = object.respond_to?(:sec) ? 'time' : 'date'
formats = translate(locale, "#{type}.formats""#{type}.formats")
format = formats[format.to_sym] if formats && formats[format.to_sym]
format = format.to_s.dup
format.gsub!(/%a/, translate(locale, "date.abbr_day_names""date.abbr_day_names")[object.wday])
format.gsub!(/%A/, translate(locale, "date.day_names""date.day_names")[object.wday])
format.gsub!(/%b/, translate(locale, "date.abbr_month_names""date.abbr_month_names")[object.mon])
format.gsub!(/%B/, translate(locale, "date.month_names""date.month_names")[object.mon])
format.gsub!(/%p/, translate(locale, "time.#{object.hour < 12 ? :am : :pm}""time.#{object.hour < 12 ? :am : :pm}")) if object.respond_to? :hour
object.strftime(format)
end