I am using Ruby on Rails 3.1 and I would like to know how to correctly handle internationalization related to partial template files. That is, ...
... in my app/views/users/flag.html.erb
file I have:
<%= t('.test_key1') %>
<%= render :partial => "/users/flag_form" %>
... in my app/views/users/_flag_form.html.erb
file I have:
<%= t('.test_key2') %>
If in my config/locales/views/users/en.yml
file (note: I am organizing files as stated in the official RoR guide) I use
en:
users:
flag:
test_key1: Test 1 text
test_key2: Test 2 text
the Test 1 text
is displayed in the "main" template (app/views/users/flag.html.erb
) but the Test 2 text
isn't for the partial template (app/views/users/_flag_form.html.erb
). How could\should I solve this issue so to properly display the Test 2 text
?
config/locales/en.yml
app/views/users/flag.html.erb
app/views/users/_flag_form.html.erb
NB:
I wrote this. What do you think about it?
Is that bad to make such a method ?
One way would be to using scope, instead of "lazy loading" using the full stop. Something like this should work:
or use:
Lastly, you could even pass it to the partial as in
You should also checkout the appendix section on this website as it might be listing something that I am missing: http://www.unixgods.org/~tilo/Rails/where_is_Rails_trying_to_lookup_L10N_strings.html