本地化strftime rails 2.2

时间:2009-11-25 07:14:11

标签: ruby-on-rails ruby datetime

<%  @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 %>

在这种情况下,您如何本地化day.strftime

1 个答案:

答案 0 :(得分:2)

假设dayTime个实例,请将strftime替换为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 %>

然后转到您的en.yml文件并添加以下项目。

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

weekmonth定义添加到每个语言文件中。