Question

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.

Was it helpful?

Solution

UPDATE: Been away from this project for some time but figured out the issue....

SOLVED: Pretty stupid I might add.
Make sure you do not tab ('\t') to space the text in the files.
Clearly it's not able to compile correctly with the tab characters.

OTHER TIPS

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!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top