i18n on Ruby on Rails, < and > gets replaced by > ; < ; 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
< ;a href= "/info/index.html"> ;xxxx</a> ;
which bre开发者_开发技巧aks 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
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 >
and <
.
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' %>
Rails is preventing injection attacks by preventing model data from being displayed as actual markup. The raw function prevents that conversion.
Does
<%= raw t(foo.bar.xxxx) %>
work?
精彩评论