Nona
Nona

Reputation: 5472

How to lookup i18n translations in nested yaml file in Rails 4.2?

Under 4.1.4 "Lazy" Lookup, if you have the following dictionary:

es:
  books:
    index:
      title: "Título"

you can look up the books.index.title value inside app/views/books/index.html.erb template like this (note the dot):

<%= t '.title' %>

But if I alter the dictionary like this:

es:
  books:
    index:
      title: "Título"
      author:
        first_name: "Jane"

Then:

<%= t '.first_name' %>

gives a missing translation error.

1) Is there a limit on the nesting depth you can have?
2) Can you setup custom hash keys via yaml (for example, suppose instead of "index" as a key I want to use "kite", even though kite is not an actual view) and if so how?

Upvotes: 0

Views: 532

Answers (1)

Danny
Danny

Reputation: 6025

No, there is no limit on the nesting depth, it's only that you're not following the "logic" behind it:

the '.' in '.first_name' refers to the controller + action in your page, in this case books: index: - so if you want to access author: first_name:, you should put '.author.first_name' in your index file.

Upvotes: 1

Related Questions