Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I18n in Rails 3 with a admin namespace

I am developing an Rails app on the advice of the Rails Guides to create the folder tree and files with the translations. My folder tree is similar to this:

|-defaults
|---es.rb
|---en.rb
|-models
|---book
|-----es.rb
|-----en.rb
|-views
|---defaults
|-----es.rb
|-----en.rb
|---books
|-----es.rb
|-----en.rb
|---users
|-----es.rb
|-----en.rb
|---navigation
|-----es.rb
|-----en.rb

The content in config/locales/views/books/en.yml is similar to this:

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

A in inside app/views/books/index.html.erb template like this (note the dot):

<%= t '.title' %>

When I have no namespace my translations in views work well but with the namespace "admin" that I use in my backend it does not work. Anyone know what is the problem?

like image 599
Jesus Avatar asked Mar 14 '12 17:03

Jesus


1 Answers

I am using <%= t '.title' %> because I am using “Lazy” Lookup http://guides.rubyonrails.org/i18n.html#lazy-lookup.

Rails implements a convenient way to look up the locale inside views. When 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' %>
like image 86
Jesus Avatar answered Oct 04 '22 21:10

Jesus