Rails: How to make Date strftime aware of the default locale?

前端 未结 3 2160
北海茫月
北海茫月 2020-12-23 18:53

I have my default locale set in the environment.rb as de (German).

I also see all the error messages in German, so the locale is picked up

相关标签:
3条回答
  • 2020-12-23 19:29

    you can also make it shorter:

    l(some_date, :format => '%d %B %Y')
    
    0 讨论(0)
  • 2020-12-23 19:41

    In es.yml put:

    es:
      date:
        formats:
          default: "%d / %m / %Y"
    

    In index.html.erb put:

    <%= l somemodel.datefield %>
    
    0 讨论(0)
  • 2020-12-23 19:48

    Use the l (alias for localize) method instead of raw strftime, like this:

    l(date, format: '%B %d, in the year %Y')
    

    See here for more information, hope that helps.

    You can also define 'named' formats, a couple of them (short, long) are already predefined.

    0 讨论(0)
提交回复
热议问题