Forum: Rails I18n Passing a dynamic class to translate

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.
71ee1809f53df0a2b4dac0530f630933?d=identicon&s=25 Richard Schneeman (snowmaninthesun)
on 2008-12-31 00:17
I have a single form that can be used for multiple models, in my view i
origionally had "Add a New #{@element.class}" how can i write a dynamic
i18n translate call?

I want to do something like

<%= t 'new.form.@element.class'%>

What is the best way to accomplish this functionality?
71ee1809f53df0a2b4dac0530f630933?d=identicon&s=25 Richard Schneeman (snowmaninthesun)
on 2009-01-04 20:56
figured it out...

<% 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.