Localize month names - Calendar Railscasts #213 Localize month names - Calendar Railscasts #213 ruby-on-rails ruby-on-rails

Localize month names - Calendar Railscasts #213


You should use the localize method of I18n (shortened as l):

<h2 id="month"><%= l(@date) %></h2>

Then you can set different formats on your own:http://guides.rubyonrails.org/i18n.html#adding-date-time-formats

# config/locales/es.ymles:  date:    formats:      short: "%B %Y"      default: "%D %m, %Y"

And use it like this:

<h2 id="month"><%= l(@date, format: :short) %></h2>


just want to clarify that if you use with active record, just simply convert the string datetime value to date object as example below.

en:  date:    formats:      default: "%Y-%m-%d"      short: "%b %d"      long: "%B %d, %Y"    enter code here

<%= l(post.the_created_at.to_date, format: :long) %>