'Rails internationalization (i18n): Everything translating except layouts/application.html.erb

I keep getting "translation missing: en.layouts.application.title" for title or any item I try to translate within app/views/layouts/application.html.erb file.

config/locales/en.yml

en:

  layouts:
    application:
      title:  "My Catalog"
      home:  "Home"
      store:   "Store"
      faq:      "FAQ"
      contact:  "Contact"
      about:    "About"

app/views/layouts/application.html.erb

<div id="banner">
  <% t('.title') %>
</div>
<div id="nav_menu" class="sidebar_menu">
  <a href="/"><%= t('.home') %></a>
  <a href="/store"><%= t('.store') %></a>
  <a href="/faq"><%= t('.faq') %></a>
  <a href="/contact"><%= t('.contact') %></a>
  <a href="/about"><%= t('.about') %></a>
</div>

All the translations in the views are working but anything in the layout says its missing. I am using en.yml, fr.yml, and es.yml and it's the same issue with each (fr.layouts.application.title and es.layouts.application.title, respectively)

If I move the lines out of the layouts: application: nest and into the root hierarchy of the .yml file (removing the period from the t method of course) then everything translates. As soon as I move them back under layouts: application: I get translation missing again.

What could be wrong? I am using Rails 3.2.7

EDIT 1: Just tried using <% t('layouts.application.title') %> but still says translation missing.

EDIT 2: Work-around found if I copy or rename application.html.erb to a different name (and change *.yml files accordingly).
If I start a new project translations work just fine within application.html.erb. However in the current project: as long as I'm using application.html.erb (even with minimal test content) I still get translation missing.



Solution 1:[1]

I run today into the exact same problem and after a debugging session I found the root of the problem. I bet this is your problem too, because it also makes sense with your workaround and with the issue not happening on a brand new project. Do you happen to have the hierarchy

en:
  layouts:
    application:

defined somewhere else in your yml files?

I was defining

en:
  layouts:
    header:
      language: "Language"

and

en:
  layouts:
    header:
      my_profile: "My profile"

in two different places, so I guess the translator would look for the first (and assumed unique) occurrence of the key combination and would never find the other one...

Hope this will solve your problem!

Solution 2:[2]

In case it helps anyone else:

My issue was a little different — I was including periods in the translation keys (e.g., In retrospect...: 'In retrospect, it should've been obvious that was a bad idea.'). Enclosing the keys in single quotes did not make a difference, so I just removed the periods entirely, and the problem was solved.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 deivid
Solution 2 Wanderspeak