如何在en.yml上格式化带有“th”后缀的日期?

时间:2013-02-04 10:46:13

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

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

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

1 个答案:

答案 0 :(得分:1)

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

en:
  foo: "it is the %{day} of %{month} today"

I18n.t('foo', day: Date.today.day.ordinalize, month: Date::MONTHNAMES[Date.today.month] )