Carlos Barbosa
Carlos Barbosa

Reputation: 1432

localize strftime rails 2.2

<%  @recently_active_objects = Activity.find(:all, :limit => 10, :order => "id DESC")  %>

<% @recently_active_objects.group_by{ |object| object.created_at.midnight }.each do |day, objects| %>
<h3><%=  day.strftime("%A, %B %e")  %></h3>

                <% objects.each do |object| %>
                <%= activity_message_for_activity(object) %>
                <% end %>

<% end %>

How do you localize day.strftime in this case?

Upvotes: 2

Views: 994

Answers (1)

Simone Carletti
Simone Carletti

Reputation: 176402

Assuming that day is a Time instance, replace strftime by l.

<% @recently_active_objects.group_by{ |object| object.created_at.midnight }.each do |day, objects| %>
  <h3><%=l day, :format => :weekmonth %></h3>
  <% objects.each do |object| %>
    <%= activity_message_for_activity(object) %>
  <% end %>
<% end %>

Then go to your en.yml file and add the following item.

en:
  time: 
    formats: 
      weekmonth: "%A, %B %e"

Add the weekmonth definition to every language file.

Upvotes: 2

Related Questions