Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

i18n on Ruby on Rails, < and > gets replaced by &gt ; &lt ; when not intended

I am creating locale files for internationalization in a rails app, and have a url that I want translated with tags included , for example

html.erb

<%= t(foo.bar.xxxx) %>

yml file

foo: bar: xxxx: "xxxx"

result

&lt ;a href= "/info/index.html"&gt ;xxxx</a&gt ;

which breaks my links. I do not have an h on the ruby part, so shouldn't this work? Or should I just not have html tags within the yml file?

Rails version is 3.0.1 Ruby version is 1.8.7 p249

like image 656
Saifis Avatar asked Oct 21 '10 15:10

Saifis


1 Answers

Your HTML YAML keys need to have a _html suffix:

foo:
  bar:
    xxxx_html: "<strong>Some HTML Here</strong>"

Doing this Rails will mark the string has html_safe and will render out the HTML instead of converting it to &gt; and &lt;.

You need to reference it with the full key name as well, Rails doesn't automatically see the _html suffix when you call xxxx.

<%= t 'foo.bar.xxxx_html' %>
like image 141
Garrett Avatar answered Nov 02 '22 23:11

Garrett