Rails 3++ translation text with url
Problem: I want to have a link in the translation file. The text associated with the link also has to be translatable.
My YAML file with english version:
<br />
...<br />
messages:<br />
<span style="visibility: hidden;">++</span>surveyclosed: "If you have any issues or questions, please contact us through our email or phone number available in %{contacts_url} page"<br />
<span style="visibility: hidden;">++</span>surveyclosed_link: "contacts"<br />
This results in
If you have any issues or questions, please contact us through our email or phone number available in <a href="/contacts">contacts</a> page
The reason: Rails 3 automatically escapes the translation file.
The solution: suffix the YAML translation tag with _html. This way, Rails won’t escape the translation and put the link correctly
<br />
...<br />
messages:<br />
<span style="visibility: hidden;">++</span>surveyclosed_html: "If you have any issues or questions, please contact us through our email or phone number available in %{contacts_url} page"<br />
<span style="visibility: hidden;">++</span>surveyclosed_link: "contacts"<br />
Comments