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:
...
messages:
surveyclosed: "If you have any issues or questions, please contact us through our email or phone number available in %{contacts_url} page"
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
...
messages:
surveyclosed_html: "If you have any issues or questions, please contact us through our email or phone number available in %{contacts_url} page"\