我的问题正是this question中描述的问题。唯一的区别是:我使用的是Rails 3(确切地说是3.0.4),它使用%{...}
语法而不是旧的{{...}}
。
问题:Rails 3逃脱%{...}
内的所有标记,因此我无法在其中插入链接。
有没有办法克服这个问题?
答案 0 :(得分:42)
我终于明白了,你必须使用_html
作为任何yaml-key的后缀,你不希望html转义:
paragraph_html: "This is some text with a %{link}"
paragraph_linktext: "really cool link"
然后
link = link_to t( paragraph_linktext ), "http://www.example.com"
<%= t( paragraph_html, :link => link ) %>
瞧,那里有你的i18n-ized链接。
答案 1 :(得分:10)
你可以这样做
my_translation: "Click to access %{link} page"
然后:
<%= t( my_translation, :link => link_to("Google", "http://google.com") ).html_safe %>
一切都会好的!