【发布时间】:2012-08-14 05:53:24
【问题描述】:
我在当前的 Rails 项目中遇到了一个非常奇怪的 i18n 问题。每当我尝试使用密钥 notifications 时,都会收到翻译缺失消息。例如:
#en-US.yml
en-US:
notifications:
index:
title: 'notification page'
#/notifications/index.html.erb
<%= content_for :title, t('.title') -%>
这会失败并告诉我翻译丢失了
#en-US.yml
en-US:
notifications:
index:
title: 'notification page'
#/notifications/index.html.erb
<%= content_for :title, t('notifications.index.title') -%>
这也会失败。
#en-US.yml
en-US:
notification:
index:
title: 'notification page'
#/notifications/index.html.erb
<%= content_for :title, t('notification.index.title') -%>
奇怪的是,这会起作用,删除 s 将允许它找到翻译。
#en-US.yml
en-US:
notifications1:
index:
title: 'notification page'
#/notifications/index.html.erb
<%= content_for :title, t('notifications1.index.title') -%>
这也可以,在通知末尾添加1 即可。
Rails 似乎不喜欢通知这个词。这是一个问题,因为我不想为此重命名整个模型,而且我想使用 i18n.t 视图快捷方式来保持一致性。 notifications 是保留字吗?找不到它有什么原因吗?
【问题讨论】:
标签: ruby-on-rails-3 internationalization