我正在尝试使用railscasts第213集的教程。 我添加es.yml但没有工作。 我尝试使用en.yml上的替换单词本地化月份名称,例如
en:
date:
month_names: [~, Enero, Febrero, Marzo, Abril, Mayo, Junio, Julio, Agosto, Septiembre, Octubre, Noviembre, Diciembre]
abbr_month_names: [~, Ene, Feb, Mar, Abr, May, Jun, Jul, Ago, Sep, Oct, Nov, Dic]
不能正常工作
on html.erb
<h2 id="month"><%= @date.strftime("%B %Y") %></h2>
我想改变这个
感谢的
答案 0 :(得分:14)
您应该使用I18n的localize
方法(缩写为l
):
<h2 id="month"><%= l(@date) %></h2>
然后您可以自己设置不同的格式: http://guides.rubyonrails.org/i18n.html#adding-date-time-formats
# config/locales/es.yml
es:
date:
formats:
short: "%B %Y"
default: "%D %m, %Y"
并像这样使用它:
<h2 id="month"><%= l(@date, format: :short) %></h2>
答案 1 :(得分:0)
只是想澄清一下,如果您使用活动记录,只需将字符串Observable.using(
() -> newResponseEndWatcher(), // create a new response end watcher on each subscription
responseEndWatcher -> apScanDataNotificationObservable.takeUntil(responseEndWatcher), // create the response observable that will complete properly
responseEndWatcher -> { /* ignored, responseEndWatcher will get GCed eventually */ }
);
值转换为datetime
对象,如下例所示。
date
en:
date:
formats:
default: "%Y-%m-%d"
short: "%b %d"
long: "%B %d, %Y"
enter code here