Forum: Rails I18n different view based on different model

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Richard S. (Guest)
on 2009-01-03 19:55
I have a view that looks like this "Add a New #{@element.class}"
where my class can be "definition", "phrase", etc.

I want to do something like

<%= t 'removed_email_address@domain.invalid'%>

so when @element is a "phrase" my view would show "Add New Phrase", When
my @element is a "definition" my view needs to be "Add New Definition"

Is this possible?
Richard S. (Guest)
on 2009-01-04 21:56
This forum must really not get much traffic. Anywhoo, I solved my own
problem


<% type_of_element = @element.class.to_s.downcase %>
<% add_element_to_translate =
                          ["model", "add", type_of_element
].compact.join('.')%>
<%= t add_element_to_translate %>

hopes this helps someone else, if you figure out a better way let me
know!!

--
Richard
http://www.slangslang.com
This topic is locked and can not be replied to.