【问题标题】:How do I format a date with the “th” suffix, on en.yml?如何在 en.yml 上格式化带有“th”后缀的日期?
【发布时间】:2013-02-04 10:46:13
【问题描述】:

我想在我的日期中添加“th”、“nd”后缀。这个问题解决了一部分问题:In Ruby on Rails, how do I format a date with the "th" suffix, as in, "Sun Oct 5th"?

但我需要将它添加到 /config/en.yml 中。怎么做?

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-3.2


    【解决方案1】:

    您可以将字符串传递给语言环境

    en:
      foo: "it is the %{day} of %{month} today"
    
    I18n.t('foo', day: Date.today.day.ordinalize, month: Date::MONTHNAMES[Date.today.month] )
    

    【讨论】:

      猜你喜欢
      • 2010-09-14
      • 1970-01-01
      • 2011-01-30
      • 1970-01-01
      • 2017-01-07
      • 2011-04-08
      • 1970-01-01
      • 2022-07-13
      相关资源
      最近更新 更多