我尝试使用rails-i18n gem将我的应用程序表单中的datetime frome英语翻译成意大利语。
我创建了it.yml文件并输入了
config.i18n.default_locale = :it
application.rb中的代码
在表单中结果很棒但是当我编译表单然后显示它时,翻译就消失了!!!
我该怎么办?
appllication.rb
class Application < Rails::Application
config.time_zone = "Rome"
config.assets.initialize_on_precompile = false
config.i18n.default_locale = :it
form.html.erb
<h2>Riferimenti temporali</h2><br/>
<div class="form-field">
<h3> Data di inizio campionamento </h3><br/>
<%= f.date_select :data_inizio, :order => [:month, :year],
:discard_days => true %>
</div>
<div class="form-field">
<h3> Data di fine campionamento </h3><br/>
<%= f.date_select :data_fine, :order => [:month, :year],
:discard_days => true %>
</div>
show.html.erb
<h2>Riferimenti temporali</h2><br/>
<div class="form-field">
<h3> Data di inizio campionamento </h3><br/>
<p> <%= @modulo2.data_inizio.strftime("%B %Y") %> </p>
</div>
<div class="form-field">
<h3> Data di fine campionamento</h3><br/>
<p> <%= @modulo2.data_fine.strftime("%B %Y") %> </p>
</div>
it.yml
it:
date:
abbr_month_names:
-
- Gen
- Feb
- Mar
- Apr
- Mag
- Giu
- Lug
- Ago
- Set
- Ott
- Nov
- Dic
month_names:
-
- Gennaio
- Febbraio
- Marzo
- Aprile
- Maggio
- Giugno
- Luglio
- Agosto
- Settembre
- Ottobre
- Novembre
- Dicembre
如果您需要其他一些代码告诉我:)
答案 0 :(得分:1)
Rubys strftime
不了解本地化,您需要浏览I18n
API。
请改为:l(@modulo2.data_fine, format: "%B %Y")
l
方法是I18n.localize