Question

In my Rails localization YAML-files I often have hardcoded links like these:

text: "Contact our <a href=\'/contact\'>support team</a> about your questions."

Is there a way to automatically prefix links like that with the current locale?

For example, the link above should be forwarded to /en/contact.

Of course, I might just hardcode the link in the localization files, however with a project of this scale this will be cumbersome.

Thanks for any help.

Was it helpful?

Solution

You could use interpolation on the translation:

in your en.yml:

support_team: "support team"    
contact_support_team: "Contact our %{support_link} about your questions."

in your ruby code:

support_link = link_to(i18n.t('.support_team'), support_path(i18n.locale))
i18n.t '.contact_support_team', support_link: support_link
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top