Rails localization "lazy" lookup

565 Views Asked by At

I have such views structure:

views
  layouts
    visitors
      _footer.html.haml
      _header.html.haml
    visitors.html.haml

In my config/application.rb I've added

config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}').to_s]

My locales file structure looks like this:

config
  locales
    views
      layouts
        visitors.en.yml

My visitors.en.yml has such structure

en:
  layouts:
    visitors:
      title: Site title

In my views/layouts/visitors.html.haml I call I18n.t('.title'), but receive error translation missing en.title.

If I do like this I18n.t('layouts.visitors.title') - it translates everything properly.

What I'm doing wrong?

1

There are 1 best solutions below

0
On BEST ANSWER

Already found the answer. It turned out that this Rails feature works only when I call helper like this t('.title'). Only then the appropriate translation is picked up. If I use I18n.t only full I18n.t('layouts.visitors.title') works properly.