gpt4 book ai didi

ruby-on-rails - 本地化月份名称 - 日历 Railscasts #213

转载 作者:行者123 更新时间:2023-12-03 22:27:48 25 4
gpt4 key购买 nike

我正在尝试使用 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]

也不工作

在 html.erb 上
<h2 id="month"><%= @date.strftime("%B %Y") %></h2>

我想改变这个

enter image description here

有人帮我吗?

谢谢

最佳答案

您应该使用 localize I18n 的方法(缩写为 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>

关于ruby-on-rails - 本地化月份名称 - 日历 Railscasts #213,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13883878/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com