2
votes

I'm having a really weird issue with i18n on a current rails project. I get translation missing messages whenever I attempt to use the key notifications. For example:

#en-US.yml
en-US:
  notifications:
    index:
      title: 'notification page'

#/notifications/index.html.erb
<%= content_for :title, t('.title') -%>

This will fail and tell me the translation is missing

#en-US.yml
en-US:
  notifications:
    index:
      title: 'notification page'

#/notifications/index.html.erb
<%= content_for :title, t('notifications.index.title') -%>

This will also fail.

#en-US.yml
en-US:
  notification:
    index:
      title: 'notification page'

#/notifications/index.html.erb
<%= content_for :title, t('notification.index.title') -%>

This oddly, will work, removing the s will allow it to find the translation.

#en-US.yml
en-US:
  notifications1:
    index:
      title: 'notification page'

#/notifications/index.html.erb
<%= content_for :title, t('notifications1.index.title') -%>

This also will work, adding a 1 to the end of notifications works.

It appears that rails does not like the word notifications. This is a problem because I don't want to have to rename the entire model for this, and also I want to use the i18n.t view shortcuts for consistency. Is notifications a reserved word? Is there any reason why it is failing to find it?

2

2 Answers

0
votes

I'm not sure why it's failing in your case but I just had a go myself and it's not a reserved word, my locale file:

en:
  notifications:
    foo: bar

The result:

1.8.7 :001 > I18n.t('notifications.foo')
 => "bar"

This test was done with Rails 3.1.5 and Ruby 1.8.7.

In your case you got the following?

1.8.7 :001 > I18n.t('notifications')
 => "translation missing: en.notifications" 
0
votes

Although not an exact answer, I have found that there are a few words in I18n that cannot be used as keys. I am assuming the I18n code uses them elsewhere.

Others include "no", "yes", "on", etc.

Just using a synonym or do something like "notifications_" to make it different.