Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use HTML inside a Rails translation file

I have some translations in my Rails application (config/locale/[en|de].yml) and I use it in my views with <%=t "teasers.welcome" %>. Example:

teasers:     welcome: "<strong>Welcome</strong> to the Website ..." 

In Rails 2.3.8 this works just fine, with Rails 3, the HTML is escaped and translated to &lt;... How can I prevent this form this translation and use HTML in my translation files like in Rails 2.3.8?

like image 583
f00860 Avatar asked Sep 02 '10 10:09

f00860


1 Answers

Other than using raw, there's an other undocumented (but official) way to do so. All keys ending with _html are automatically rendered unescaped.

Rename the key from

teasers:     welcome: "<strong>Welcome</strong> to the Website ..." 

to

teasers:     welcome_html: "<strong>Welcome</strong> to the Website ..." 
like image 133
Simone Carletti Avatar answered Sep 23 '22 22:09

Simone Carletti