Forum: Rails I18n Passing a dynamic class to translate

Posted by 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?
Posted by 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
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.