在 Rails 中,我试图本地化日期:
2.1.1 :005 > Date.today
=> Mon, 14 Apr 2014
2.1.1 :006 > I18n.localize(Date.today)
=> "14/04/2014"
2.1.1 :007 >
第二个输出不是第一个的正确翻译!
你能帮助我吗 ?
在 Rails 中,我试图本地化日期:
2.1.1 :005 > Date.today
=> Mon, 14 Apr 2014
2.1.1 :006 > I18n.localize(Date.today)
=> "14/04/2014"
2.1.1 :007 >
第二个输出不是第一个的正确翻译!
你能帮助我吗 ?
您可以定义新格式:
en:
date: # there is also a section for datetime and time
formats:
day_month_abbr: "%a, %d %b %Y"
并像这样使用它:
I18n.localize(Date.today, format: :day_month_abbr)
# => "Mon, 14 Apr 2014"
或者您可以覆盖默认格式:
en:
date:
formats:
default: "%a, %d %b %Y"
然后你不需要给出任何论点:
I18n.l(Date.today) #=> "Mon, 14 Apr 2014"
可用于 DateTime/Time/Date的所有通配符列表:http: //apidock.com/ruby/DateTime/strftime
The second upload is in fact the correct translation.
If you want to customize the output formatting, check out the documentation here: http://edgeguides.rubyonrails.org/i18n.html#adding-date-time-formats