Rails用自定义翻译形成select_month帮助器数月

时间:2017-10-04 20:14:51

标签: ruby-on-rails

我试图通过使用翻译在select_month帮助程序下拉列表中使用自定义月份缩写。

我的表单如下所示:

<div class="col-xs-4 col-sm-4 pad-bottom">
  <div class="pull-right pad-top">
    <%= select_month(Date.today, :field_name => 'cc_exp_month', :add_month_numbers => true, :use_month_names => t('date.abbr_month_names')) %>
    <%= select_year(Date.today, :field_name => 'cc_exp_year', :start_year => Date.today.year, :end_year => 8.years.from_now.year) %>
  </div>
</div>

我有一个包含以下翻译的en.yml文件:

date:
  abbr_month_names: [~, M1, M2, M3, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec]

我试图使用以下内容,它们似乎也没有帮助。

:use_month_names => %w(t('date.abbr_month_names'))
:use_month_names => %w(I18n.t('date.abbr_month_names')) 

有人知道怎么这样做吗?

1 个答案:

答案 0 :(得分:0)

您缺少该语言作为翻译文件的顶级键。在您的情况下en。您可以查看默认的rails locale file of active support

en:
  date:
    abbr_month_names: [~, Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec]
相关问题