Heelo,基本上我想做的是
我有一个帮助器,它从一个索引返回一周中的一天名称,函数的基础是哈希Date :: DAYS_INTO_WEEK如何本地化这些名称?我已经在pt-BR中使用了svenfuch i18n,但我可以在那部分申请。 这是我的帮手:
def weekDayName(dayNumber)
weekDays = Date::DAYS_INTO_WEEK
weekDays.index(dayNumber)
end
这里是在i18n:
---
pt-BR:
date:
abbr_day_names:
- Dom
- Seg
- Ter
- Qua
- Qui
- Sex
在视图中:
<td><%= weekDayName(price.week_day)%></td>
答案 0 :(得分:0)
这可行:
在i18n:
---
pt-BR:
helpers:
labels:
monday: 'Segunda-feira'
tuesday: 'Terça-feira'
.. etc
在视图中:
<td><%= t('helpers.labels.' + weekDayName(price.week_day).to_s) %></td>
答案 1 :(得分:0)
weekDays.index(dayNumber) index is deprecated; use Hash#key weekDAys.key(dayNumber)
而不是
application.rb中
config.i18n.available_locales = [:'pt-BR',:en,:pt]
config.i18n.enforce_available_locales = true
配置/语言环境/ PT-BR.yml
pt-BR:
monday: Dom
tuesday: Seg
wednesday: Ter
thursday: Qua
friday: Qui
saturday: Sex
重启服务器
def weekDayName(dayNumber)
weekDays = Date::DAYS_INTO_WEEK
day = weekDays.key(dayNumber)
I18n.translate day, locale: 'pt-BR'
end